Sign in to follow this  
Followers 0
Mikie

Executing a script on a remote machine

20 posts in this topic

I have created a script that will install an application. I compile the code. I then copy the code (answer file) to a remote machine along with the original install.exe. I can't get the code to install on the remote machine. But it launches on the local machine I launch the code on. Here are the two scripts. Whatever insight you could give me would be great!

Creates dir, copies files: filename = VisioInst.exe

DirCreate("\\machinename\C$\Program files\VisioInst")

FileInstall("c:\Code\Scripts\AutoIT\VisioViewer\Visio_a.exe", "\\machinename\C$\Program files\VisioInst\Visio_a.exe")

FileInstall("c:\Code\Scripts\AutoIT\VisioViewer\VViewer.exe", "\\machinename\C$\Program files\VisioInst\VViewer.exe")

Run("\\machinename\C$\Program files\VisioInst\Visio_a.exe") This is where it bombs!

(Should) Launch install on remote machine: filename = Visio_a.exe

Run("vviewer.exe", "\\machinename\C$\Program files\VisioInst")

WinWait("Visio Viewer","")

$CLVItem = ControlListView("Visio Viewer","","SysListView321","FindItem","vviewer.exe")

ControlListView("Visio Viewer","","SysListView321","SelectClear")

ControlListView("Visio Viewer","","SysListView321","Select",$CLVItem)

$CLVItem = ControlListView("Visio Viewer","","SysListView321","FindItem","vviewer.exe")

ControlListView("Visio Viewer","","SysListView321","SelectClear")

ControlListView("Visio Viewer","","SysListView321","Select",$CLVItem)

WinWait("Microsoft Office Visio Viewer 2003 Setup","I &accept the terms in the Lic")

ControlCommand("Microsoft Office Visio Viewer 2003 Setup","I &accept the terms in the Lic","Button1","Check","")

Send("!I")

WinWait("Microsoft Office Visio Viewer 2003 Setup","The readme file provides addit")

ControlClick("Microsoft Office Visio Viewer 2003 Setup","The readme file provides addit","Button2")

Share this post


Link to post
Share on other sites



I think you'll need to use something like psexec.exe. Google for it.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

See FAQ:

Q9. How can I run my script on a remote computer over the network?

http://www.autoitscript.com/forum/index.ph...st&p=253174

it has the PsExec link that Teldin mentioned.

-MSP-

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

look, to run applications remotely you need to use WMI .. (forget PSEXEC when you have autoIT :shocked: )

only thing you can come across that might be problematic is the fact that the userprofile doesnt get loaded before

execution of the command, which will mean to you that you will see the application running in taskmanager, but it wont popup

a new window..

this fnc you can use like this

RemoteExecute($strComputer, $CommandLine)

func RemoteExecute($strComputer, $CommandLine)      ; Simple
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") 
$objShare = $objWMIService.Get("Win32_Process")
$objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
$objInParam.Properties_.Item("CommandLine") =  $CommandLine
$objOutParams = $objWMIService.ExecMethod("Win32_Process", "Create", $objInParam)
$PID = $objOutParams.ProcessId 
$ReturnValue = $objOutParams.ReturnValue
Switch $ReturnValue
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$strComputer: " & $strComputer & @CRLF & _
                        "$CommandLine: " & $CommandLine)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $ReturnValue)
    EndSwitch
EndFunc

oÝ÷ ÚØb²ÞÊj{¬z'ò¢èZ½æ¥µêçj×­ç^ØÇâX§¶¯j¸nW¬jëh×6Func RemoteExecuteAdvanced()
    global $Hostname,$Application,$WorkingDirectory,$User,$Password
    $Locator = ObjCreate("WbemScripting.SWbemLocator")
    $Service = $Locator.ConnectServer($Hostname,"root/cimv2",$User,$Password)
    $Security = $Service.Security_
    $Security.ImpersonationLevel = 3
    $Class = $Service.Get("Win32_Process")
    If $WorkingDirectory == "" then
        $Result = $Class.Create($Application)  ;no working directory specified
    Else
        $Result = $Class.Create($Application,$WorkingDirectory)
    EndIf
;   $Class.close
;   $Security.close
;   $Service.close
;   $Locator.close
    Switch $Result
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$Hostname: " &         $Hostname &         @CRLF & _
                        "$Application: " &      $Application &      @CRLF & _
                        "$WorkingDirectory: " & $WorkingDirectory & @CRLF & _
                        "$User: " &             $User &             @CRLF & _
                        "$Password: " &         $Password)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $Result)
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

Thanks for the heads up. I never think to go to the FAQ's.

Share this post


Link to post
Share on other sites

look, to run applications remotely you need to use WMI .. (forget PSEXEC when you have autoIT :) )

only thing you can come across that might be problematic is the fact that the userprofile doesnt get loaded before

