VBScript Err.number codes RRS feed

  • Question

  • Hi,

    I'm receiving the following two error codes from a vbscript which is mapping printers but, I cannot find any information on the internet explaining what these error codes mean. The error number is coming from Err.number.


    Could someone please let me know what these error codes mean?


    Tuesday, February 1, 2011 12:12 AM

All replies

  • Based on the error codes alone, I think it's practically impossible to diagnose the issue. Maybe you can post a part of your code, and indicate on which line you get those errors?
    Tuesday, February 1, 2011 1:58 PM
  • The script i'm using is below. The script usually works - the issue is intermittent. I'm guessing it's something on the computers running the script, not the script itself.

    '** Created 2-9-09 RS **
    '** Revised script to Map printers for Learning Common NW2, using log files to record success/fail **

    Option Explicit
    DIM Wshell, LogFileSystemObject, LogFile, OutputFileName, UserProfile, strComputerName, strUsername

    ' We need a shell object
    Set Wshell = CreateObject("Wscript.Shell")

    ' Determine the location of the \Local Settings\Temp directory for the current user, this is where the log file will be stored
    UserProfile = Wshell.ExpandEnvironmentStrings("%USERPROFILE%")
    strComputerName = Wshell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    strUsername = wshell.ExpandEnvironmentStrings("%USERNAME%")
    OutputFileName = "\\studentprint2\70601_logfiles\LIB2003\" & strComputerName & "_" & strUsername & "_" & ".txt"

    'Create the File object for the log file
    Set LogFileSystemObject = CreateObject("Scripting.FileSystemObject")

    'If the file exists, open it for appending, otherwise create a new one
    If LogFileSystemObject.FileExists(OutputFileName) Then
      Set LogFile = LogFileSystemObject.OpenTextfile(OutputFileName, 8)
      Set LogFile = LogFileSystemObject.CreateTextFile(OutputFileName)
    End If

    ' ** For testing
    'call SetPrinter("\\staffprint1\MBSprn02")

    'Call the subroutine to create each printer that we want. The last printer ends up as the default
    ' call SetPrinter("\\vader\LLCNW3")
    call SetPrinter("\\studentprint2\LLCLINK2")
    call SetPrinter("\\studentprint2\LLCNW2")

    'Close the log file, we are done


    ' ***  This subroutine installs the printer specified in PrinterPath and sets it as the default.
    Sub SetPrinter(ByVal PrinterPath)

      'Turn Error trapping on
      On Error resume next

      DIM WshNetwork
      Set WshNetwork = CreateObject("WScript.Network")

      'Error handling
      If Err.number <> 0 Then

        ' The printer did not get mapped - write an error to the log
        LogFile.WriteLine (Date & " " & Time & " Error - Printer " & PrinterPath & " was not mapped. Error code:" & Hex (Err.Number))
        On Error goto 0

        ' The printer mapped successfully - write the result to the log
        LogFile.WriteLine (Date & " " & Time & " Success - Printer " & PrinterPath & " has been mapped ")
        WshNetwork.SetDefaultPrinter Printerpath
      End If
    End sub

    Friday, February 11, 2011 1:33 AM