'VBSApp class 'Intended to support identical handling of class procedures by .vbs/.wsf files and .hta files. 'This can be useful when writing a class that might be used in both types of "apps". 'Four ways to instantiate 'For .vbs/.wsf scripts, '
Dim app : Set app = CreateObject( "VBScripting.VBSApp" )'For .hta applications, '
app.Init WScript
Dim app : Set app = CreateObject( "VBScripting.VBSApp" )'If the script may be used in .vbs/.wsf scripts or .hta applications '
app.Init document
With CreateObject( "VBScripting.Includer" )'Alternate method for both .hta and .vbs/.wsf, '
Execute .Read( "VBSApp" )
End With
Dim app : Set app = New VBSApp
Set app = CreateObject( "VBScripting.VBSApp" )'Examples '
If "HTMLDocument" = TypeName(document) Then
app.Init document
Else app.Init WScript
End If
'test.vbs "arg one" "arg two"' '
With CreateObject( "VBScripting.Includer" )
Execute .Read( "VBSApp" )
End With
Dim app : Set app = New VBSApp
MsgBox app.GetFileName 'test.vbs
MsgBox app.GetArg(1) 'arg two
MsgBox app.GetArgsCount '2
app.Quit
<!-- test.hta "arg one" "arg two" -->' Class VBSApp Private fso 'Scripting.FileSystemObject Private hta 'VBSHta object Private incl 'VBScripting.Includer object Private wrapAll_ 'holds WrapAll property value Private filespec, argumentsString 'strings Private arguments 'array of strings Private IAmAnHta, IAmAScript 'booleans Private userInteractive 'boolean Private visibility, visible, hidden 'integers Private powershell 'pwsh.exe filespec or just "powershell" Private UACMsg 'User Account Control warning message Sub Class_Initialize Set fso = CreateObject( "Scripting.FileSystemObject" ) Set incl = CreateObject( "VBScripting.Includer" ) hidden = 0 visible = 1 wrapAll = False SetUserInteractive True IAmAScript = False IAmAnHta = False InitializeAppTypes Execute incl.Read( "Configurer" ) With New Configurer powershell = .PowerShell End With UACMsg = " Restart %s with elevated privileges? %s (The User Account Control dialog may open.)" End Sub 'Determine whether the source file is a script, '(.wsf or .vbs), an .hta, or a .wsc. This method is for when the VBSApp object is included by 1) direct reference in a
<hta:application icon="msdt.exe">
<script language="VBScript">
With CreateObject( "VBScripting.Includer" )
Execute .Read( "VBSApp" )
End With
Dim app : Set app = New VBSApp
MsgBox app.GetFileName 'test.hta
MsgBox app.GetArg(1) 'arg two
MsgBox app.GetArgsCount '2
app.Quit
</script>
</hta:application>