Jump to content

Newbie question


Recommended Posts

I'm in the process of of deploying an application to our clients using Microsoft SMS. I have no problem installing the program but the process involves assigning a host server that can only be done once the installation completes. I haven't been able to get any help from the vendor so I thought about using AutoIt. I used AutoIt help file and came up with this simple script. It opens up the program and goes under "Help-About" menu and assigns the Host server. When I run this script manually while logged in to a system it does exactly what I want it to do but when I push it out with SMS it doesn't work. Only thing I can think of is that SMS uses local system account to install applications so maybe this is a profile issue. By the way I've also used Macro values other than @sw_show to no avail. I hope someone here can give me other suggestions.

run("C:\Program Files\Embarcadero\ERStudio Viewer\ERVIEWER.exe", "", @SW_SHOW)
ControlSend("ER/Studio Viewer", "", "", "{TAB}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
ControlSend("ER/Studio Viewer", "", "", "(!H)")
ControlSend("ER/Studio Viewer", "", "", "+{DOWN 4}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
ControlSend("About ERViewer", "", "", "{TAB}")
ControlSend("About ERViewer", "", "", "{ENTER}")
ControlSend("Embarcadero License Server", "", "", "HostServerName")
ControlSend("Embarcadero License Server", "", "", "{Enter}")
ControlSend("About ERViewer", "", "", "+{TAB 7}")
ControlSend("About ERViewer", "", "", "{ENTER}")
ControlSend("ER/Studio Viewer", "", "", "(!F)")
ControlSend("ER/Studio Viewer", "", "", "{DOWN}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
Exit
Link to comment
Share on other sites

I'm in the process of of deploying an application to our clients using Microsoft SMS. I have no problem installing the program but the process involves assigning a host server that can only be done once the installation completes. I haven't been able to get any help from the vendor so I thought about using AutoIt. I used AutoIt help file and came up with this simple script. It opens up the program and goes under "Help-About" menu and assigns the Host server. When I run this script manually while logged in to a system it does exactly what I want it to do but when I push it out with SMS it doesn't work. Only thing I can think of is that SMS uses local system account to install applications so maybe this is a profile issue. By the way I've also used Macro values other than @sw_show to no avail. I hope someone here can give me other suggestions.

run("C:\Program Files\Embarcadero\ERStudio Viewer\ERVIEWER.exe", "", @SW_SHOW)
ControlSend("ER/Studio Viewer", "", "", "{TAB}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
ControlSend("ER/Studio Viewer", "", "", "(!H)")
ControlSend("ER/Studio Viewer", "", "", "+{DOWN 4}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
ControlSend("About ERViewer", "", "", "{TAB}")
ControlSend("About ERViewer", "", "", "{ENTER}")
ControlSend("Embarcadero License Server", "", "", "HostServerName")
ControlSend("Embarcadero License Server", "", "", "{Enter}")
ControlSend("About ERViewer", "", "", "+{TAB 7}")
ControlSend("About ERViewer", "", "", "{ENTER}")
ControlSend("ER/Studio Viewer", "", "", "(!F)")
ControlSend("ER/Studio Viewer", "", "", "{DOWN}")
ControlSend("ER/Studio Viewer", "", "", "{ENTER}")
Exit
Is the problem that the app doesn't run at all, or something with the ControlSend() action?

One thing I see is no checking that the app is ready for input. After Run() the first ControlSend() will happen in a couple of milliseconds, and the app may not be ready yet. Any ControlSend() that causes the app to do some processing may not be done by the time the next ControlSend() is done, causing timing issues.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Is the problem that the app doesn't run at all, or something with the ControlSend() action?

One thing I see is no checking that the app is ready for input. After Run() the first ControlSend() will happen in a couple of milliseconds, and the app may not be ready yet. Any ControlSend() that causes the app to do some processing may not be done by the time the next ControlSend() is done, causing timing issues.

:)

thanks for the feedback. I did place a sleep (5000) command after run and in between every ControlSend commands and it still didn't work. One thing I noticed is that when I run this script through SMS or even Psexec the ERVIEWER process is still running in Task Manager when the script exits. When I run it manually the process exits at the same time the script ends. So somewhere along the line something fails when this script is deployed.
Link to comment
Share on other sites

thanks for the feedback. I did place a sleep (5000) command after run and in between every ControlSend commands and it still didn't work. One thing I noticed is that when I run this script through SMS or even Psexec the ERVIEWER process is still running in Task Manager when the script exits. When I run it manually the process exits at the same time the script ends. So somewhere along the line something fails when this script is deployed.

The nice thing about ControlSend() vice Send() is that it will target a specific window. This version adds some error handling and makes sure the expected windows are available before continuing. Failure is indicated by a non-zero %ERRORLEVEL% on exit. You could change that to a log file or some other kind of error reporting:
Global $iPID; Process ID
Global $sWinTitle; Expected Window Titles
Global $sWinText; Expected Window Texts
Global $sRunDir = "C:\Program Files\Embarcadero\ERStudio Viewer"
Global $sRunExe = $sRunDir & "\ERVIEWER.exe"

If Not FileExists($sRunExe) Then Exit 1; Exe file not found
    
$iPID = Run($sRunExe, $sRunDir, @SW_SHOW)

$sWinTitle = "ER/Studio Viewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 2
EndIf

ControlSend($hWin, "", "", "{TAB}")
ControlSend($hWin, "", "", "{ENTER}")
ControlSend($hWin, "", "", "(!H)")
ControlSend($hWin, "", "", "+{DOWN 4}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "About ERViewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 3
EndIf

ControlSend($hWin, "", "", "{TAB}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "Embarcadero License Server"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 4
EndIf

ControlSend($hWin, "", "", "HostServerName")
ControlSend($hWin, "", "", "{Enter}")

$sWinTitle = "About ERViewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 5
EndIf

ControlSend($hWin, "", "", "+{TAB 7}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "ER/Studio Viewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 6
EndIf

ControlSend($hWin, "", "", "(!F)")
ControlSend($hWin, "", "", "{DOWN}")
ControlSend($hWin, "", "", "{ENTER}")

Exit 0; Success

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The nice thing about ControlSend() vice Send() is that it will target a specific window. This version adds some error handling and makes sure the expected windows are available before continuing. Failure is indicated by a non-zero %ERRORLEVEL% on exit. You could change that to a log file or some other kind of error reporting:

Global $iPID; Process ID
Global $sWinTitle; Expected Window Titles
Global $sWinText; Expected Window Texts
Global $sRunDir = "C:\Program Files\Embarcadero\ERStudio Viewer"
Global $sRunExe = $sRunDir & "\ERVIEWER.exe"

If Not FileExists($sRunExe) Then Exit 1; Exe file not found
    
$iPID = Run($sRunExe, $sRunDir, @SW_SHOW)

$sWinTitle = "ER/Studio Viewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 2
EndIf

ControlSend($hWin, "", "", "{TAB}")
ControlSend($hWin, "", "", "{ENTER}")
ControlSend($hWin, "", "", "(!H)")
ControlSend($hWin, "", "", "+{DOWN 4}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "About ERViewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 3
EndIf

ControlSend($hWin, "", "", "{TAB}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "Embarcadero License Server"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 4
EndIf

ControlSend($hWin, "", "", "HostServerName")
ControlSend($hWin, "", "", "{Enter}")

$sWinTitle = "About ERViewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 5
EndIf

ControlSend($hWin, "", "", "+{TAB 7}")
ControlSend($hWin, "", "", "{ENTER}")

$sWinTitle = "ER/Studio Viewer"
$sWinText = ""
WinWait($sWinTitle, $sWinText, 30)
If @error  = 0 Then 
; Window opened normally
    $hWin = WinGetHandle($sWinTitle, $sWinText)
Else
; Window did not open before timeout
    ProcessClose($iPID)
    Exit 6
EndIf

ControlSend($hWin, "", "", "(!F)")
ControlSend($hWin, "", "", "{DOWN}")
ControlSend($hWin, "", "", "{ENTER}")

Exit 0; Success

:)

Thank you. I work with this and see if I can get different results. What puzzles me is that why would the same script work when it's executed manually but not remotely.
Link to comment
Share on other sites

Thank you. I work with this and see if I can get different results. What puzzles me is that why would the same script work when it's executed manually but not remotely.

The user environment of the remote session is likely different. Drive mappings and permissions could be different. I also added an explicit working directory to the function call in my version, which is often significant.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...