Jump to content

Remote AutoIt script execution?


Recommended Posts

Is there any method of remote command line execution of a compiled AutoIt script? Run() works okay but send() and other functionality dies.

We need command line execution as this is interfacing with existing automation infrastructure.

Thanks in advance,

Chris

Link to comment
Share on other sites

Not sure if this is what you mean but

If you compiled the below code to an exe called test.exe then called it with

Test "MsgBox (0,'Test', 'My Message')"

Then the exe would run the autoit line and generate a message box.

Note the surounding quote marks are " doubles and the internal ones are singles

If $CMDLINE [0] > 0  Then 
    $cmd = $CMDLINE [1]

    Else
        MsgBox (0,"Error","No command line specified" ,5)
    EndIf


RunWait(@AutoItExe & ' /AutoIt3ExecuteLine "' & $Cmd & '"')
Link to comment
Share on other sites

Alternatively..

This one you wite the AutoIt code as an inifile which is the same name as the exe.

So install.exe and install.ini, each section that runs then the count is increased in the ini file and the next time it is called it runs the next section, handy for reboots etc

$iniFile = StringTrimRight ( @scriptname, 3 )& "ini" 
$Count = iniread( $iniFile,"Count","Run","1")
$Section = IniReadSection ($iniFile,"Run" & $count)
if fileexists(@tempdir &"\temp.au3") then FileDelete (@tempdir &"\temp.au3")
For $i = 1 to Ubound ($Section)-1
FileWriteLine (@tempdir & "\temp.au3",$Section[$i][1])
Next

If Ubound ($Section)-1 <> -1 then
$Count +=1
If not StringinStr (FileGetAttrib($iniFile),"+R")then iniwrite ($iniFile,"Count","Run",$Count)
RunWait(@AutoItExe & ' /AutoIt3ExecuteScript ' & @tempdir & '\temp.au3')
Endif

The ini file contens look like this.

[Count]
Run=1

[Run1]
1=RunWait ("C:\Drivers\NewSid\Newsid.exe /a", "C:\Drivers\NewSid")


[Run2]

1=Run ("Convert c: /FS:NTFS")

[Run3]

1=Run ("Convert D: /FS:NTFS")

[Run4]
1=MsgBox (262144,"Customise","Insert customisation CD and Click OK")
2=For $i = 65 to 89
3=  $Type = DriveGetType (Chr ($i) & ":")
4=  if $Type = "CDROM" then 
5=      $CDROM = Chr ($i) & ":\"
6=      exitloop 
7=      Endif
8=  Next
9=WaitForDrive ($CDRom)
10=$Ready = FileExists ($cdrom & "Customise.exe")
11=While $Ready = 0
12=$Answer = MsgBox (262145,"Error","Can not find Customisation" & @crlf & "Insert customisation CD and Click OK")
13=If $Answer = 2 then exitloop
14=WaitForDrive($CDRom)
15=Sleep (500)
16=$Ready = FileExists ($cdrom & "Customise.exe")
17=Wend 
18=If $Ready = 1 then 
19= Run ($CDRom & "Customise.exe", $Cdrom)

20=Else

21= iniwrite ("c:\Drivers\install.ini","Count","Run","4")
22= Endif
23=Func WaitForDrive($Drive)
24= For $b = 1 to 10
25= If DriveStatus ($Drive) = "Ready" then 
26=     Return "Ready"
27= Else
28= Sleep (500)
29= Endif
30= Next
31=Return "NotReady"
32=EndFunc
Edited by ChrisL
Link to comment
Share on other sites

Thanks ChrisL and Coffee for your quick replies!

The problem here is that our *very* simple script is executing in command line mode but we are trying to invoke interactive windows programs. VNC can't be used as we need a command line interface (hook for our larger automation infrastructure).

I realize this is more of a windows question but is there any way to accomplish this?

Thanks again,

Chris

Link to comment
Share on other sites

How do you invoke the Autoit (other) application?

psexec from sysinternals can upload and execute your autoit executable.

From the help file tutorial

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
sleep(5000)
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")

Compile and place in same dir as yo launch psexec from:

C:\pstools>psexec \\pcname  -u username -p userpwd -c -f -i -w c:\ testNotepadAuto.exe

Not sure how this will turn out if no one is logged on :D

Edited by Uten
Link to comment
Share on other sites

Thanks ChrisL and Coffee for your quick replies!

The problem here is that our *very* simple script is executing in command line mode but we are trying to invoke interactive windows programs. VNC can't be used as we need a command line interface (hook for our larger automation infrastructure).

I realize this is more of a windows question but is there any way to accomplish this?

Thanks again,

Chris

Can we see your *very* simple script so we know what it does and thereby might get a better feel for what you mean?

Link to comment
Share on other sites

Uten thanks for the link to psexec! With some experimentation it works by telnet/ssh to the local machine (using system switch):-

telnet <ip_addr>

psexec -i -s c:\temp\test.exe

exodius/autoguy100 we are playing with MSN IM interactively using the following simple script:-

Run("C:\Program Files\MSN Messenger\msnmsgr")
WinWaitActive("Windows Live Messenger 8.0 BETA")
Send("!S")
; Check that login successful and close info window
;WinWaitActive("Today")
;WinClose("Today")
; Switch back to messenger and send IM
WinWaitActive("Windows Live Messenger 8.0 BETA", "msn")
Send("<user>")
sleep (2000)
Send("{ENTER}")
WinWaitActive("<user>@hotmail.com - Conversation")
sleep (5000)
Send("Hello {ENTER}")
; Close chat window
WinWaitActive("<user>@hotmail.com - Conversation")
Send("!F")
Send("C")
; Close IM session and logout
WinWaitActive("Windows Live Messenger 8.0 BETA", "msn")
Send("!F")
Send("n")
WinClose("Windows Live Messenger 8.0 BETA")

Again a big thanks to everyone who replied!!

Link to comment
Share on other sites

Sometimes PSExec isn't the best way to run a remote script. Sometimes you don't have the

Credentials to do that. I'd really recommend using WMI to do it. There are plenty of tutorials.

I could put code examples in, for perl, but the most "Secure" method in my opinion is WMI.

Not just that, but PSExec can also call up Anti-virus software.. because so many worm-writers

have used its source code that it cannot be used reliably now.

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