Search This Blog

VBS - Template

Template for VBScripts with all necessary things that you will need to get started:

  • ScriptVersion variable - in case you need to keep track
  • Header - just to remind you what you have built and when
  • force_cscript - to run your script in CMD window and get a better response
  • On Error Resume Next - because who knows

ScriptVersion = "1.0.0"
'==========================================================================
' NAME: Name of your Script
' DESCRIPTION: short description
' AUTHOR: PeskyJim
' CREATION DATE  : YYYY-MM-DD
'==========================================================================
force_cscript

On Error Resume Next

'Your code here

'==========================================================================
sub force_cscript
    Dim Arg, Str
    If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
        For Each Arg In WScript.Arguments
            If InStr( Arg, " " ) Then Arg = """" & Arg & """"
            Str = Str & " " & Arg
        Next
        CreateObject( "WScript.Shell" ).Run "cmd.exe /k " & "cscript //nologo """ & WScript.ScriptFullName & """" & Str
        WScript.Quit
    End If
end sub
'==========================================================================

No comments:

Post a Comment