FatBoy Posted May 7, 2009 Posted May 7, 2009 Hi all, Just wondering if anyone can help me with a problem? I'm running a vbs script via a shortcut with a switch on the end of the shortcut. I need to return the value of the switch within the script its self. e.g. if the target of the shortcut was: C:\Shortcutmsg.vbs -HebronClientLauncher I need to return "HebronClientLauncher" within the vbs file if its possible. I can return the script name using the WScript.ScriptName command but can't work out how to return the switch Thanks
jamesb Posted May 7, 2009 Posted May 7, 2009 WScript.Arguments? Arguments Property (WScript Object) WshArguments Object Those two links might be useful to you. 1
matt40k Posted May 7, 2009 Posted May 7, 2009 Hahaha Yer, starting to feel my age... even tho I'm younger then you!! I'll go with excuse no3. - I'm rather busy at the moment...
FatBoy Posted May 11, 2009 Author Posted May 11, 2009 I used the script and it doesn't error so I suppose it thinks it's working correctly. The only problem is it still doesn't return the Argument. I just get 0 returned as the Argument is empty I'll have to play a bit more.
srochford Posted May 11, 2009 Posted May 11, 2009 If you do C:\Shortcutmsg.vbs -HebronClientLauncher then WScript.Arguments.Item(0) gives you "-HebronClientLauncher" - not the "-" so if you're just checking for the text it won't work (and your script will error if there's no argument at all) If you do: C:\Shortcutmsg.vbs /name:HebronClientLauncher and then in code do: sName=wscript.arguments.named("name") then sName will be set to HebronClientLauncher (or whatever) and no error if there's no argument. 1
FatBoy Posted May 13, 2009 Author Posted May 13, 2009 Thanks Steve, I'll try that later... just struggling with office 2007 deployment at the moment which has taken presidents over this
apeo Posted May 13, 2009 Posted May 13, 2009 If you wanted to specify a switch followed by switch value then you can use named arguments e.g.: Set objArgs = WScript.Arguments Set objArgNamed = objArgs.named strSwitch = objNamed("Switch") So you can call your script as follows: foo.vbs /Switch:bar Dont need to do it this way but is an option. 1
FatBoy Posted May 20, 2009 Author Posted May 20, 2009 Thanks apeo I got it working using your script in the end thanks to everyone else for the help as well
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now