execution of the command, which will mean to you that you will see the application running in taskmanager, but it wont popup

a new window..

this fnc you can use like this

RemoteExecute($strComputer, $CommandLine)

func RemoteExecute($strComputer, $CommandLine)      ; Simple
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") 
$objShare = $objWMIService.Get("Win32_Process")
$objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
$objInParam.Properties_.Item("CommandLine") =  $CommandLine
$objOutParams = $objWMIService.ExecMethod("Win32_Process", "Create", $objInParam)
$PID = $objOutParams.ProcessId 
$ReturnValue = $objOutParams.ReturnValue
Switch $ReturnValue
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$strComputer: " & $strComputer & @CRLF & _
                        "$CommandLine: " & $CommandLine)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $ReturnValue)
    EndSwitch
EndFunc

oÝ÷ ÚØb²ÞÊj{¬z'ò¢èZ½æ¥µêçj×­ç^ØÇâX§¶¯j¸nW¬jëh×6Func RemoteExecuteAdvanced()
    global $Hostname,$Application,$WorkingDirectory,$User,$Password
    $Locator = ObjCreate("WbemScripting.SWbemLocator")
    $Service = $Locator.ConnectServer($Hostname,"root/cimv2",$User,$Password)
    $Security = $Service.Security_
    $Security.ImpersonationLevel = 3
    $Class = $Service.Get("Win32_Process")
    If $WorkingDirectory == "" then
        $Result = $Class.Create($Application)  ;no working directory specified
    Else
        $Result = $Class.Create($Application,$WorkingDirectory)
    EndIf
;   $Class.close
;   $Security.close
;   $Service.close
;   $Locator.close
    Switch $Result
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$Hostname: " &         $Hostname &         @CRLF & _
                        "$Application: " &      $Application &      @CRLF & _
                        "$WorkingDirectory: " & $WorkingDirectory & @CRLF & _
                        "$User: " &             $User &             @CRLF & _
                        "$Password: " &         $Password)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $Result)
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

I'm trying to use this function (see below) but I'm getting an error that "the requested action with this object has failed", any ideas? Am I doing something wrong? The machine I'm trying to do this to is in a workgroup.

Thanks,

Terry

$Hostname="GATEWAYT6828"
$Application="shutdown.exe -s -f -t 60"
$WorkingDirectory="c:\windows\system32"
$User="GATEWAYT6828\Microsoft"
$Password="pass@word1"

RemoteExecuteAdvanced()

Func RemoteExecuteAdvanced()
    global $Hostname,$Application,$WorkingDirectory,$User,$Password
    
    $Locator = ObjCreate("WbemScripting.SWbemLocator")
    $Service = $Locator.ConnectServer($Hostname,"root/cimv2",$User,$Password)
    $Security = $Service.Security_
    $Security.ImpersonationLevel = 3
    $Class = $Service.Get("Win32_Process")
    
    If $WorkingDirectory == "" then
        $Result = $Class.Create($Application) ;no working directory specified
    Else
        $Result = $Class.Create($Application,$WorkingDirectory)
    EndIf
    
;   $Class.close
;   $Security.close
;   $Service.close
;   $Locator.close

    Switch $Result
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$Hostname: " &   $Hostname &   @CRLF & _
                        "$Application: " &   $Application &  @CRLF & _
                        "$WorkingDirectory: " & $WorkingDirectory & @CRLF & _
                        "$User: " &          $User &             @CRLF & _
                        "$Password: " &      $Password)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $Result)
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The following variable belong to the main part of the script and not to RemoteExecuteAdvanced() function. If you want to use them with RemoteExecuteAdvanced() function you need to add Global at the beginning of the variable. Ex($Hostname="GATEWAYT6828" change it to Global $Hostname="GATEWAYT6828")

$Hostname="GATEWAYT6828"
$Application="shutdown.exe -s -f -t 60"
$WorkingDirectory="c:\windows\system32"
$User="GATEWAYT6828\Microsoft"
$Password="pass@word1"
Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I had been using Psexec to run a very simple program to monitor the existance of a window on a remote machine. The code I'm executing is just;

If WinExists(" Done") Then
    Exit(0) ;good
Else
    Exit(1) ;bad
EndIf

Psexec will tell me the return code of the exe (0 or 1), so I can use a local script to monitor that output. How can I use the RemoteExecuteAdvanced method and still nab the exe's return value? Or better how can I use wmi to list the open windows of a remote machine?

Thanks

EDIT: Forgot to say I'm using the -i option in psexec. Looks like this psexec \\computer -u User -p Password -i -c test.exe

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

The more I read on this it doesn't sound possible and that psexec is the best option, but I'm still curious, hence a bump.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

So I gave up on the WMI remote query... hopefully some day someone else will have a solution. Instead I just manually went around to the 200 systems and ran the script locally.

BUT I also have another script I'm now using to do things on those machines using PSEXEC.

To get psexec to work on Vista, there were several things I had to do on the machines.

There's a registry key that needs to be set and a port that needs to be open ( port 445)

Reg key is:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system", "LocalAccountTokenFilterPolicy", "REG_DWORD", "1")

Thanks,

Terry

Share this post


Link to post
Share on other sites

Do we have a solution for this?

Running a GUI automation script on remote computer?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

yes, it's possible.

1st method : run Win32_Process Class by WMI (this does the script above by lordofthestrings). disadvantage: no gui on remote.

2nd method : schedule the process as a task on remote by Win32_ScheduledJob Class (WMI). this will create a normal gui with the process.

Source: How to execute program on remote computer?

strComputer = "."
strCommand = "notepad.exe"


Const INTERVAL = "n"
Const MINUTES = 1


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")


objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)


If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If
Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

look, to run applications remotely you need to use WMI .. (forget PSEXEC when you have autoIT :P ) ...

... Win32_Process Class by WMI ...

...

... Win32_ScheduledJob Class (WMI). ...

And if WMI is disabled on the remote computer - then stick with PsExec


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

from the above script :

$Security = $Service.Security_
    $Security.ImpersonationLevel = 3oÝ÷ ÙªÞ¶¬zX§zÇ(®·µ«·r©ÝN'rv÷öÙbëazh§µêé­ëbazéÝz»¢·²X§yºÞjKzkhÂä~)Þnël¢g­)àË­ìvêb笲Øqçb¶ÈhºWgßÛbµ·ºÚ"µÍIÌÍÓØØ]ÜHØÜX]J ][ÝÕØ[TØÜ[ËÕØ[SØØ]Ü][ÝÊBIÌÍÔÙXÙHH ÌÍÓØØ]ÜÛÛXÝÙ
    ÌÍÔÙ    ][ÝÜÛÝØÚ[]][ÝË  ÌÍÐ[Y[[[YK   ÌÍÔÜÝÛÜ
BNÉÌÍÔÙXÝ]HH  ÌÍÔÙXÙKÙXÝ]WÂNÉÌÍÔÙXÝ]K[ÛÛ][Û][HÂIÌÍÔÙXÙKÙXÝ]WË[ÛÛ][Û][HÂIÌÍÐÛÜÈH   ÌÍÔÙXÙKÙ]
    ][ÝÕÚ[ÌÔØÙÜÉ][ÝÊ

or is it the same ?

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

yes, it's possible.

2nd method : schedule the process as a task on remote by Win32_ScheduledJob Class (WMI). this will create a normal gui with the process.

And in AutoIt3 code :

Func RemoteExecute($strPCName, $CommandLine)
Dim $objWMIService, $objscheduledJob, $objSWbemDateTime, $errReturn, $runtime, $intJobID

$objWMIService = ObjGet("winmgmts:\\" & $strPCName & "\root\cimv2")
$objScheduledJob = $objWMIService.Get("Win32_ScheduledJob")

If @min > 55 Then
    $time = (@hour + 1) & ":01" & ":" & @SEC
Else
    $time = @hour & ":" & (@min + 1) & ":" &  @SEC
EndIf
$runtime = @mon & "/" & @MDAY & "/" & @YEAR & " " & $time

$objSWbemDateTime = ObjCreate("WbemScripting.SWbemDateTime")
$objSWbemDateTime.SetVarDate($runtime)
$errReturn = $objScheduledJob.Create($CommandLine, $objSWbemDateTime.Value, False, 0, 0, True, $intJobID)


If $errReturn = 0 Then
FileWriteLine($LogFile, "Scheduled task was started with task ID: " & $intJobID)
Else
FileWriteLine($LogFile, "Scheduled task could not be started due to error: " & $errReturn)
EndIf
EndFunc

Of course, if someone knows a simpler thing to do with the time... by all means. ^_^

Share this post


Link to post
Share on other sites

Also, WMI does not allow desktop interaction. You MUST use either a scheduled task or PSEXEC as to get it to run "interactively".

Share this post


Link to post
Share on other sites

Hi

I'm trying to create an autoit script to execute remotly some UI web tests. I tried the examples from this page, used psexec, and I was able to execute remotly the script BUT in kid of silent mode, no UI. I saw that the process was started, and remains opened.I don't see the tests being launched.

Can you help with some suggestions?

Thanks

Share this post


Link to post
Share on other sites

dcalina, please do not resurrect old threads (especially after 5+ years). If you are running into an issue, please start a new thread, and provide a detailed description of what you are trying to accomplish, along with the code you are using (even if it is not working as you should) so we are not left to guess. I guarantee you, you will get many more eyes on the subject this way rather than replying to such an old thread.


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

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