Sign in to follow this  
Followers 0
bniemeyer

Automating a monitor script (hospital application)

6 posts in this topic

Hi everyone, I'm new to autoit. I'm hoping I can get some hints, pointers, etc.

Problem: Our emergency department can't access an application sporadically, log in prompt doesn't come up. We can't get the vendor to work the issue effectively until we can qunatify (and prove!) the issue is occurring.

Proposed solution: Use our monitoring solution (Microsoft's SCOM) to execute an autoit script via SCOM's local agent. The script returns a time in milliseconds it takes for the login window to appear. It times out after 60 seconds. We want to generate an alert if the 60 second value is returned.

Current Issue: The script returns 60 seconds every time when executed by SCOM _but_ works fine when I execute it manually. I think the problem is no GUI session (hence no login window). Anyone have any ideas? Code posted below. I already used the information from the FAQ on locked screens to not depend on the window being active, FWIW.

-----------------------------------------------

SCOM executes a VB script:

-----------------------------------------------

Dim oAPI, oBag

set shellobj=WScript.CreateObject("WScript.Shell")

set execObj=shellobj.Exec("C:\Scripts\TestCitrixSCMStart\autoit_console.bat C:\Scripts\TestCitrixSCMStart\TestCitrixPoolSCMStart.exe")

outData=execObj.StdOut.ReadAll()

Set oAPI = CreateObject("MOM.ScriptAPI")

Set oBag = oAPI.CreatePropertyBag()

Call oBag.AddValue("Time",outData)

Call oAPI.Return(oBag)

CAll oAPI.LogScriptEvent("Citrix SCM Startup Time =",111,0,outData)

----------------------------------------------

Which executes a batch file to force the AutoIt script to return command line values

----------------------------------------------

@echo off

rem workaround to make AutoIt executables "consoleable"

rem From http://www.autoitscript.com/forum/index.php?showtopic=31607

%COMSPEC% /c %* | find /V ""

---------------------------------------------

Which executes the following AutoIt script

---------------------------------------------

Local $ts, $td

;Check link

$ts = TimerInit()

Run(@ComSpec & ' /c "' & 'C:\Users\omagent\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\PRD SCM 55\Sunrise Clinical Manager.lnk' & '"')

If WinWait( "Allscripts Gateway Logon","", 60 ) Then

$td = TimerDiff( $ts )

; MsgBox(0,"Got SCM Window","Startup took " & $td )

ConsoleWrite( StringFormat("%#.6g", $td) )

WinClose( "Allscripts Gateway Logon" )

Else

ConsoleWrite( "60000" )

EndIf

;Return check results to command line for SCOM to use for alerting

Share this post


Link to post
Share on other sites



I would suggest not running it by the link. Right click the link, go to properties, and the Target is a direct link to the program.

Also, if the system is logged off or on standby, I don't believe WinWait will work correctly. You may have to prevent sleeping and only use a screensaver. And, of course, write some code to stop the screensaver.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

As @abberration said, use a direct call to executable or if you want to use the shortcut then use ShellExecute:

ShellExecute("C:UsersomagentAppDataRoamingMicrosoftWindowsStart MenuProgramsPRD SCM 55Sunrise Clinical Manager.lnk")

Also, not sure what's going on with the whole .bat file solution for ConsoleWrite, just use (it's much cleaner):

#AutoIt3Wrapper_Change2CUI=y

Lastly, this could all be done in just an AutoIt script to begin with:

Local $iInit, $iDiff = 60000
$iInit = TimerInit()
ShellExecute('C:UsersomagentAppDataRoamingMicrosoftWindowsStart MenuProgramsPRD SCM 55Sunrise Clinical Manager.lnk')

If WinWait( "Allscripts Gateway Logon","", 60 ) Then
$iDiff = TimerDiff($iInit)
WinClose( "Allscripts Gateway Logon" )
EndIf
ConsoleWrite(StringFormat("%#.6g", $iDiff))

$oAPI = ObjCreate("MOM.ScriptAPI")
$oBag = $oAPI.CreatePropertyBag()
$oBag.AddValue("Time", $iDiff)
$oAPI.Return($oBag)
$oAPI.LogScriptEvent("Citrix SCM Startup Time =", 111, 0, $iDiff)
Edited by zorphnog

Share this post


Link to post
Share on other sites

Well, that's not exactly what I meant. I was trying to get him to launch the program directly from the exe. It should look something like:

ShellExecute(“C:Program Files (x86)Allscripts SunriseClinical Manager ClientThe_Program_Name.exe″, "parameters if any")

If there are any parameters, they will also be in the Target section of the properties. They would be listed after the executable.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Thanks for the responses. Couple of points:

1. I have to use vbs to start the script, SCOM only supports executing vbs.

2. The three steps work fine when I run it from the desktop, so I think the problem is that I don't have a desktop when I run the script in the background.

3. The link works fine, and since the users are using it to launch the citrix thin client, it's preferable so we are testing exactly what the user is using. I have tried it running the fat client, same result.

Share this post


Link to post
Share on other sites

Well I'm not familiar with SCOM so I'm not sure how it invokes a process and I'm not sure of all the specifics of your intended solution. If you are having problems with the being able to "see" windows through your script, one solution might be to run the script as a startup script for users and have it store the time results in the registry or text file. Then have your SCOM script simply read that file/registry value for reporting.

Another question would be whether the Run/ShellExecute function is actually spawning anything. You could check for the existence of the process:

While TimerDiff($ts) < 60000
    If ProcessExists("yourprocess.exe") Then
        ConsoleWrite(1)
        Exit
    EndIf
    Sleep(250)
WEnd
ConsoleWrite(0)

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