Why do files get placed in “C:\Users\AppData\Local\VirtualStore\Program Files(x86)”?

An application that is not running with raised privileges should does not have access to the Program Files and Program Files (x86) directories. This is good for safety. In addition, in most cases when a developer tells his program to save data in the Program Files folder, for example, program settings, he has completely forgotten … Read more

Request Windows Vista UAC elevation if path is protected?

The best way to detect if they are unable to perform an action is to attempt it and catch the UnauthorizedAccessException. However as @DannySmurf correctly points out you can only elevate a COM object or separate process. There is a demonstration application within the Windows SDK Cross Technology Samples called UAC Demo. This demonstration application … Read more

Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

I resolved using the library. It resulted to be quite easy to work with the classes provided: First I had to create a WlanClient object wlan = new WlanClient(); And then I can get the list of the SSIDs the PC is connected to with this code: Collection<String> connectedSsids = new Collection<string>(); foreach (WlanClient.WlanInterface wlanInterface … Read more

How to run NOT elevated in Vista (.NET)

The WinSafer API’s allow a process to be launched as a limited, normal, or elevated user. Sample Usage: CreateSaferProcess(@”calc.exe”, “”, SaferLevel.NormalUser); Source code: //http://odetocode.com/Blogs/scott/archive/2004/10/28/602.aspx public static void CreateSaferProcess(String fileName, String arguments, SaferLevel saferLevel) { IntPtr saferLevelHandle = IntPtr.Zero; //Create a SaferLevel handle to match what was requested if (!WinSafer.SaferCreateLevel( SaferLevelScope.User, saferLevel, SaferOpen.Open, out saferLevelHandle, IntPtr.Zero)) … Read more

Windows 7 and Vista UAC – Programmatically requesting elevation in C#

WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator); if (!hasAdministrativeRight) { RunElevated(Application.ExecutablePath); this.Close(); Application.Exit(); } private static bool RunElevated(string fileName) { //MessageBox.Show(“Run: ” + fileName); ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.Verb = “runas”; processInfo.FileName = fileName; try { Process.Start(processInfo); return true; } catch (Win32Exception) { //Do nothing. Probably the user canceled the UAC window … Read more

How to programmatically derive Windows Downloads folder “%USERPROFILE%/Downloads”?

Yes it is special, discovering the name of this folder didn’t become possible until Vista. .NET still needs to support prior operating systems. You can pinvoke SHGetKnownFolderPath() to bypass this limitation, like this: using System.Runtime.InteropServices; … public static string GetDownloadsPath() { if (Environment.OSVersion.Version.Major < 6) throw new NotSupportedException(); IntPtr pathPtr = IntPtr.Zero; try { SHGetKnownFolderPath(ref … Read more

Does Windows 7 restrict folder access as Vista does?

It’s not a “problem”, it’s a feature. It’s called User Account Control (UAC), and it’s one of the ways that system security was tightened under Windows Vista. Windows 7 indeed retains a similar security model. There’s absolutely no reason that your application should need to mess with system folders in the first place. As you’ve … Read more