Skip to content

Instantly share code, notes, and snippets.

@tacolin
Created September 1, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacolin/4317d6b78751699d36cc to your computer and use it in GitHub Desktop.
Save tacolin/4317d6b78751699d36cc to your computer and use it in GitHub Desktop.
How to run multiple vbscripts in Secure CRT
#$language = "VBScript"
#$interface = "1.0"
' use this to get the output from script1 and script2 '
dim run_return : run_return = False
Sub Run(vbsFile)
'-------------------------------------------------------------------------'
' Read the script text'
'-------------------------------------------------------------------------'
dim filename : filename = Split(vbsFile, ".")(0)
dim fso, f, s
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile(vbsFile)
s = f.ReadAll()
f.Close
'-------------------------------------------------------------------------'
' Remove the un-necessary part :'
' 1. #$language = "VBScript" '
' 2. #$interface = "1.0"'
' '
' Replace the Sub Main () to Sub 'filename' ()
'-------------------------------------------------------------------------'
lines = Split(s, vbCrLf)
dim beginLine, endLine
For i=0 To Ubound(lines)
If InStr(LCase(lines(i)), "language") > 0 and InStr(LCase(lines(i)), "vbscript") Then
lines(i) = ""
ElseIf InStr(LCase(lines(i)), "interface") > 0 and InStr(LCase(lines(i)), "1.0") Then
lines(i) = ""
ElseIf InStr(LCase(lines(i)), "sub") > 0 and InStr(LCase(lines(i)), "main") > 0 Then
lines(i) = "Sub " & filename & " ()"
End If
Next
'-------------------------------------------------------------------------'
' Re-assemble the text '
' Append the execution of 'filename' () in the last line
'-------------------------------------------------------------------------'
s = ""
For Each line In lines
s = s & line & vbCrLf
Next
s = s & vbCrLf
s = s & " " & filename
'-------------------------------------------------------------------------'
' Execute the script '
'-------------------------------------------------------------------------'
ExecuteGlobal s
End Sub
Sub Main ()
scripts = Array("script1.vbs", "script2.vbs")
For Each script In scripts
Run script
msgbox script & " return value = " & run_return
Next
End Sub
#$language = "VBScript"
#$interface = "1.0"
'Scirpt1.vbs can be excuted by itself'
param = 100
Function common_func ()
msgbox "[script1][common_func] this is common func"
End Function
Sub Main ()
' notice: reset the run_return value at the beginning of script'
run_return = False
msgbox "[script1] enter"
msgbox "[script1] param = " & param
common_func
run_return = True
msgbox "[script1] exit"
End Sub
#$language = "VBScript"
#$interface = "1.0"
'Scirpt2.vbs can be excuted by itself'
Function script2_func ()
msgbox "[script2][func] this is script2-specific func"
End Function
Function common_func ()
msgbox "[script2][common_func] this is common func"
End Function
param = 200
Sub Main ()
' notice: reset the run_return value at the beginning of script'
run_return = False
msgbox "[script2] enter"
msgbox "[script2] param = " & param
common_func
script2_func
If run_return = False Then
msgbox "[script2] break"
Exit Sub
End If
msgbox "[script2] exit"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment