Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Reload Script if Window is closed

Status
Not open for further replies.

marklee98

MIS
Jan 9, 2007
5
US
I need to have this script reload if someone closes the window. I am new at scripting an need some ideas to help. What we are trying to do is use this on a RDP client machine and it needs to load a signature pad software and also launch Remote desktop using the username of the Enduser. Below is the Script:
'##### GIDE: CREATE FORMS - DO NOT ALTER ANY PART OF THIS BLOCK #######################

'-----------------------------------------------------------------------------------
'---- Script Generated by GIDE - The GooeyScript IDE
'---- Date/Time: 7/13/2009 4:14:15 PM
'-----------------------------------------------------------------------------------

'##### GIDE: MAIN DECLARATIONS - DO NOT ALTER ANY PART OF THIS BLOCK #######################

Option Explicit

Dim objWSHShell
Dim objFSO
Dim bGooeyScriptMissing 'Is GooeyScript.exe missing?
Dim strScriptDir 'This script's path - needed for Windows 2000

'##### GIDE: MAIN DECLARATIONS - DO NOT ALTER ANY PART OF THIS BLOCK #######################

Set objWSHShell = WScript.CreateObject("WScript.Shell")

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")

strScriptDir = Replace(Wscript.ScriptFullName, Wscript.ScriptName,"")
If objFSO.fileExists(strScriptDir & "GooeyScript.exe") then
'Enclosed the following filename in quotes just in case the path name contains spaces
objWSHShell.run """" & strScriptDir & "GooeyScript.exe" & """" & "/regserver",1,True 'Register GooeyScript.exe if found
Else
bGooeyScriptMissing = True
End if

If (bGooeyScriptMissing = True) or _
objFSO.fileExists(strScriptDir & "vbrun60sp5.exe") = false or _
objFSO.fileExists(strScriptDir & "picGooeyScript.jpg") = false or _
objFSO.fileExists(strScriptDir & "ProgressBar.gif") = false then
msgbox "This script requires that GooeyScript.exe, GooeyScript images (picGooeyScript.jpg and ProgressBar.gif) and vbrun60sp5.exe are all in the same directory. Please put the required files in this directory."
wscript.quit
End If

If Not objFSO.FileExists(objWSHShell.ExpandEnvironmentStrings("%systemroot%") & "\system32\msvbvm60.dll") Then
'Installing VisualBasic RunTime libraries
objWSHShell.Run """" & Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "vbrun60sp5.exe /q" & """",0, True
End If

'##### GIDE: LOAD FORMS - DO NOT ALTER ANY PART OF THIS BLOCK #######################

Dim NameEntry
Set NameEntry = WScript.CreateObject("GooeyScript.Form", "NameEntry_")

NameEntry.load ,,380,240,"",true,,true

NameEntry.BackColor 240,240,240
NameEntry.ForeColor 18,1,1
'NameEntry.Font False,7.8,"MS Sans Serif"
NameEntry.ontop = true

NameEntry.label.Load "Caption",20,15,180,25,"Enter your username here",True
NameEntry.label.Font "Caption",True,12,"Calibri"
NameEntry.label.BackColor "Caption",240,240,240
NameEntry.label.ForeColor "Caption",18,1,1

NameEntry.textbox.Load "ConnectionString",20,40,265,50,"",0,True
NameEntry.textbox.Font "ConnectionString",False,16,"Calibri"
NameEntry.textbox.BackColor "ConnectionString",255,255,255
NameEntry.textbox.ForeColor "ConnectionString",18,1,1


NameEntry.Button.Load "OK",20,120,260,76,"OK",True
NameEntry.Button.Font "OK",True,13.2,"Calibri"
NameEntry.Button.BackColor "OK",240,240,240

'---- Set control tab orders
'NameEntry.textbox. "ConnectionString",0
'NameEntry.Button.TabIndex "OK",1


Sub NameEntry_ButtonClick(name)

Select Case name
Case "OK"
ProcessClick
End Select

End Sub 'NameEntry_ButtonClick

Sub NameEntry_TextBoxChange(name)
Dim strTemp
Dim intPos

strTemp = NameEntry.TextBox.Text("ConnectionString")

intPos = instr(strTemp, vbCRLF)

if (intPos = 1) then
NameEntry.TextBox.Text "ConnectionString", mid(strTemp, 3, len(strTemp))
NameEntry.MsgBox mid(strTemp, 3, len(strTemp))

ProcessClick
elseif (intPos > 0) then
NameEntry.TextBox.Text "ConnectionString", mid(strTemp, 1, intPos-1)
NameEntry.MsgBox mid(strTemp, 1, intPos-1)

ProcessClick
end if
End Sub 'NameEntry_TextBoxChange

Sub ProcessClick
Dim strTemp
Dim strCMD

' Get the value they typed in
strtemp = NameEntry.TextBox.Text("ConnectionString")

if (trim(strTemp) <> "" ) then
' Start the SegSOCK running
strCMD = "c:\" & "sigsock " & strtemp & " " & "test" & " 6" & """"
objWSHShell.Run "%comspec% /C " & strCMD,0

' Run the RDP session
strCMD = """" & "%systemroot%\system32\mstsc.exe /f /v:" & strtemp & """"
objWSHShell.Run "%comspec% /C " & strCMD,0

NameEntry.ontop = false

' remove the form and quit the script: NO: Leave running
'NameEntry.unload
'wscript.quit
end if
End Sub

'##### GIDE: END CUSTOM CODE - DO NOT ALTER ANY PART OF THE FOLLOWING BLOCK #######################

Sub NameEntry_KeepAlivePing()
NameEntry.keepAlivePong
End Sub


NameEntry.pause
NameEntry.unload


Set NameEntry = Nothing

 
From what I gather, you want to keep a script running - like a service. I'm sure there are otherways to go about this but...

Put the main routine in a conditionalized loop that checks to see if the process or window is still active. This can be done using objShell.AppActivate(name | PID). Bare in mind that this menthod will try to bring focus to the process 100% of the time. As an alternative, you can use SysInternals' PSlist.exe to get a list of processes. Compare your process to the list and take appropriate action.

This works really well for kiosk-like implementations (eg. launching an interface in IE). You can take this a step further and install the script as a service using instrsrv.exe and srvany.exe (both files are available from Microsoft).

Here is some code that may satisfy your requirements.


do
strPID = getPID("IEXPLORE")
if (strPID = 0) then
objShell.Run("""c:\program files\internet explorer\IEXPLORE.exe"" -k " & strKioskWebSite)
wscript.sleep 3000 ' 3 seconds
else
wscript.sleep 3000 ' 3 seconds
end if
loop

'NOTE: getPID() is a function that uses PSlist to dump a list of active processes to a text file. The file is read to determine if the process is still active.

-Geates
 
no need for redundant code

do
strPID = getPID("IEXPLORE")
if (strPID = 0) then objShell.Run("""c:\program files\internet explorer\IEXPLORE.exe"" -k " & strKioskWebSite)
wscript.sleep 3000 ' 3 seconds
loop

Geates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top