Jump to content

Running a command prompt command as administrator?


Recommended Posts

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?

Link to comment
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?

Link to comment
Share on other sites

  • 6 months later...

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~~

Link to comment
Share on other sites

  • 2 years later...

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");
Link to comment
Share on other sites

  • 6 months later...

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:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...