Sign in to follow this  
Followers 0
ICANSEEYOU7687

Running a command prompt command as administrator?

12 posts in this topic

I need to run some command prompt commands automatically, but the problem is (even if im logged in as a local administrator) I have to right click the CMD program and click "run as administrator" for these commands to complete successfully. Any idea how to do this?

thanks!

Share this post


Link to post
Share on other sites



thanks! that solved it. For one of the folders at least.

I am trying to do that same thing with a folder in system32, and it is giving me an access denied.

RunWait(@ComSpec & " /C " & "takeown /F C:\Windows\System32\oobe", "", @SW_HIDE)
RunWait(@ComSpec & " /C " & "ICACLS C:\Windows\System32\oobe /T /grant Administrators:F", "", @SW_HIDE)
RunWait(@ComSpec & " /C " & "mkdir C:\Windows\System32\oobe\Info\backgrounds")
RunWait(@ComSpec & " /C " & "copy Aurora.jpg C:\Windows\System32\oobe\Info\backgrounds\")

Now, this all works great, if I open a CMD as administrator and type in these commands, but will not work through autoit. I also do have "#RequireAdmin" at the top of my script. Any suggestions?

Share this post


Link to post
Share on other sites

Anyone have any ideas

Thanks

Share this post


Link to post
Share on other sites

I think this one should help

If not IsAdmin() Then
RunAs($user, $domain, $pass,0,@ScriptName,@ScriptDir)

Share this post


Link to post
Share on other sites

I think this one should help

If not IsAdmin() Then
RunAs($user, $domain, $pass,0,@ScriptName,@ScriptDir)

Cool that looks like it might work the way I need it to. So to run a command prompt as a local administrator... I tried something like this

RunAs(Administrator, @ComputerName, "", 0, @ComSpec & " /C " & "mkdir C:\Windows\System32\oobe\Info\backgrounds", @SystemDir)

the administrator account would just be activated, and I dont think there is a password for it. But its yelling at me telling me error. Any ideas?

Share this post


Link to post
Share on other sites

The code would start the entire autoit script as admin and then you just shellexecute your cmd.

Share this post


Link to post
Share on other sites

sure, but

RunAs(Administrator, @ComputerName, "", 0, @ComSpec & " /C " & "mkdir C:\Windows\System32\oobe\Info\backgrounds", @SystemDir)

Does not work, the actually code produces an error, that basically just says error, lol

Share this post


Link to post
Share on other sites

sure, but

RunAs(Administrator, @ComputerName, "", 0, @ComSpec & " /C " & "mkdir C:\Windows\System32\oobe\Info\backgrounds", @SystemDir)

Does not work, the actually code produces an error, that basically just says error, lol

I've been doing the exact same project as you for a while now XD

Here's what I found to work (running on windows 7 x64), if you haven't got it to work by now.

This is for computers running x64 versions of windows. Add this line to the beginning of your script:

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ;

Along with #RequireAdmin

Also try searching for the files/folders that you need with fileexists()

This way you won't have to do a password prompt or anything of the sort.


[member='That Guy']~~Normonator~~

Share this post


Link to post
Share on other sites

I have found this works 100% of the time. It should work in theory for any program.  

 

DIM $sLocation = 'taskmgr';
DIM $sCmmd = 'cmd'

 

Send("#r");Select the shortcut for Run Windows
WinWaitActive("Run"); Wait till run window is active
ControlSetText("Run", "", "[CLASS:Edit; INSTANCE:1]",$sLocation);
ControlClick("Run","","[TEXT:OK]","primary");Select Ok
WinWaitActive("Task Manager");
Send("!f");Select File
Send("n");Select new task
WinWaitActive("Create new task");
Send( $sCmmd)
AutoItSetOption ( "SendKeyDelay",5);
AutoItSetOption ( "SendKeyDownDelay",5);
Send( '{TAB}')
AutoItSetOption ( "SendKeyDelay",5);
AutoItSetOption ( "SendKeyDownDelay",5);
Send( '{SPACE}')
AutoItSetOption ( "SendKeyDelay",0);
AutoItSetOption ( "SendKeyDownDelay",0);
ControlClick("Create new task","","[TEXT:OK]","primary");Select Ok
WinClose("Task Manager");
WinWaitActive("Administrator");

Share this post


Link to post
Share on other sites

Try this:

runas.exe /savecred /user:administrator "defrag c:"

It saves the password 1 st time and never asks again. may be when you change the admin password you will be prompted again

Share this post


Link to post
Share on other sites

I've been doing the exact same project as you for a while now XD

Here's what I found to work (running on windows 7 x64), if you haven't got it to work by now.

This is for computers running x64 versions of windows. Add this line to the beginning of your script:

 

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ;

Along with #RequireAdmin

Also try searching for the files/folders that you need with fileexists()

This way you won't have to do a password prompt or anything of the sort.

 

Thank you!! I have been struggling with this for months now I could seriously hug you..

:thumbsup:

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