Monthly Archives: June 2013
Visual Studio 2012 Update 3
Microsoft released Visual Studio 2012 Update 3 (Visual Studio 2012.3) on June 26, 2013. This update introduces TFS build improvements as well as various bug fixes.
You can download the update from Microsoft’s download centre using the links below. Alternative you can use the links bellow to download the installation file that better suits your needs.
Note: Visual Studio 2012 Update 4 is now available. You can download it for free using the download links below.
Download Links
Web installation file: http://go.microsoft.com/?linkid=9821199
Offline installation file: http://go.microsoft.com/?linkid=9833082
Posted in Microsoft, Software Updates.
Tagged Microsoft, Visual Studio, Visual Studio 2012
How to allow only one application instance
The following code will ensure that your application can only have one instance active. If the user tries to open the application again while the application is already running then the application will simply quit (in this case after showing a message).
For this to work we will need to modify the Program.cs to check with the use of Mutex if the application is already running or not before we open the main form. Our check will take place in the Main method.
Your code in Program.cs should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication1 { static class Program { [STAThread] static void Main() { /* Retrieve the application Guid attribute. Alternative you can simply use the application name to initialize the Mutex * but it might be risky as other programs might have similar name and make use of the Mutex class as well. */ GuidAttribute appGuid = (GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), true)[0]; // The boolean that will store the value if Mutex was successfully created which will mean that our application is not already running. bool createdNew = true; // Initialize the Mutex object. using (Mutex mutex = new Mutex(true, appGuid.Value, out createdNew)) { /* If Mutex was created successfully which means our application is not running run the application as usual * or else display a message and close the application.*/ if (createdNew) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } else { MessageBox.Show("Application is already running"); } } } } } |
Feel free to modify the example to suit your needs.
Get value between two strings
You might find this snippet particular useful in cases where you want to get a value between two other values.
This takes advantage of the string’s Split
overload to pass an array of two values. This will result in the string being split twice, once for the first value in the array and once more for the second value. The result will be that the second value in the array that Split
returns is the actual value between the first and the second value we passed as argument.
Code:
1 2 3 4 5 6 7 8 9 10 11 | private string GetBetween(string strSource, string strStart, string strEnd) { string result = string.Empty; if (strSource.Contains(strStart) && strSource.Contains(strEnd)) { result = strSource.Split(new string[] { strStart, strEnd }, StringSplitOptions.None)[1]; } return result; } |
Example:
1 2 3 4 | string source = "this is (my value) a test"; // Returns "(my value)" GetBetween(source, "this is ", " a test"); |
How to edit a file in Program Files
Windows User Account Control (UAC) is a security infrastructure introduced with Windows Vista and has been included in all Windows versions after that so far. UAC limits the access to application software to ensure that they cannot perform actions that might harm the system in any way.
Because of how UAC works you might have noticed a few times that you are unable to edit specific files, getting an access denied error. The reason for that, as stated above, is because UAC is limiting the access you have to particular folders and files, allowing you in most cases just to view them.
In order to be able to edit a file that is protected by UAC you will need to access that file while having administrator rights. Luckily there is an easy functionality provided by Microsoft for that. Right click the application, file or folder you want to run as administrator and select the Run as administrator option.
That will give administration rights to the program/file you want to run, allowing you to modify the contents where in other cases would be impossible because of UAC.
Posted in Software Tips.
Tagged UAC, User Account Control, Windows UAC