6 Replies Latest reply on Jan 21, 2009 7:43 AM by jemonty

    VBScript Exit Codes


      I am using a Windows Script Host distribution package in Landesk to run a VBScript which performs several different tasks when executed.  I have written the script in such a way that I can receive a status back at various points to determine if the script is executing as expected.  If at any point something is failing I exit the script using the wscript.quit method.  I would like to be able to get some status back to the Landesk console to report the error.  If I quit the script and specify an exit code ( e.g. wscript.quit(1) ) I will get an error message.  Here are a few of the errors that correspond to different exit codes:


      wscript.quit(1) = Incorrect function.

      wscript.quit(2) = The system cannot find the file specified.

      wscript.quit(3) = The system cannot find the path specified.

      wscript.quit(4) = The system cannot open the file.


      What I would like is to be able to get a custom result message back in the Landesk console instead of the standard ones I mentioned above if the script errors out.  Is there any way to accomplish this or is there another method that works better when running WSH packages?


      Thanks in advance.

        • 1. Re: VBScript Exit Codes
          MarXtar ITSMMVPGroup

          Take a look at the sdclient /msg="your message here" functions.  If you launch sdclient with this parameter from your script, you could pass back your actual message into the scheduled task pane.


          Mark Star - MarXtar LANDesk Enhancements

          Home of Power State Notifier & Wake-On-WAN for LANDesk

          1 of 1 people found this helpful
          • 2. Re: VBScript Exit Codes
            ahe Expert



            take a look at this document: About Batch File Distribution Packages

            This document describes how to use batches to distribute packages but it describes the way to send messages to LANDesk too (s. page 33ff)




            • 3. Re: VBScript Exit Codes

              ahe...Thanks for the info.  I found the following in the PDF you referenced.


              NOTE: The failure string displayed in the task may be incorrect as batch files are linked to facility 7, Microsoft, which results in the Win32 strings being displayed on the console regardless of what command in the batch file really returned the error. Except when using the basic batch file to deploy an MSI file or other Win32® tasks, the failure string on the console should be ignored.


              From that paragraph, it sounds like the failure strings you see in the console when running a scheduled task cannot be modified.

              • 4. Re: VBScript Exit Codes



                Thanks for the suggestion.  I tried calling sdclient /msg="your message here" from within the script.  I still end up with a status as I originally posted it.  Do you know of any other information on how sdclient operates and how it could be used in a vbscript?

                • 5. Re: VBScript Exit Codes

                  The suggestion to call sdclient /msg was never going to change the way in which exit codes are being interpreted. As you have found, the exit code of a vbscript package always seems to be interpreted as a Win32 error code and nothing is going to change that.


                  What sdclient /msg will do is generate a message that will appear in the message column of scheduled tasks. One thing you need to know if you are going to run sdclient /msg from within a vb script is that a vbscript "exec" runs asynchronously. If you "exec" sdclient /msg and then immediately exit, you vb script will terminate before sdclient has had a chance to do its thing and the message will never appear. You need to a little loop as shown below to wait for sdclient:


                  Dim WshShell, oExec
                  Set WshShell = CreateObject("WScript.Shell")

                  Set oExec = WshShell.Exec("""c:\program files\landesk\ldclient\sdclient"" /msg=""vbtest message 1""")

                  Do While oExec.Status = 0
                       WScript.Sleep 100



                  I also chose to use an exit code (29001) that means nothing as a Win32 error code. When you run the above as a package, what will appear in scheduled tasks is Failed, unknown status code(0x80077149,7:29001), vbtest message 1. I thought you might prefer that to a bogus Win32 error.

                  • 6. Re: VBScript Exit Codes

                    Thanks for the info Jan!  Very helpful!