Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am trying since long to run command prompt with UAC rights i.e it must be similar as user right click and run as administrator.

Also I want to execute set of command

for eg:

net user administrator /active:yes
net user administrator passowrd


the above command will execute only if the user runs cmd.exe as run as administrator.
I am not getting how to do this programmatically.

I tried with below command
runas /savecred /profile /user:Administrator "net user administrator /active:yes"


but it asks for administrator password which does not exist as the account is not active.

Basically I want to do is that my program should call cmd.exe with prompting UAC "i.e Run as administrator" and then the user should ckick yes and the command

XML
<pre>
net user administrator /active:yes
net user administrator passowrd
</pre>


should run in which case it does not require administrator password
Posted

1 solution

You are doing it correctly, if the password is requested via the UAC dialog. And you cannot bypass UAC, otherwise — who would need such "protection"? The privilege elevation can only be granted via the UAC dialog.

All you can do in your application is to request UAC dialog from the very beginning, by creating and embedding appropriate application manifest:
http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].

Please don't tell us "this is not what I want". There is no a way to bypass UAC.

—SA
 
Share this answer
 
Comments
VipinKumar Maurya 6-Feb-15 23:24pm    
I think you got it wrong. I want UAC Dialog while I run the batch file that has these commands to activate administrator user and then set passowrd for it
Sergey Alexandrovich Kryukov 6-Feb-15 23:41pm    
You want it, but how? Batch files is the old facility, much older than UAC. So, you need to run something newer from batch of wrap batch in something newer. I explained the second approach, which I think is the most reasonable. You can have another tiny application (with the manifest requesting UAC) which only runs the batch; and then you can execute if from the bigger application (but I would not advise that).

The example of first approach is shown here: http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file.

You need to do something to activate the dialog.

Now, another approach could be not using batch at all.

—SA

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