Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is wrong with the following code?
ProcessStartInfo startInfo = default(ProcessStartInfo);

     startInfo = new ProcessStartInfo(SetupProgramPath)
     {
         UseShellExecute = true,
         Verb = "runas",
         WindowStyle = ProcessWindowStyle.Normal,
         CreateNoWindow = false
     };

     Process.Start(startInfo);

It is expected to prompt for credentials but nothing shows up. The system has the UAC enabled and not supposed to be changed.
I appreciate your help in this one. Thank you in advance.

What I have tried:

Have tried setting
UseShellExecute = False
Also, tried removing WindowStyle and CreateNoWindow
Posted
Updated 20-Jan-17 7:55am
v2
Comments
Richard MacCutchan 20-Jan-17 13:14pm    
Nothing there that calls for elevated permissions.

1 solution

A child process inherits the environment of the process that launched it. If this code you posted is being run as an administrator already the child process you launch will inherit it. There would be no need to ask for permissions because it already has them.

Now, the account running this code ... at the time this code is executed, is the account in the administrators group on the machine or in a group that is in the administrators group? Or is this a normal user account, not in the administrators group?
 
Share this answer
 
Comments
Sundar9057 20-Jan-17 23:28pm    
It is a normal user account
Dave Kreskowiak 21-Jan-17 10:26am    
OK, in that case, you have to ask the user for the login credentials for the account you need to use and then pass those credentials in the ProcessStartInfo instance you created, the UserName and Password properties. You don't need the Verb "runas" line at all.

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