Sign in to follow this  
Followers 0
Rogue5099

Run CMD as Admin local user UAC

4 posts in this topic

With the following code I want to read the system defrag status to a GUI.  I have UAC disabled on my PC and I am able to get the results.  When I run this on other PC's it says they don't have the correct privileges.

$iPID = Run(@ComSpec & ' /C defrag ' & @HomeDrive & ' /a /v', "", @SW_HIDE, $STDOUT_CHILD)

I have #RequireAdmin at the begining of my script but this still does not pass on to a sub-process.

I don't mind UAC interrupting and asking for permission.  Even tried RunAs() but each computer's Password is different if even non existent. 

I see how to open cmd by clicking start menu, typing cmd, right clicking Command Prompt, clicking Run As Admin does work but how do I tell CMD that through AutoIt?

(This is not for a network just several local computers.)

I just want to run the above line in Admin CMD and have UAC prompt if needed.

Share this post


Link to post
Share on other sites



I do not know if >this will be useful...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Sub-processes started by a program that has itself been run with elevated privileges normally inherit the elevation.
The problem may be that the user is not a member of the administrators group (which is required to run defrag)
.

You can add a check for this in your code :

#RequireAdmin
If NOT IsAdmin() Then Exit MsgBox(16, "Error", "Access denied")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0