View Single Post
  #2 (permalink)  
Old April 30th, 2004, 02:08 PM
dddane dddane is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dddane
Default

I posted this on another site and got an answer... The completed/working script (for those who care!) is as follows:


Function GetDefaultPrinter()
Set oShell = CreateObject("WScript.Shell")
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
sDefault = ""
On Error Resume Next
 sDefault = oShell.RegRead(sRegVal)
 sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)
 On Error Goto 0
GetDefaultPrinter = sDefault
End Function

oldDefault = GetDefaultPrinter
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections

                           'loop through each printer, searching for printer to replace. 'do this whole iteration one time for EACH printer to replace '################################################# ###########################

    oldPrinter="\\BANNER\Color1100"
       newPrinter="\\CHISALPRSRV\Color1100"

       For i = 0 to oPrinters.Count - 1 Step 2

            if Trim(oPrinters.Item(i+1)) = oldPrinter then
            'Printer found. Lets add the replacement, if successful delete the old.

                WshNetwork.AddWindowsPrinterConnection newPrinter

            if Trim(oldDefault)=Trim(oldPrinter) then
            'set new as default printer
            WshNetwork.SetDefaultPrinter newPrinter
            end if

                If Err <> 0 OR blnError = True Then
                'Printer was NOT added
                    WScript.Echo "UTOH! " & Err
                Else

                    WshNetwork.RemovePrinterConnection oldPrinter, true, true
            End If 'end if err<>0

            End If 'end if printer matches current


         Next

        'END ITERATION SEARCHING FOR PRINTER



                     'END ITERATION SEARCHING FOR PRINTER 'REPEAT THE FOR I=0 THROUGH NEXT FOR EACH PRINTER

Reply With Quote