tags:

views:

428

answers:

2

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 affect 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.

+3  A: 

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/

Lex Li
Thanks lextm. I didn't know a manifest file could be made for exe files I didn't create. Or that they didn't have to be embedded either. Thanks for the links.
JimDel
+1  A: 

Hi, I have your same problem.

In my Windows 7 the value of "RUNASADMIN" is placed in the key:

[HKEY_USERS \ S-1-5-21-3280352481-4073337744-872459336-1001 \ Software \ Microsoft \ Windows NT \ CurrentVersion \ AppCompatFlags \ Layers]

I don't think is valid for all PC. Let me know if it solves the problemw. I am interested in the problem.

Bye Leo

Leo
Thanks Leo, Ill look into that.
JimDel