![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Printer Swaping Script Error 800708CA I have a VBscript which I am hoping to use to remove old network printers while adding new ones to replace them. I am getting error 800708CA from this line in the code "WshNetwork.RemovePrinterConnection objPrinter.Name,True,True" (line 99) when trying to remove the old printer. Dose anyone have any idea what is wrong and how I can get this to work? Thanks for your assistance, code is below. ' Author: sebastien@xxxxxx_pittet_dot_org ' Date : 04.2005 ' Goal : Migrate the network printer connections ' Works WITHOUT PRNADMIN.DLL, a version with PRNAdmin is also available ' Version : PrintQMigrator.vbs ' Check www.pittet.org to get more information ! 'On Error Resume Next '@@@@@@@@@@@@@ ' MAIN PROGRAM '@@@@@@@@@@@@@ Const Title = "PrintQMigrator v.1.0 - sebastien@xxxxxx_pittet.org" 'Title InputBoxes Const ForReading = 1 Const DEFAULT_TEXTFILE = "ChangePrinter.txt" Dim strDefaultPrinter 'store the name of the default printer Dim InstalledPrinters 'Array of printer names Dim strNoParams 'Text displayed if no parameters is given Dim Textfile 'File which contains all printer information Dim OldPrintQueues() 'Dynamic array to store old print queue names, from the text file Dim NewPrintQueues() 'Dynamic array to store new print queue names, from the text file Dim fso 'File System Object Dim objTextFile 'Text file object Dim strNextLine 'Line of the text file Dim i 'Indice used to loop... Dim WshNetwork 'Use to work with the print queues (requested because no prnadmin.dll) strNoParams = "This Script reads a text file and set " & _ "migrate the print queues defined on this computer" & vbCrLf & vbCrLf & _ "Type the path of the file containing the information the script needs." & vbCrLf & VbCrLf 'Get the command line args SET Parameters = Wscript.arguments 'If no command line arguments provided, prompt for file If Parameters.Count = 0 Then Textfile = InputBox(strNoParams,Title, GetThisFolderPath & "\" & DEFAULT_TEXTFILE) Else Textfile = Parameters.item(0) End If If Textfile = "" or Not Right(TextFile,4) = ".txt" or Not FileExist (Textfile) Then Error=MsgBox("No valid input file provided. Stopping the script now.",vbokonly, Title) WScript.Quit(1) End If 'Read the text file and import it in a Array Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile (TextFile, ForReading) i=-1 While not objTextFile.AtEndOfStream i = i+1 Redim Preserve OldPrintQueues(i) ReDim Preserve NewPrintQueues(i) strLine = objTextFile.Readline 'Do not import the comment lines If Left(strLine,2) = "\\" Then OldPrintQueues(i) = Left(strLine,InStr(strline,";")-1) NewPrintQueues(i) = Mid(strline,InStr(strline,";")+1,Len (strline)) 'WScript.Echo OldPrintQueues(i) &", " & NewPrintQueues(i) End If Wend objTextFile.Close Set WshNetwork = CreateObject("WScript.Network") 'Store the name of the default Printer strDefaultPrinter = DefaultPrinter 'Loop through all printer connections on this computer/user strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") 'Loop in printer collection of this workstation/user For Each objPrinter in colInstalledPrinters If Left(objPrinter.Name, 2) = "\\" Then 'Work only On network printers 'Search the corresponding printer and create it i = 0 'set the indice at the beginning of the array (prepare to loop) Do Until i >= UBound(OldPrintQueues) 'Wscript.Echo UCase(objPrinter.Comment) If UCase(objPrinter.Name) = UCase(OldPrintQueues(i)) Then 'Create the connection to the new printer WshNetwork.AddWindowsPrinterConnection NewPrintQueues (i) If UCase(strDefaultPrinter) = UCase(objPrinter.Name) Then 'This is the default printer 'Set the default Printer WshNetwork.SetDefaultPrinter NewPrintQueues(i) End If 'Delete the printer connection WshNetwork.RemovePrinterConnection objPrinter.Name,True,True End If i = i + 1 Loop End If 'End of check for network printers Next 'End of the loop through the printers of this user Set WshNetwork = Nothing '@@@@@@@@@@@ ' Functions '@@@@@@@@@@@ '----------------- 'Return the defaut printer Function DefaultPrinter Dim strComputer Dim Result strComputer = "." Result = "" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root \cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters If objPrinter.Default = True Then Result = objPrinter.Name End If Next DefaultPrinter = Result End Function '----------------- 'Check If File Exist at a specified path (Boolean) Function FileExist (FileFullPath) Dim Fso Set Fso = CreateObject("Scripting.FileSystemObject") If (Fso.FileExists(FileFullPath)) Then FileExist = True Else FileExist = False End If End Function '----------------- 'Return the current script path Function GetThisFolderPath() Set fso = CreateObject("Scripting.FileSystemObject") Set file = fso.GetFile(wscript.scriptfullname) GetThisFolderPath=File.ParentFolder End Function '----------------- |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Printer Swaping Script Error 800708CA "AJ" <aragorn.m@xxxxxx> wrote in message news:ddb65dab-4087-440b-b72a-6e08b304b241@xxxxxx Quote: >I have a VBscript which I am hoping to use to remove old network > printers while adding new ones to replace them. I am getting error > 800708CA from this line in the code > "WshNetwork.RemovePrinterConnection objPrinter.Name,True,True" (line > 99) when trying to remove the old printer. Dose anyone have any idea > what is wrong and how I can get this to work? > > Thanks for your assistance, code is below. > > ' Author: sebastien@xxxxxx_pittet_dot_org > ' Date : 04.2005 > ' Goal : Migrate the network printer connections > ' Works WITHOUT PRNADMIN.DLL, a version with PRNAdmin is also > available > ' Version : PrintQMigrator.vbs > > ' Check www.pittet.org to get more information ! > > 'On Error Resume Next > > '@@@@@@@@@@@@@ > ' MAIN PROGRAM > '@@@@@@@@@@@@@ > > Const Title = "PrintQMigrator v.1.0 - sebastien@xxxxxx_pittet.org" > 'Title InputBoxes > Const ForReading = 1 > Const DEFAULT_TEXTFILE = "ChangePrinter.txt" > > Dim strDefaultPrinter 'store the name of the default printer > Dim InstalledPrinters 'Array of printer names > Dim strNoParams 'Text displayed if no parameters is given > Dim Textfile 'File which contains all printer information > Dim OldPrintQueues() 'Dynamic array to store old print queue names, > from the text file > Dim NewPrintQueues() 'Dynamic array to store new print queue names, > from the text file > Dim fso 'File System Object > Dim objTextFile 'Text file object > Dim strNextLine 'Line of the text file > Dim i 'Indice used to loop... > Dim WshNetwork 'Use to work with the print queues (requested because > no prnadmin.dll) > > strNoParams = "This Script reads a text file and set " & _ > "migrate the print queues defined on this computer" & vbCrLf & vbCrLf > & _ > "Type the path of the file containing the information the script > needs." & vbCrLf & VbCrLf > > 'Get the command line args > SET Parameters = Wscript.arguments > > 'If no command line arguments provided, prompt for file > If Parameters.Count = 0 Then > Textfile = InputBox(strNoParams,Title, GetThisFolderPath & "\" & > DEFAULT_TEXTFILE) > Else > Textfile = Parameters.item(0) > End If > > If Textfile = "" or Not Right(TextFile,4) = ".txt" or Not FileExist > (Textfile) Then > Error=MsgBox("No valid input file provided. Stopping the script > now.",vbokonly, Title) > WScript.Quit(1) > End If > > 'Read the text file and import it in a Array > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile (TextFile, ForReading) > > i=-1 > While not objTextFile.AtEndOfStream > i = i+1 > Redim Preserve OldPrintQueues(i) > ReDim Preserve NewPrintQueues(i) > > strLine = objTextFile.Readline > 'Do not import the comment lines > If Left(strLine,2) = "\\" Then > OldPrintQueues(i) = Left(strLine,InStr(strline,";")-1) > NewPrintQueues(i) = Mid(strline,InStr(strline,";")+1,Len > (strline)) > 'WScript.Echo OldPrintQueues(i) &", " & NewPrintQueues(i) > End If > Wend > > objTextFile.Close > > Set WshNetwork = CreateObject("WScript.Network") > > > 'Store the name of the default Printer > strDefaultPrinter = DefaultPrinter > > 'Loop through all printer connections on this computer/user > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") > Set colInstalledPrinters = objWMIService.ExecQuery _ > ("Select * from Win32_Printer") > > 'Loop in printer collection of this workstation/user > For Each objPrinter in colInstalledPrinters > If Left(objPrinter.Name, 2) = "\\" Then 'Work only On network > printers > 'Search the corresponding printer and create it > i = 0 'set the indice at the beginning of the array (prepare > to loop) > Do Until i >= UBound(OldPrintQueues) > 'Wscript.Echo UCase(objPrinter.Comment) > If UCase(objPrinter.Name) = UCase(OldPrintQueues(i)) Then > 'Create the connection to the new printer > WshNetwork.AddWindowsPrinterConnection NewPrintQueues > (i) > If UCase(strDefaultPrinter) = UCase(objPrinter.Name) > Then 'This is the default printer > 'Set the default Printer > WshNetwork.SetDefaultPrinter NewPrintQueues(i) > End If > 'Delete the printer connection > WshNetwork.RemovePrinterConnection > objPrinter.Name,True,True > End If > i = i + 1 > Loop > End If 'End of check for network printers > Next 'End of the loop through the printers of this user > > Set WshNetwork = Nothing > > > '@@@@@@@@@@@ > ' Functions > '@@@@@@@@@@@ > > '----------------- > > 'Return the defaut printer > Function DefaultPrinter > Dim strComputer > Dim Result > > strComputer = "." > Result = "" > > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root > \cimv2") > Set colInstalledPrinters = objWMIService.ExecQuery _ > ("Select * from Win32_Printer") > For Each objPrinter in colInstalledPrinters > If objPrinter.Default = True Then > Result = objPrinter.Name > End If > Next > DefaultPrinter = Result > End Function > > '----------------- > > 'Check If File Exist at a specified path (Boolean) > Function FileExist (FileFullPath) > Dim Fso > Set Fso = CreateObject("Scripting.FileSystemObject") > If (Fso.FileExists(FileFullPath)) Then > FileExist = True > Else > FileExist = False > End If > End Function > '----------------- > 'Return the current script path > Function GetThisFolderPath() > Set fso = CreateObject("Scripting.FileSystemObject") > Set file = fso.GetFile(wscript.scriptfullname) > GetThisFolderPath=File.ParentFolder > End Function > '----------------- example: WshNetwork.RemovePrinterConnection objPrinter.ServerName & "\" & objPrinter.ShareName, True, True -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Printer Swaping Script Error 800708CA On Mar 26, 1:10*pm, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > "AJ" <aragor...@xxxxxx> wrote in message > > news:ddb65dab-4087-440b-b72a-6e08b304b241@xxxxxx > > > > > Quote: > >I have a VBscript which I am hoping to use to remove old network > > printers while adding new ones to replace them. I am getting error > > 800708CA from this line in the code > > "WshNetwork.RemovePrinterConnection objPrinter.Name,True,True" (line > > 99) when trying to remove the old printer. Dose anyone have any idea > > what is wrong and how I can get this to work? Quote: > > Thanks for your assistance, code is below. Quote: > > ' Author: sebastien@xxxxxx_pittet_dot_org > > ' Date : 04.2005 > > ' Goal : Migrate the network printer connections > > ' Works WITHOUT PRNADMIN.DLL, a version with PRNAdmin is also > > available > > ' Version : PrintQMigrator.vbs Quote: > > ' Checkwww.pittet.orgto get more information ! Quote: > > 'On Error Resume Next Quote: > > '@@@@@@@@@@@@@ > > ' MAIN PROGRAM > > '@@@@@@@@@@@@@ Quote: > > Const Title = "PrintQMigrator v.1.0 - sebastien@xxxxxx_pittet.org" > > 'Title InputBoxes > > Const ForReading = 1 > > Const DEFAULT_TEXTFILE = "ChangePrinter.txt" Quote: > > Dim strDefaultPrinter 'store the name of the default printer > > Dim InstalledPrinters 'Array of printer names > > Dim strNoParams 'Text displayed if no parameters is given > > Dim Textfile 'File which contains all printer information > > Dim OldPrintQueues() 'Dynamic array to store old print queue names, > > from the text file > > Dim NewPrintQueues() 'Dynamic array to store new print queue names, > > from the text file > > Dim fso 'File System Object > > Dim objTextFile 'Text file object > > Dim strNextLine 'Line of the text file > > Dim i 'Indice used to loop... > > Dim WshNetwork 'Use to work with the print queues (requested because > > no prnadmin.dll) Quote: > > strNoParams = "This Script reads a text file and set " & _ > > "migrate the print queues defined on this computer" & vbCrLf & vbCrLf > > & _ > > "Type the path of the file containing the information the script > > needs." & vbCrLf & VbCrLf Quote: > > 'Get the command line args > > SET Parameters = Wscript.arguments Quote: > > 'If no command line arguments provided, prompt for file > > If Parameters.Count = 0 Then > > Textfile = InputBox(strNoParams,Title, GetThisFolderPath & "\" & > > DEFAULT_TEXTFILE) > > Else > > Textfile = Parameters.item(0) > > End If Quote: > > If Textfile = "" or Not Right(TextFile,4) = ".txt" or Not FileExist > > (Textfile) Then > > Error=MsgBox("No valid input file provided. Stopping the script > > now.",vbokonly, Title) > > WScript.Quit(1) > > End If Quote: > > 'Read the text file and import it in a Array > > Set objFSO = CreateObject("Scripting.FileSystemObject") > > Set objTextFile = objFSO.OpenTextFile (TextFile, ForReading) Quote: > > i=-1 > > While not objTextFile.AtEndOfStream > > * *i = i+1 > > * *Redim Preserve OldPrintQueues(i) > > * *ReDim Preserve NewPrintQueues(i) Quote: > > * *strLine = objTextFile.Readline > > * *'Do not import the comment lines > > * *If Left(strLine,2) = "\\" Then > > * * * *OldPrintQueues(i) = Left(strLine,InStr(strline,";")-1) > > * * * *NewPrintQueues(i) = Mid(strline,InStr(strline,";")+1,Len > > (strline)) > > * * * *'WScript.Echo OldPrintQueues(i) &", " & NewPrintQueues(i) > > * *End If > > Wend Quote: > > objTextFile.Close Quote: > > Set WshNetwork = CreateObject("WScript.Network") Quote: > > 'Store the name of the default Printer > > strDefaultPrinter = DefaultPrinter Quote: > > 'Loop through all printer connections on this computer/user > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:" _ > > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") > > Set colInstalledPrinters = objWMIService.ExecQuery _ > > ("Select * from Win32_Printer") Quote: > > 'Loop in printer collection of this workstation/user > > For Each objPrinter in colInstalledPrinters > > * *If Left(objPrinter.Name, 2) = "\\" Then 'Work only On network > > printers > > * * * *'Search the corresponding printer and create it > > * * * *i = 0 'set the indice at the beginning of the array (prepare > > to loop) > > * * * *Do Until i >= UBound(OldPrintQueues) > > * * * *'Wscript.Echo UCase(objPrinter.Comment) > > * * * * * *If UCase(objPrinter.Name) = UCase(OldPrintQueues(i)) Then > > * * * * * * * *'Create the connection to the new printer > > * * * * * * * *WshNetwork.AddWindowsPrinterConnection NewPrintQueues > > (i) > > * * * * * * * *If UCase(strDefaultPrinter) = UCase(objPrinter.Name) > > Then 'This is the default printer > > * * * * * * * * * *'Set the default Printer > > * * * * * * * * * *WshNetwork.SetDefaultPrinter NewPrintQueues(i) > > * * * * * * * *End If > > * * * * * * * *'Delete the printer connection > > * * * * * * * * WshNetwork.RemovePrinterConnection > > objPrinter.Name,True,True > > * * * * * *End If > > * * * * * *i = i + 1 > > * * * *Loop > > * *End If 'End of check for network printers > > Next 'End of the loop through the printers of this user Quote: > > Set WshNetwork = Nothing Quote: > > '@@@@@@@@@@@ > > ' Functions > > '@@@@@@@@@@@ Quote: > > '----------------- Quote: > > 'Return the defaut printer > > Function DefaultPrinter > > * *Dim strComputer > > * *Dim Result Quote: > > * *strComputer = "." > > * *Result = "" Quote: > > * *Set objWMIService = GetObject("winmgmts:" _ > > * * & "{impersonationLevel=impersonate}!\\" & strComputer & "\root > > \cimv2") > > * *Set colInstalledPrinters = objWMIService.ExecQuery _ > > * * ("Select * from Win32_Printer") > > * *For Each objPrinter in colInstalledPrinters > > * * * *If objPrinter.Default = True Then > > * * * * Result = objPrinter.Name > > * * * *End If > > * *Next > > * *DefaultPrinter = Result > > End Function Quote: > > '----------------- Quote: > > 'Check If File Exist at a specified path (Boolean) > > Function FileExist (FileFullPath) > > Dim Fso > > Set Fso = CreateObject("Scripting.FileSystemObject") > > If (Fso.FileExists(FileFullPath)) Then > > FileExist = True > > Else > > FileExist = False > > End If > > End Function > > '----------------- > > 'Return the current script path > > Function GetThisFolderPath() > > Set fso = CreateObject("Scripting.FileSystemObject") > > Set file = fso.GetFile(wscript.scriptfullname) > > GetThisFolderPath=File.ParentFolder > > End Function > > '----------------- > Does it help if you use .ServerName and .ShareName instead of .Name? For > example: > > WshNetwork.RemovePrinterConnection objPrinter.ServerName & "\" & > objPrinter.ShareName, True, True > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > --- Hide quoted text - > > - Show quoted text - Thanks for your reply. I have tried your sugestion as well as objPrinter.DeviceID. I have also tried using objPrinter.Delete_ insted of WshNetwork.RemovePrinterConnection, all to no avail. With objPrinter.Delete_ I get a slightly different error (80041001). The printers I am trying to remove are on my workstations and they have a lot of spaces in a long share name. For example "Canon iR5070 24th floor near Conference Room 24B" I know it is really long I would not have used such a name... I am running this on XP SP3 vbs is version5.7. I have done some extensive searching I can find many references to these error numbers but no answers... --AJ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script to install a "HP 5Si Printer" as a local printer | VB Script | |||
| Network printer deployment script | VB Script | |||
| Inactive printer-checking script | PowerShell | |||
| Shared Printer - Script | Vista networking & sharing | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||