Sign in to follow this  
Followers 0
ThiagoBeier

Call function with RunAs

3 posts in this topic

#1 ·  Posted

Guys, how can I call a function when I have the following code?

in bold you can find the RunAsWait calling the command to stop and start 2 services in a windows server remotely

how do I break it into a function Elevate () to run as my domain admin user and another function to restart the services we need

*sometimes a few customers complain about "user rights" but this way we solve a lot of issues without giving them access on servers (domain controllers and third company servers)

;#include <MsgBoxConstants.au3>
;RUN AS WITH WAIT
Elevate()

Func Elevate()
Local $strUserName = "admin"
Local $strPassword = "P@ssw0rd"
Local $strDirectory = "C:\scrtips\"
;RunAsWait ( "username", "domain", "password", logon_flag, "program" [, "workingdir" [, show_flag [, opt_flag]]] )
RunAsWait($strUserName, "domain.local", $strPassword, 0, "sc \\server01 stop rinetd")
RunAsWait($strUserName, "domain.local", $strPassword, 0, "sc \\server01 stop OpenVPNService")
RunAsWait($strUserName, "domain.local", $strPassword, 0, "sc \\server01 start rinetd")
RunAsWait($strUserName, "domain.local", $strPassword, 0, "sc \\server01 start OpenVPNService"
)
;MsgBox($MB_SYSTEMMODAL, "Title", "Message", 5)
EndFunc

reference to this Funcion Elevate ()

http://eddiejackson.net/wp/?p=7832


regards,

Thiago

Share this post


Link to post
Share on other sites



#2 ·  Posted

@ThiagoBeier in the future, please don't resurrect a 10 year old post, especially one that has nothing to do with your question. Just start a new thread.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Why not just use psexec to run the commands on the remote server.  If I am understanding correctly, you are trying to start to services on a remote server.  Psexec was made exactly for cases like this.  Just download the tool on your computer, and if the server you are trying to access is on the same LAN, then either type from the command line or incorporate into an autoit script the following (can be run as limited account as the credentials are supplied to and elevation is performed by psexec):

psexec \\server01 -u domain.local\$strUserName -p $strPassword -h net stop rinetd

psexec \\server01 -u domain.local\$strUserName -p $strPassword -h net stop OpenVPNService

psexec \\server01 -u domain.local\$strUserName -p $strPassword -h net start rinetd

psexec \\server01 -u domain.local\$strUserName -p $strPassword -h net start OpenVPNservice

Note that this will only work if the user account that you supply to psexec has permissions to access the remote device you specify in the command (meaning it has to be a domain admin.  You might be able to supply the credentials for a local user account with admin permissions, but I have never tried that before.  I would just stick with using a domain admin account.)  Also, I would only use the netbios domain name instead of the full domain.local.

Edited by MattHiggs

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