Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Check Wscript.Argument IS NULL

Author Message
acidedge2004

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 5/20/2008
  • Status: offline
Check Wscript.Argument IS NULL Tuesday, May 20, 2008 10:44 PM (permalink)
0
hey, I have a script that I want to use a conditional on to determine how to execute it. I want to have WScript.Arguments(1) IsNull int he script to check whether a 2nd argument was passed to the script from the command prompt. I have tried several variations and keeping getting syntax error messages or "Object is required"

I have tried IsEmpty(), IsNull(), Wscript.Argument(1) Is Null. I have passed the contents of wscript to x then used the functions on x and checked if it = '' but keep getting problems. SOmetimes the condition is ignored and the script executed anyway.

Does anyone know how to check if an argument is null or empty?

Cheers, Mike
#1
    mbouchard

    • Total Posts : 2110
    • Scores: 27
    • Reward points : 0
    • Joined: 5/15/2003
    • Location: USA
    • Status: offline
    RE: Check Wscript.Argument IS NULL Tuesday, May 20, 2008 11:26 PM (permalink)
    0
    Have you tried count?  To see if the proper number of arguements have been passed?  Also, post your code, may help get help.
    Mike

    For useful Scripting links see the Read Me First stickey!

    Always remember Search is your friend.
    #2
      acidedge2004

      • Total Posts : 5
      • Scores: 0
      • Reward points : 0
      • Joined: 5/20/2008
      • Status: offline
      RE: Check Wscript.Argument IS NULL Tuesday, May 20, 2008 11:43 PM (permalink)
      0
      I did not post the code as I do not really think it is specific to my code. I want to know if it could be done in general, so I could use it in this code and future scripts. Even basic code like:

      If IsNull(WScript.Arguments(1)) Then
          WScript.Echo "Hello"
      Else
          WScript.Echo "Goodbye"
      End If

      I hope you can see what I mean by this. I tried IsEmpty in place of IsNull and ='' but got nothing.

      I have googled this and found nothing to help me either.

      I haven't tried count, never even thought of that! Though it may work in this instance, I would stil like to know if anyone knows a method similar to the one I have shown above.

      Cheers, Mike

      #3
        ehvbs

        • Total Posts : 3190
        • Scores: 108
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        RE: Check Wscript.Argument IS NULL Wednesday, May 21, 2008 12:38 AM (permalink)
        0
        Hi acidedge2004,

        WScript.Arguments is an array (for all practical purposes), that contains the space delimited
        arguments from the command line. If there are no parameters, the array will be empty:

           WScript.Arguments.Count == WScript.Arguments.Length == 0

        Given one argument

           WScript.Arguments.Count == WScript.Arguments.Length == 1

        you can access it by

           WScript.Arguments( 0 )

        - remember VBScript arrays are zero-based. Of course it can't be 0, null,
        or empty, because then it couldn't be in the array. In general: passing n
        arguments/options will result in an array of Count/Length == n with n
        non empty strings (Len(WScript.Arguments( i ) > 0) accessible via index
        0 ... (n-1).

        Regards

        ehvbs



        #4
          acidedge2004

          • Total Posts : 5
          • Scores: 0
          • Reward points : 0
          • Joined: 5/20/2008
          • Status: offline
          RE: Check Wscript.Argument IS NULL Wednesday, May 21, 2008 1:27 AM (permalink)
          0
          Cheers   ehvbs,

          Great help!
          #5
            4scriptmoni

            • Total Posts : 224
            • Scores: 0
            • Reward points : 0
            • Joined: 5/3/2007
            • Status: offline
            RE: Check Wscript.Argument IS NULL Thursday, May 22, 2008 1:06 AM (permalink)
            0
            Could also do something like

             set objArgs = WScript.Arguments
             if WScript.Arguments.Count = 3 then
                 wscript.echo "Total number of arguments: " & WScript.Arguments.Count    
                 strEmailTo = WScript.Arguments(0)
                 strSub    = WScript.Arguments(1)
                 strBody = WScript.Arguments(2)
             for each strArg in objArgs    
                 wscript.echo strArg
             next
             else
                 wscript.echo"Error, Must pass arumgnets sendemail <email to> <subject> <body>"
                 wscript.quit
             end if
             

            Enterprise Microsoft Scripts Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc... http://www.felipeferreira.net
            #6

              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 3 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2011 ASPPlayground.NET Forum Version 3.8