Click here to Skip to main content
Click here to Skip to main content

PSC: Basic script

By , 23 Mar 2013
 

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!

Option explicit

Check if the script is running from console or windows mode by checkking the WScript.FullName string.

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

Sub for handling the command line version. Checks for command line arguments, if none displays help.

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

Sub for handling if the user double clicks the script...

Sub InitWindow()
	wscript.echo "You are running this by dubble click..."
End Sub

Stay tuned for the next version!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kristofer Kallsbo
CEO Kallsbo Consulting
Sweden Sweden
Member
I develop in C# on .Net platforms like MVC. Like to use jQuery to build rich interfaces. I also blog about development and snags I got and the solutions I found for them.
 
I also a full time CIO at a Swedish energy company. When there is time I do some part time consulting on cloud issues.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberMihai MOGA12 Apr '13 - 19:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 23 Mar 2013
Article Copyright 2013 by Kristofer Kallsbo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid