Option Explicit
Dim FSO, WshShell
Dim strTemp, strAnswerFile, strURL
Dim oSourceTS, sLine, sKey, sVal, intEquals, appIE
Dim Computer, strCurrentFolder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
strCurrentFolder = UCase(Left(Wscript.ScriptFullName, Len(Wscript.ScriptFullName) - Len(Wscript.ScriptName) - 1))
If Wscript.Arguments.Count = 2 Then
strAnswerFile = Wscript.Arguments.Item(0)
strURL = Wscript.Arguments.Item(1)
Else
Msgbox "already installed, please uninstall"
Wscript.Echo 1 'wrong number of arguments
End If
'strFile2Launch = "
to automate"
If Left(LCase(strURL), 4) = "http" Then
Set appIE = CreateObject("InternetExplorer.Application")
appIE.ToolBar = True
appIE.StatusBar = True
appIE.Visible = True
'appIE.FullScreen = True
appIE.Height = 640
appIE.Width = 480
appIE.Left = 50
appIE.Top = 50
appIE.Navigate strURL
Else
If FSO.FileExists(strURL) Then
appIE = WshShell.Run(strURL, 1, False)
End If
End If
If FSO.FileExists(strAnswerFile) Then
'Set Computer = New clsMachine
Set oSourceTS = FSO.OpenTextFile(strAnswerFile, 1, False)
Do While Not oSourceTS.AtEndOfStream
sLine = ""
sLine = Trim(oSourceTS.ReadLine)
If sLine <> "" Then
If Not Left(sLine, 1) = "'" Then
If InStr(sLine, " '") Then
sLine = Left(sLine, InStr(sLine, " '") - 1)
End If
sLine = WshShell.ExpandEnvironmentStrings(sLine)
intEquals = InStr(1, sLine, "=")
If (intEquals <= 1) Then
'msgbox "error: the following line is invalid " & sLine
Else
'weve found a valid line
sKey = Trim(LCase(Left(sLine, intEquals - 1)))
sVal = Right(sLine, Len(sLine) - intEquals)
'sLine = Replace(sLine, "^computername^", Computer.NetbiosName)
'sLine = Replace(sLine, "^fqdomainname^", Computer.FQDomainName)
'sLine = Replace(sLine, "^domainname^", Computer.DomainName)
Select Case sKey
Case "sendkeys"
If UCase(sVal) = "{ENTER}" Then
'Msgbox "going to press enter"
End If
'Msgbox sVal & "$"
WshShell.SendKeys sVal
Wscript.Sleep 500
Case "wait4ie"
waitBusy appIE
Case "sleep"
If IsNumeric(sVal) Then
If CInt(sVal) < 60001 Then
If CInt(sVal) > 0 Then
Wscript.Sleep sVal
End If
End If
End If
Case "msgbox"
Msgbox sVal
Case "popup"
WshShell.Popup sVal, 3
Case "appactivate"
WshShell.AppActivate sVal
Case "run"
If InStr(LCase(sVal), "%currentfolder%") Then
sVal = Replace(sVal, "%currentfolder%", strCurrentFolder)
End If
If Right(LCase(sVal), 5) = ";false" Then
WshShell.Run Left(sVal, Len(sVal) - 6), 1, False
Else
WshShell.Run sVal, 1, True
End If
Case "space"
WshShell.SendKeys " "
End Select
'
End If
End If
End If
Loop
oSourceTS.Close
Set oSourceTS = Nothing
End If
'Set Computer = Nothing
Set FSO = Nothing
Set WshShell = Nothing
'#####################################################################
'### sub to wait for IE to stop being busy..timeout?
Sub waitBusy(ByRef appIE)
Dim iCount
iCount = 0
If IsObject(appIE) Then
Do
If appIE.Busy = True Then
Wscript.Echo "ie is busy,,,sleeping"
Wscript.Sleep 500
Else
Exit Do
End If
'get out cluase?
iCount = iCount + 1
If iCount = 240 Then
Exit Do
End If
Loop
End If
End Sub
'example input file
AppActivate=Internet Explorer
sleep=10000
sendkeys={TAB 11}
sendkeys={ENTER}
run=