Script to change the local printer port - error 80041001

P

Pedro Lima

Dear Friends,

We will rename a lot of client machines here in the network - all of them
are running Windows XP with SP2. The problem behind this fact is obvious:
many workstations using local ports that are not really "local" will face
discontinued printing services. I have made a script - based on others found
in the internet - that try to change the port. The problem is that it doesn't
work. The error is a generic failure in SWbemObjectEx (80041001) in line 9.
Here is the code:

Line 1: strComputer = "."
Line 2: Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Line 3:
Line 4: Set colPrinters = objWMIService.ExecQuery ("Select * from
Win32_Printer")
Line 5:
Line 6: For Each objPrinter in colPrinters
Line 7: If objPrinter.PortName = "\\sieci_sso01\BrotherH" Then
Line 8: objPrinter.PortName = "\\stici_sso01\BrotherH"
Line 9: objPrinter.Put_
Line10: End If
Line11: Next

Well... Does anybody have a solution for this ? This scenario is easily
reproducible in any environment, so you can see the error in your machine to
try to figure out why it happens.
 
A

Alan Morris [MSFT]

How are you creating the new Local Port?

"\\stici_sso01\BrotherH"

if you do not add the port, it cannot be set

prncnfg -t -p PRINTER -r "\\newserver\oldshare"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Unable to configure printer PRINTER Error 0x80041001 Generic failure
Operation PutInstance
Provider Win32 Provider
Description The specified port is unknown.
Win32 error code 1796

--
Alan Morris
Windows Printing Team
Search the Microsoft Knowledge Base here:
http://support.microsoft.com/search/?adv=1

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

Pedro Lima

Alan,

Thank you for your answer to my post. I have just one more question: how can
I add a local port first ? I have seen examples on how to do it, but only on
IP ports. I have not seen redirection ports - like my case. I have tried the
command you showed in your last post, but it didn't work out. My version of
prncfg is the one that comes with Windows 2003 resource kit that is available
for download in microsoft web page.

Greatings,
 
P

Pedro Lima

Guys... Mr. Alan (thanks Alan) gave me part of the solution. He pointed to me
that I had to create the port first. Then, God gave me a light to find the
rest of the solution to my problem. Since there is not an easy way to create
a port, I decided to create it directly in the registry. I share with you the
script that is working! Yes!!!

strkey = "Software\Microsoft\Windows NT\CurrentVersion\Ports"
strType = "REG_SZ"
strComputer = "."
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
For Each objPrinter in colPrinters
If objPrinter.PortName = "\\sieci_sso01\BrotherH" Then
strValue = "\\stici_sso01\BrotherH"
call createport(strkey, strvalue, strtype)
objPrinter.PortName = strValue
objPrinter.Put_
End If
Next

Function createport(key, value, type)
Set objService = objWMIService.ExecQuery ("Select * from Win32_Service
Where Name = 'Spooler'")
For Each objService in ObjService
objService.StopService()
const HKEY_LOCAL_MACHINE=&H80000002
set regkey=GetObject("winmgmts:root\default:StdRegProv")
createkey=regkey.setstringvalue(HKEY_LOCAL_MACHINE,Key,Value,"")
set regkey=nothing
objService.StartService()
Next
End Function
 
L

lorenzo

Pedro Lima said:
Dear Friends,

We will rename a lot of client machines here in the network - all of them
are running Windows XP with SP2. The problem behind this fact is obvious:
many workstations using local ports that are not really "local" will face
discontinued printing services. I have made a script - based on others found
in the internet - that try to change the port. The problem is that it doesn't
work. The error is a generic failure in SWbemObjectEx (80041001) in line 9.
Here is the code:

Line 1: strComputer = "."
Line 2: Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Line 3:
Line 4: Set colPrinters = objWMIService.ExecQuery ("Select * from
Win32_Printer")
Line 5:
Line 6: For Each objPrinter in colPrinters
Line 7: If objPrinter.PortName = "\\sieci_sso01\BrotherH" Then
Line 8: objPrinter.PortName = "\\stici_sso01\BrotherH"
Line 9: objPrinter.Put_
Line10: End If
Line11: Next

Well... Does anybody have a solution for this ? This scenario is easily
reproducible in any environment, so you can see the error in your machine to
try to figure out why it happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top