Sign in to follow this  
Followers 0
simondavies

Help, newb here trying to create a run as admin batch commands

4 posts in this topic

Hello AutoIT forums.

This is probably an easy one for you but being a newb, I am having trouble.

I really just need to open an administrative Command Prompt window, and run a few commands.    This is to allow remote users to have a 1 click resolution to a problem with IKEEXT failing to start properly and thus killing DirectAccess for them.

My environment is 100% Windows 8 and 8.1 Enterprise, running 64bit.

This is the code I have so far (provided by someone at SpiceWorks) 

Local $sUsername = "localadmin"
Local $sPassword = "p@sswOrd"
Local $sDomain   = @computerName

local $sCommand1 = @comspec & " /c sc config ikeext start= auto"
local $sCommand2 = @comspec & " /c net stop ikeext"
local $sCommand3 = @comspec & " /c net start ikeext"

Local $iPID = RunAsWait($sUserName, $sDomain, $sPassword, 0,$sCommand1 , "", @SW_SHOWDEFAULT)
$iPID = RunAsWait($sUserName, $sDomain, $sPassword, 0, $sCommand2 , "", @SW_SHOWDEFAULT)
$iPID = RunAs($sUserName, $sDomain, $sPassword, 0, $sCommand3 , "", @SW_SHOWDEFAULT)

It flashes open 3 command prompt windows in quick succession and I can see a permission error, so I guess it is not running as an administrative cmd prompt.

I read in a few threads that the solution would be doing something like using the ShellExecute() function with the verb "runas". But I am unsure how to implement that in the code I have.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

To run as admin, you need prior HighLevel execution, add #RequireAdmin to the top of your script.

Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Well that doesn't achieve anything...  The users do not have an admin account and if I were going to go that route, I would have just sent the simple batch file and told the users to right click > run as admin.

I need to do the very common task of making a file that with open an administrative command prompt, using the admin credentials that I put into the script and run some commands.

I tested with the #RequireAdmin and it still failed to run the actual commands also.

How do I use the ShellExecute() function with the verb "runas" to call an administrative command prompt using the credentials in the code and then send commands?

Share this post


Link to post
Share on other sites

Nope, doesn't work:

ConsoleWrite(RunAs("username",@ComputerName,"123","notepad.exe","C:\windows\system32\",@SW_MAXIMIZE)&@LF)

I suggest you use some microsoft tool like psexec: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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