ICANSEEYOU7687 Posted November 17, 2010 Share Posted November 17, 2010 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! Link to comment Share on other sites More sharing options...
Bert Posted November 17, 2010 Share Posted November 17, 2010 Look for #RequireAdmin in the helpfile The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
ICANSEEYOU7687 Posted November 18, 2010 Author Share Posted November 18, 2010 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 More sharing options...
ICANSEEYOU7687 Posted November 19, 2010 Author Share Posted November 19, 2010 Anyone have any ideas Thanks Link to comment Share on other sites More sharing options...
Juvigy Posted November 19, 2010 Share Posted November 19, 2010 I think this one should help If not IsAdmin() Then RunAs($user, $domain, $pass,0,@ScriptName,@ScriptDir) Link to comment Share on other sites More sharing options...
ICANSEEYOU7687 Posted November 19, 2010 Author Share Posted November 19, 2010 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 More sharing options...
Juvigy Posted November 22, 2010 Share Posted November 22, 2010 The code would start the entire autoit script as admin and then you just shellexecute your cmd. Link to comment Share on other sites More sharing options...
ICANSEEYOU7687 Posted November 24, 2010 Author Share Posted November 24, 2010 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 Link to comment Share on other sites More sharing options...
Normonator Posted May 27, 2011 Share Posted May 27, 2011 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 More sharing options...
Witmarquzot Posted September 11, 2013 Share Posted September 11, 2013 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"); kenvalyi 1 Link to comment Share on other sites More sharing options...
jimmaqualin Posted September 12, 2013 Share Posted September 12, 2013 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 Link to comment Share on other sites More sharing options...
Morronic Posted March 21, 2014 Share Posted March 21, 2014 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.. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now