JimDel JimDel - 1 month ago 17
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");


Thanks.

Answer

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.

http://msdn.microsoft.com/en-us/library/bb756929.aspx

http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx

http://channel9.msdn.com/posts/jmazner/How-To-Tell-Vistas-UAC-What-Privelege-Level-Your-App-Requires/