JimDel JimDel - 6 months ago 63
C# Question

RUNASADMIN in Registry doesnt seem to work in Windows 7

For a while now the installer for my program has used the below code to make my app run with administer privileges. But it seems to have no effect under Windows 7. In Vista it worked beautifully. If I right click the shortcut and tell it to run as Administer, the program will start fine. But by using the below, code it should be made to run the program that way all the time. It doesn't anymore. Does anyone know if Win 7 still uses this key? UAC is also on by the way.

Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\
CurrentVersion\AppCompatFlags\Layers", "C:\App\app.exe", "RUNASADMIN");



I am using Windows 7 and I can see such keys. However, I don't think that's a proper way to configure your application and installer.

My recommendation is that you distribute a manifest file along with your application (app.exe). The manifest file can be even embedded in the executable easily if you are using Visual Studio 2008. Then in the manifest file you can require administrator rights.