Announcement

Collapse
No announcement yet.

printers script - change server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • printers script - change server

    i have got a remote server which looks to be going down (file replication not working etc)

    so i want to move the printer connection off this to another server

    have tried this

    Code:
    Option Explicit
    
    on error resume next
    
    Dim objNetwork, strUNCPrinter, bForce, bUpdateProfile
    strUNCPrinter = "\\server300\Panasonic DP-8020"
    
    if objnetwork.item = strUNCPrinter then
        
        '------- del
        bForce = "True"
        bUpdateProfile = "False"
        Set objNetwork = CreateObject("WScript.Network")
        objNetwork.RemovePrinterConnection strUNCPrinter, bForce, bUpdateProfile
        '-----------------
    
        strUNCPrinter = "\\servers03\Panasonic DP-8020 (Glasgow)"
        objNetwork.AddWindowsPrinterConnection strUNCPrinter
    
        WScript.Echo "Printer Changed - check for default settings: " & strUNCPrinter
    
    end if
    
    WScript.Quit
    but the if statement does not work, and it adds the printer is the old one does not exist.

    any ideas how to fix it?
    Last edited by Rems; 17th February 2009, 13:07. Reason: added [code]-tags

  • #2
    Re: printers script - change server

    Originally posted by adencool View Post
    Dim objNetwork, strUNCPrinter, bForce, bUpdateProfile
    strUNCPrinter = "\\server300\Panasonic DP-8020"

    if objnetwork.item = strUNCPrinter then
    objNetwork is unassigned variable, so comparison fails. You need to set a value for it first. Maybe loop through all the installed printers on local computer and replace only those that are mapped onto server300?

    -vP

    Comment


    • #3
      Re: printers script - change server

      It is like vonPryz stated.

      - Define the variables in the right order.
      - Loop through all connected printers.
      - Oh, and mind the case when comparing strings.

      Code:
      Option Explicit
      Dim objNetwork, oPrinters, i
      Dim strUNCPrinterOLD, strUNCPrinterNEW
      
      strUNCPrinterOLD = "\\server300\Panasonic DP-8020"
      strUNCPrinterNEW = "\\servers03\Panasonic DP-8020 (Glasgow)"
      
      Set objNetwork = WScript.CreateObject("WScript.Network")
      Set oPrinters = objNetwork.EnumPrinterConnections
      
      ' loop through all the currently mapped network printers...
      For i = 0 to oPrinters.Count - 1 Step 2
         If LCase(oPrinters.Item(i+1)) = LCase(strUNCPrinterOLD) Then
      
            '------ del -----
            objNetwork.RemovePrinterConnection _
                 strUNCPrinterOLD, True, True
            wscript.sleep 800
            '----------------
      
            objNetwork.AddWindowsPrinterConnection _
                 strUNCPrinterNEW
      
            WScript.Echo "Printer Changed - check for default settings: " _
                 & strUNCPrinterNEW
      
        End if
      Next
      \Rems
      Last edited by Rems; 17th February 2009, 15:11.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X