VBS doesn't work on remote computer like it should
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: VBS doesn't work on remote computer like it should

  1. #1
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284

    VBS doesn't work on remote computer like it should

    Hi gang,

    Trying to use the prnctl.vbs script supplied with XP.

    http://technet.microsoft.com/en-us/l.../bb490976.aspx

    While it works beautifully on local computers, I can't get it to work on any networked computer. I am very certain that I have input the -s, -u & -w parameters correctly. And I have tried it on 2 different physical networks. Any idea?

  2. #2
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428
    It may be a permissions problem. Are you specifying a username and password for a valid user account that has admin rights on the remote computer?

  3. #3
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    Quote Originally Posted by jdc2000 View Post
    Are you specifying a username and password for a valid user account that has admin rights on the remote computer?
    Yes and that's why I can't figure out why it is not working.

  4. #4
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428
    You might have to use some specialized monitoring software to see what, if anything, is happening when you try the command. You would need to verify that the remote computer is being connected to and the appropriate command sent, and that it is being run. You could check the event viewer logs, but there may not be anything there.

    I assume that you have tried the command on the remote computer while actually physically at that computer and it works.

  5. #5
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    Quote Originally Posted by jdc2000 View Post
    I assume that you have tried the command on the remote computer while actually physically at that computer and it works.
    Yes.

  6. #6
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428
    Try connecting two test computers directly with a crossover cable. Make sure all firewalls are turned off.

  7. #7
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    Sorry for taking so long to get back at this.

    Would it be possible that the reason the script doesn't work is b/c the computers are in a workgroup instead of a domain?

  8. #8
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428
    I did not see any requirement that the computers involved be part of a domain.

  9. #9
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    This is strange. I have now tried all the computers on the same network and the result is the same. The script works if only I run the script directly on a computer. It fails when running it from a networked computer. The network is fine AFAIK ... they can ping each other and share files, etc.

    I am not good with VBS at all, maybe you script gurus here can look at the script (%windir%\system32\prnqctl.vbs) and tell me what I am doing wrong.

  10. #10
    Join Date
    Apr 2000
    Location
    Sheboygan, WI
    Posts
    53,391
    Prnqctl.vbs

    Prints a test page, pauses or resumes a printer, and clears a printer queue. Used without parameters, prnqctl.vbs displays command-line help for the prnqctl.vbs command.

    -s RemoteComputer : Specifies, by name, the remote computer to which the printer on which you want to print a test page is attached. If you do not specify a computer, the local computer is used.


    Possibly where the errors are made.

    Post the full script.

  11. #11
    Join Date
    Sep 1999
    Location
    Clearwater, Fl.
    Posts
    22,610
    As Train mention - post an example of the script.

    Are the printers litteraly attached to the computers in question?

    Are you trying to pause a 100 page doc and not a three page doc that gets sent to the printer's memory faster then you can pause the printer?

    Are you getting an error message with important info in it?
    If you're happy and you know it......it's your meds.

  12. #12
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    Just to be clear, this is not my script. It is supplied w/ XP (found in the Windows\System32 folder.) I cut-&-paste the script here at the end of this post.

    This is what I have been trying.

    First, I run the script on a local computer (C1).
    The printer in question (PT) is connected to C1 directly via usb . PT is share across the network.
    The script works perfectly. I can Print a test print (-e); pause printing (-z); cancel all spooled print jobs (-x) and resume printing (-m).

    Now I go to a networked computer (N1), run the same script on N1 but this time I add -s C1 -u falcon2000 -w mypassword to the command line. Nothing will happen. No error nessage, nothing.

    And, no, it is not because the print jobs spooled faster than I can stop them. I purposefully send out a good number of large image files just so I can monitor the print queue.

    Code:
    '----------------------------------------------------------------------
    '
    ' Copyright (c) Microsoft Corporation. All rights reserved.
    '
    ' Abstract:
    ' prnqctl.vbs - printer control script for WMI on Whistler
    '    used to pause, resume and purge a printer
    '    also used to print a test page on a printer
    '
    ' Usage:
    ' prnqctl [-umex?] [-s server] [-p printer] [-u user name] [-w password]
    '
    ' Examples:
    ' prnqctl -m -s server -p printer
    ' prnqctl -x -s server -p printer
    ' prnqctl -e -b printer
    '----------------------------------------------------------------------
    
    option explicit
    
    '
    ' Debugging trace flags, to enable debug output trace message
    ' change gDebugFlag to true.
    '
    const kDebugTrace = 1
    const kDebugError = 2
    dim   gDebugFlag
    
    gDebugFlag = false
    
    '
    ' Operation action values.
    '
    const kActionUnknown    = 0
    const kActionPause      = 1
    const kActionResume     = 2
    const kActionPurge      = 3
    const kActionTestPage   = 4
    
    const kErrorSuccess     = 0
    const KErrorFailure     = 1
    
    const kNameSpace        = "root\cimv2"
    
    '
    ' Generic strings
    '
    const L_Empty_Text                 = ""
    const L_Space_Text                 = " "
    const L_Error_Text                 = "Error"
    const L_Success_Text               = "Success"
    const L_Failed_Text                = "Failed"
    const L_Hex_Text                   = "0x"
    const L_Printer_Text               = "Printer"
    const L_Operation_Text             = "Operation"
    const L_Provider_Text              = "Provider"
    const L_Description_Text           = "Description"
    const L_Debug_Text                 = "Debug:"
    
    '
    ' General usage messages
    '                                 
    const L_Help_Help_General01_Text   = "Usage: prnqctl [-zmex?] [-s server][-p printer][-u user name][-w password]"
    const L_Help_Help_General02_Text   = "Arguments:"
    const L_Help_Help_General03_Text   = "-e     - print test page"
    const L_Help_Help_General04_Text   = "-m     - resume the printer"
    const L_Help_Help_General05_Text   = "-p     - printer name"
    const L_Help_Help_General06_Text   = "-s     - server name"
    const L_Help_Help_General07_Text   = "-u     - user name"
    const L_Help_Help_General08_Text   = "-w     - password"
    const L_Help_Help_General09_Text   = "-x     - purge the printer (cancel all jobs)"
    const L_Help_Help_General10_Text   = "-z     - pause the printer"
    const L_Help_Help_General11_Text   = "-?     - display command usage"
    const L_Help_Help_General12_Text   = "Examples:"
    const L_Help_Help_General13_Text   = "prnqctl -e -s server -p printer"
    const L_Help_Help_General14_Text   = "prnqctl -m -p printer"
    const L_Help_Help_General15_Text   = "prnqctl -x -p printer"
    
    '
    ' Messages to be displayed if the scripting host is not cscript
    '                            
    const L_Help_Help_Host01_Text      = "Please run this script using CScript."  
    const L_Help_Help_Host02_Text      = "This can be achieved by"
    const L_Help_Help_Host03_Text      = "1. Using ""CScript script.vbs arguments"" or" 
    const L_Help_Help_Host04_Text      = "2. Changing the default Windows Scripting Host to CScript"
    const L_Help_Help_Host05_Text      = "   using ""CScript //H:CScript //S"" and running the script "
    const L_Help_Help_Host06_Text      = "   ""script.vbs arguments""."
    
    '
    ' General error messages
    '                                                 
    const L_Text_Error_General01_Text  = "The scripting host could not be determined."                
    const L_Text_Error_General02_Text  = "Unable to parse command line." 
    const L_Text_Error_General03_Text  = "Unable to get printer instance."
    const L_Text_Error_General04_Text  = "Win32 error code"
    const L_Text_Error_General05_Text  = "Unable to get SWbemLocator object"
    const L_Text_Error_General06_Text  = "Unable to connect to WMI service"
    
    
    '
    ' Action strings
    '
    const L_Text_Action_General01_Text = "Pause"
    const L_Text_Action_General02_Text = "Resume"
    const L_Text_Action_General03_Text = "Purge"
    const L_Text_Action_General04_Text = "Print Test Page"
    
    '
    ' Debug messages
    '
    const L_Text_Dbg_Msg01_Text        = "In function ExecPrinter"
    const L_Text_Dbg_Msg02_Text        = "Server name"
    const L_Text_Dbg_Msg03_Text        = "Printer name"
    const L_Text_Dbg_Msg04_Text        = "In function ParseCommandLine"
                                   
    main
    
    '
    ' Main execution starts here
    '
    sub main
    
        dim iAction
        dim iRetval
        dim strServer
        dim strPrinter
        dim strUser
        dim strPassword
        
        '
        ' Abort if the host is not cscript
        '
        if not IsHostCscript() then
       
            call wscript.echo(L_Help_Help_Host01_Text & vbCRLF & L_Help_Help_Host02_Text & vbCRLF & _
                              L_Help_Help_Host03_Text & vbCRLF & L_Help_Help_Host04_Text & vbCRLF & _
                              L_Help_Help_Host05_Text & vbCRLF & L_Help_Help_Host06_Text & vbCRLF)
            
            wscript.quit
       
        end if
    
        '
        ' Get command line parameters
        '
        iRetval = ParseCommandLine(iAction, strServer, strPrinter, strUser, strPassword)
    
        if iRetval = kErrorSuccess then
    
            select case iAction
    
                case kActionPause
                     iRetval = ExecPrinter(strServer, strPrinter, strUser, strPassword, L_Text_Action_General01_Text)
    
                case kActionResume
                     iRetval = ExecPrinter(strServer, strPrinter, strUser, strPassword, L_Text_Action_General02_Text)
    
                case kActionPurge
                     iRetval = ExecPrinter(strServer, strPrinter, strUser, strPassword, L_Text_Action_General03_Text)
    
                case kActionTestPage
                     iRetval = ExecPrinter(strServer, strPrinter, strUser, strPassword, L_Text_Action_General04_Text)
    
                case kActionUnknown
                     Usage(true)
                     exit sub
    
                case else
                     Usage(true)
                     exit sub
    
            end select
    
        end if
    
    end sub
    
    '
    ' Pause/Resume/Purge printer and print test page
    '
    function ExecPrinter(strServer, strPrinter, strUser, strPassword, strCommand)
    
        on error resume next
    
        DebugPrint kDebugTrace, L_Text_Dbg_Msg01_Text
        DebugPrint kDebugTrace, L_Text_Dbg_Msg02_Text & L_Space_Text & strServer
        DebugPrint kDebugTrace, L_Text_Dbg_Msg03_Text & L_Space_Text & strPrinter
        
        dim oPrinter
        dim oService
        dim iRetval
        dim uResult
        
        iRetval = kErrorFailure
        
        if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then
            
            set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")
        
        else
        
            ExecPrinter = kErrorFailure
            
            exit function        
        
        end if
        
        '
        ' Check if getting a printer instance succeeded
        '
        if Err.Number = kErrorSuccess then
        
            select case strCommand
            
                case L_Text_Action_General01_Text
                     uResult = oPrinter.Pause()
                     
                case L_Text_Action_General02_Text
                     uResult = oPrinter.Resume()
                     
                case L_Text_Action_General03_Text
                     uResult = oPrinter.CancelAllJobs()          
                     
                case L_Text_Action_General04_Text
                     uResult = oPrinter.PrintTestPage()  
                
                case else
                     Usage(true)
                     
            end select
    
            '
            ' Err set by WMI 
            ' 
            if Err.Number = kErrorSuccess then
    
                '
                ' uResult set by printer methods
                '             
                if uResult = kErrorSuccess then                     
                
                    wscript.echo L_Success_Text & L_Space_Text & strCommand & L_Space_Text _
                                 & L_Printer_Text & L_Space_Text & strPrinter
            
                    iRetval = kErrorSuccess
                    
                else
                
                    wscript.echo L_Failed_Text & L_Space_Text & strCommand & L_Space_Text _
                                 & L_Text_Error_General04_Text & L_Space_Text & uResult 
                
                end if    
    
            else
    
                wscript.echo L_Failed_Text & L_Space_Text & strCommand & L_Space_Text & L_Error_Text _
                             & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
                
            end if
             
        else      
            
            wscript.echo L_Text_Error_General03_Text & L_Space_Text & L_Error_Text & L_Space_Text _
                         & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description
            
            '
            ' Try getting extended error information
            '            
            call LastError()
            
        end if
        
        ExecPrinter = iRetval
        
    end function
    
    '
    ' Debug display helper function
    '
    sub DebugPrint(uFlags, strString)
    
        if gDebugFlag = true then
    
            if uFlags = kDebugTrace then
    
                wscript.echo L_Debug_Text & L_Space_Text & strString
    
            end if
    
            if uFlags = kDebugError then
    
                if Err <> 0 then
    
                    wscript.echo L_Debug_Text & L_Space_Text & strString & L_Space_Text _
                                 & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _
                                 & L_Space_Text & Err.Description
    
                end if
    
            end if
    
        end if
    
    end sub
    
    '
    ' Parse the command line into its components
    '
    function ParseCommandLine(iAction, strServer, strPrinter, strUser, strPassword)
    
        on error resume next
    
        DebugPrint kDebugTrace, L_Text_Dbg_Msg04_Text
    
        dim oArgs
        dim iIndex
    
        iAction = kActionUnknown
        iIndex = 0
    
        set oArgs = wscript.Arguments
    
        while iIndex < oArgs.Count
    
            select case oArgs(iIndex)
    
                case "-z"
                    iAction = kActionPause
    
                case "-m"
                    iAction = kActionResume
    
                case "-x"
                    iAction = kActionPurge
    
                case "-e"
                    iAction = kActionTestPage
    
                case "-p"
                    iIndex = iIndex + 1
                    strPrinter = oArgs(iIndex)
                    
                case "-s"
                    iIndex = iIndex + 1
                    strServer = RemoveBackslashes(oArgs(iIndex)) 
                      
                case "-y"
                    iIndex = iIndex + 1
                    strUser = oArgs(iIndex)
                    
                case "-w"
                    iIndex = iIndex + 1
                    strPassword = oArgs(iIndex)           
    
                case "-?"
                    Usage(true)
                    exit function
    
                case else
                    Usage(true)
                    exit function
    
            end select
    
            iIndex = iIndex + 1
    
        wend
    
        if Err.Number = kErrorSuccess then
    
            ParseCommandLine = kErrorSuccess
    
        else
        
            wscript.echo L_Text_Error_General02_Text & L_Space_Text & L_Error_Text & L_Space_Text _
                         & L_Hex_Text & hex(Err.Number) & L_Space_text & Err.Description
            
            ParseCommandLine = kErrorFailure
        
        end if
        
    end function
    
    '
    ' Display command usage.
    '
    sub Usage(bExit)
    
        wscript.echo L_Help_Help_General01_Text
        wscript.echo L_Empty_Text
        wscript.echo L_Help_Help_General02_Text
        wscript.echo L_Help_Help_General03_Text
        wscript.echo L_Help_Help_General04_Text
        wscript.echo L_Help_Help_General05_Text
        wscript.echo L_Help_Help_General06_Text
        wscript.echo L_Help_Help_General07_Text
        wscript.echo L_Help_Help_General08_Text
        wscript.echo L_Help_Help_General09_Text
        wscript.echo L_Help_Help_General10_Text
        wscript.echo L_Help_Help_General11_Text
        wscript.echo L_Empty_Text
        wscript.echo L_Help_Help_General12_Text
        wscript.echo L_Help_Help_General13_Text
        wscript.echo L_Help_Help_General14_Text
        wscript.echo L_Help_Help_General15_Text
    
        if bExit then
    
            wscript.quit(1)
    
        end if
    
    end sub
    
    '
    ' Determines which program is being used to run this script. 
    ' Returns true if the script host is cscript.exe
    '
    function IsHostCscript()
    
        on error resume next
        
        dim strFullName 
        dim strCommand 
        dim i, j 
        dim bReturn
        
        bReturn = false
        
        strFullName = WScript.FullName
        
        i = InStr(1, strFullName, ".exe", 1)
        
        if i <> 0 then
            
            j = InStrRev(strFullName, "\", i, 1)
            
            if j <> 0 then
                
                strCommand = Mid(strFullName, j+1, i-j-1)
                
                if LCase(strCommand) = "cscript" then
                
                    bReturn = true  
                
                end if    
                    
            end if
            
        end if
        
        if Err <> 0 then
        
            wscript.echo L_Text_Error_General01_Text & L_Space_Text & L_Error_Text & L_Space_Text _
                         & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description 
            
        end if
        
        IsHostCscript = bReturn
    
    end function
    
    '
    ' Retrieves extended information about the last error that occured 
    ' during a WBEM operation. The methods that set an SWbemLastError
    ' object are GetObject, PutInstance, DeleteInstance
    '
    sub LastError()
    
        on error resume next
    
        dim oError
    
        set oError = CreateObject("WbemScripting.SWbemLastError")
       
        if Err = kErrorSuccess then
       
            wscript.echo L_Operation_Text            & L_Space_Text & oError.Operation
            wscript.echo L_Provider_Text             & L_Space_Text & oError.ProviderName
            wscript.echo L_Description_Text          & L_Space_Text & oError.Description
            wscript.echo L_Text_Error_General04_Text & L_Space_Text & oError.StatusCode
                    
        end if                                                             
                                                                 
    end sub
    
    '
    ' Connects to the WMI service on a server. oService is returned as a service
    ' object (SWbemServices)
    '
    function WmiConnect(strServer, strNameSpace, strUser, strPassword, oService)
    
       on error resume next
    
       dim oLocator
       dim bResult
       
       oService = null
       
       bResult  = false
       
       set oLocator = CreateObject("WbemScripting.SWbemLocator")
    
       if Err = kErrorSuccess then
    
          set oService = oLocator.ConnectServer(strServer, strNameSpace, strUser, strPassword)
    
          if Err = kErrorSuccess then
    
              bResult = true
          
              oService.Security_.impersonationlevel = 3
    
              '
              ' Required to perform administrative tasks on the spooler service
              '
              oService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
              
              Err.Clear
          
          else
    
              wscript.echo L_Text_Msg_General06_Text & L_Space_Text & L_Error_Text _
                           & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
                           & Err.Description
                
          end if
       
       else
       
           wscript.echo L_Text_Msg_General05_Text & L_Space_Text & L_Error_Text _
                        & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _
                        & Err.Description
             
       end if                                                         
       
       WmiConnect = bResult
                
    end function
    
    '
    ' Remove leading "\\" from server name
    '
    function RemoveBackslashes(strServer)
    
        dim strRet
        
        strRet = strServer
        
        if Left(strServer, 2) = "\\" and Len(strServer) > 2 then 
       
            strRet = Mid(strServer, 3) 
            
        end if   
    
        RemoveBackslashes = strRet
    
    end function

  13. #13
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428
    I don't know if this would be a viable solution in your case or not, but you might consider taking remote control of the desired computer so you could actually run the script on the affected computer. That would eliminate the networking component from the script. Otherwise, you will need to use Process Monitor on both the computer you are trying to affect and the computer you are using to run the script, and watch what happens on each when you try the script.

  14. #14
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284
    Quote Originally Posted by jdc2000 View Post
    I don't know if this would be a viable solution in your case or not, but you might consider taking remote control of the desired computer so you could actually run the script on the affected computer.
    This is actually what I am doing for now. It works OK but not the best for my situation ... being able to run the script from a networked computer like it is intended to will be the best. Just can't figure out why doesb't it work.

  15. #15
    Join Date
    Oct 2000
    Location
    Out of NoWhere
    Posts
    3,284

    So the plot thickens

    I decided to try another printer on the same network. It works. So I look into this printer to see is there any difference in setup, etc. There is none. Finally, I realized that this is an older printer using parallel printer cable. The other printer I having been trying on is USB. This is the only difference.

    So to test, I try the script on yet another uSB printer. No joy. After trying a few more times, it appears that I can successfully run the script from any computer targeting the parallel cable printer. But running the script targetting the any USB printer will fail.

    Then I try again at home. At home, I have a wireless printer (built-in wireless print server.) The script runs successfully from any of my 4 computers.

    But this is the thing. The script runs fine on the local computer to which a printer is directly connected either it is USB or parallel. So, seems to me that there is a problem using the script targeting a USB printer over wired network. Isn't it strange?!?!

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
  •