+ Post New Thread
Results 1 to 10 of 10
Coding Thread, Return the switch placed on a VBS script in Coding and Web Development; Hi all, Just wondering if anyone can help me with a problem? I'm running a vbs script via a shortcut ...
  1. #1
    FatBoy's Avatar
    Join Date
    Oct 2007
    Location
    Kent, UK
    Posts
    245
    Thank Post
    54
    Thanked 20 Times in 16 Posts
    Rep Power
    17

    Return the switch placed on a VBS script

    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

  2. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    WScript.Arguments?

    Arguments Property (WScript Object)
    WshArguments Object

    Those two links might be useful to you.

  3. Thanks to jamesb from:

    FatBoy (11th May 2009)

  4. #3

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,342
    Thank Post
    367
    Thanked 624 Times in 509 Posts
    Rep Power
    156
    WScript.Arguments.Item(0)

    EDIT:
    What James said.

  5. Thanks to matt40k from:

    FatBoy (11th May 2009)

  6. #4

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    Too slow Matt, too slow.

    Admittedly only by seconds.

  7. #5

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,342
    Thank Post
    367
    Thanked 624 Times in 509 Posts
    Rep Power
    156
    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...

  8. #6
    FatBoy's Avatar
    Join Date
    Oct 2007
    Location
    Kent, UK
    Posts
    245
    Thank Post
    54
    Thanked 20 Times in 16 Posts
    Rep Power
    17
    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.

  9. #7

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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.

  10. Thanks to srochford from:

    FatBoy (20th May 2009)

  11. #8
    FatBoy's Avatar
    Join Date
    Oct 2007
    Location
    Kent, UK
    Posts
    245
    Thank Post
    54
    Thanked 20 Times in 16 Posts
    Rep Power
    17
    Thanks Steve,

    I'll try that later... just struggling with office 2007 deployment at the moment which has taken presidents over this

  12. #9
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41
    If you wanted to specify a switch followed by switch value then you can use named arguments e.g.:

    Code:
    Set objArgs = WScript.Arguments
    Set objArgNamed = objArgs.named
    strSwitch = objNamed("Switch")
    So you can call your script as follows:

    Code:
    foo.vbs /Switch:bar
    Dont need to do it this way but is an option.

  13. Thanks to apeo from:

    FatBoy (20th May 2009)

  14. #10
    FatBoy's Avatar
    Join Date
    Oct 2007
    Location
    Kent, UK
    Posts
    245
    Thank Post
    54
    Thanked 20 Times in 16 Posts
    Rep Power
    17
    Thanks apeo I got it working using your script in the end

    thanks to everyone else for the help as well

SHARE:
+ Post New Thread

Similar Threads

  1. Writing to Excel from .vbs script
    By Samson in forum Windows
    Replies: 6
    Last Post: 15th October 2008, 07:34 AM
  2. Sub within a sub - VBS Script
    By FN-GM in forum Scripts
    Replies: 5
    Last Post: 18th May 2008, 06:30 PM
  3. VBS Script to copy a folder
    By FN-GM in forum Scripts
    Replies: 2
    Last Post: 23rd February 2008, 01:08 PM
  4. Trace a VBS Script
    By chalkwellstu in forum Scripts
    Replies: 2
    Last Post: 25th January 2008, 10:53 AM
  5. VBS script for prestaging computers anyone?
    By ChrisH in forum Scripts
    Replies: 7
    Last Post: 23rd June 2006, 09:59 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •