PSC: Basic script

So the challenge was accepted! Follow it here! One of the conditions was that the script has to perform like a program or command line tool to be exact! But why go for one when you can go for both! Still not sure what the final script will do but I have to detect how the script is started and act accordingly.

I always use Option explicit, makes troubleshooting so much easier!
[vb]Option explicit[/vb]
Check if the script is running from console or windows mode by checkking the WScript.FullName string.
[vb]
If InStr(1, WScript.FullName, "cscript", vbTextCompare) Then
InitConsole
ElseIf InStr(1, WScript.FullName, "wscript", vbTextCompare) Then
InitWindow
Else
‘ Hope this never fires! 🙂
wscript.echo "How the hell did you start this script?"
End If
[/vb]
Sub for handling the command line version. Checks for command line arguments, if none displays help.
[vb]
Sub InitConsole()
‘Check if we have any parameters
If Wscript.Arguments.Count = 0 then
‘Display help
wscript.echo "You didn’t supply any command line parameters… At least one parameter is required!"
Else
‘Verrify the parameters
wscript.echo "You supplied " & Wscript.Arguments.Count & " arguments!"
End If
End Sub
[/vb]
Sub for handling if the user double clicks the script…
[vb]
Sub InitWindow()
wscript.echo "You are running this by dubble click…"
End Sub
[/vb]
Stay tuned for the next version!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: