Click here to Skip to main content
15,937,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to run an exe file form my C# application. In Windows 7, due to compatibility issue I got to run that file as "set compatibility as Windows Vista" & "Run as Administrator" settings for that exe.

How can I set these permissions from my application? Couldn't find on net any answers to set such things or run a file in such a way.

[Edit : ] If I change my application's settings will that be applied to the exe file that I calling from my application whose compatibility and "Run as Admin" permissions are needed. The exe file will be bundled in my application file.

<pre>
processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
sb = new StringBuilder();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = true;
process = Process.Start(processInfo);
process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);

</pre>

I want to start the cmd as admin as the (exe) file it uses to execute may need admin access.
Actually I tested the same app on 3-4 pcs' and its running on all without any specific permissions as standard users. But on clients any pc its not working. He has all Win 7 and XP systems. I think it might be related to have low level permissions or what else can be the problem. Am not able to make out the problem and hence can't decide with the solution also.

Any help/guidance is highly appreciated. Am stuck up and can't find the problem or solution for the same.

Thanks
Posted
Updated 15-Feb-11 21:44pm
v3

Compatibility mode: (found this with google)

http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644[^]

Run as administrator: (found this with google)

You need to create a string value (REG_SZ) under one of these keys (if you want the setting to be per user or per machine, respectively):

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

or

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

The name of the value needs to be the full path to your executable (if the path contains spaces, do not surround the path with quotes) and the data of the value must contain the string RUNASADMIN.
 
Share this answer
 
v3
Comments
All Time Programming 15-Feb-11 8:39am    
Thanks Nishant & John. I will chekc both the links add my app details to Regitry and do the needful. Before that I have a question, In my application, I use openvpn.exe. If I set the Registry and UAC settings as you both said, will my application be able to run the openvpn.exe as an admin. I got to run openvpn.exe as Admin. My application itself doesn't need so but openvpn needs it in windows 7. So by doing the above will my application be able to run openvpn.exe (from cmd) as an Admin. Whose Compatibility mode should I change? It needs to be chanegd of openvpn.exe. Kindly help me know that will the above able to achieve my goal ? Thanks for your prompt response and look ahead for the same. Thanks.
#realJSOP 15-Feb-11 8:50am    
If you use explorer to specify that the app run as admin, you don't need to bother with this. Beyond that, even setting it to run as admin will still bring up the UAC prompt unless you turn UAC completely off, which is unsecure and not advisable. You shouldn't need to set compatibility mode (I have yet to need that, and I've been running Win7 since the 2nd beta).
All Time Programming 15-Feb-11 8:57am    
Asking the user to set the file as "Run as Admin", doesn't look professional. I have seen applications that use openvpn and doesn't need or any UAC prompt comes up. I was also looking for such kind of solution. Well, I found that problem in Win 7 and today only found that if I run as admin & set the Compatibility mode, the problem doesn't arise i.e. openvpn runs else it wasn't running only. So thought to add it for a better application.
For setting the compatibility, you need to use the registry, see this thread:

http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644[^]

For elevating UAC access, see:

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

You need to use requireAdministrator.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900