|
| |||||||||
| Tags: add, ports, printers, script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Problem with script to add printers ports, need help.
I am trying to add a large quantity of printers to a new printserver. I first want to add the printer ports but I am running into a problem. Whenever I run the script below it errors out with "Access Denied". Just for the heck of it I ran the template script from the script center and I get the same error. Does anyone have an idea why I get that error? Am I missing something in my script? And yes I am admin on the box. Here is the script. Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") objExcel.Visible = True intRow = 2 Do Until objExcel.Cells(intRow,1).Value = "" strComputer = "." Set objWMIService = GetObject("winmgmts:") Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ objNewPort.Name = objExcel.Cells(intRow,5).Value objNewPort.Protocol = 1 objNewPort.HostAddress = objExcel.Cells(intRow,1).Value objNewPort.PortNumber = "9100" objNewPort.SNMPEnabled = False objNewPort.Put_ intRow = intRow + 1 Loop objExcel.Quit I appreciate any advice. Thanks, Ray |
|
#2
| |||
| |||
| Re: Problem with script to add printers ports, need help.
What line number. Is it happening on the "Put_". or the new instance. Put trace statements in file to see. "WScript.Echo "We Are here trace" ... etc. Last line to send output is line before failure. Or count lines from top of notepad starting with "1". -- Jim Vierra "rham" <rham@discussions.microsoft.com> wrote in message news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... >I am trying to add a large quantity of printers to a new printserver. I > first want to add the printer ports but I am running into a problem. > Whenever I run the script below it errors out with "Access Denied". > > Just for the heck of it I ran the template script from the script center > and > I get the same error. Does anyone have an idea why I get that error? Am > I > missing something in my script? And yes I am admin on the box. > > Here is the script. > > Set objExcel = CreateObject("Excel.Application") > Set objWorkbook = > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > objExcel.Visible = True > intRow = 2 > Do Until objExcel.Cells(intRow,1).Value = "" > strComputer = "." > Set objWMIService = GetObject("winmgmts:") > Set objNewPort = objWMIService.Get _ > ("Win32_TCPIPPrinterPort").SpawnInstance_ > objNewPort.Name = objExcel.Cells(intRow,5).Value > objNewPort.Protocol = 1 > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > objNewPort.PortNumber = "9100" > objNewPort.SNMPEnabled = False > objNewPort.Put_ > intRow = intRow + 1 > Loop > objExcel.Quit > > I appreciate any advice. > > Thanks, > > Ray |
|
#3
| |||
| |||
| Re: Problem with script to add printers ports, need help.
The error is occuring at the objnewPort.Put_ line. The error message states: Line:15 Char:2 Error: Access Denied Code: 80041003 Source: SWbemObjectEx Thanks, Ray "Jim Vierra" wrote: > What line number. Is it happening on the "Put_". or the new instance. > > Put trace statements in file to see. "WScript.Echo "We Are here trace" ... > etc. > > Last line to send output is line before failure. Or count lines from top of > notepad starting with "1". > -- > Jim Vierra > > "rham" <rham@discussions.microsoft.com> wrote in message > news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... > >I am trying to add a large quantity of printers to a new printserver. I > > first want to add the printer ports but I am running into a problem. > > Whenever I run the script below it errors out with "Access Denied". > > > > Just for the heck of it I ran the template script from the script center > > and > > I get the same error. Does anyone have an idea why I get that error? Am > > I > > missing something in my script? And yes I am admin on the box. > > > > Here is the script. > > > > Set objExcel = CreateObject("Excel.Application") > > Set objWorkbook = > > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > > objExcel.Visible = True > > intRow = 2 > > Do Until objExcel.Cells(intRow,1).Value = "" > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:") > > Set objNewPort = objWMIService.Get _ > > ("Win32_TCPIPPrinterPort").SpawnInstance_ > > objNewPort.Name = objExcel.Cells(intRow,5).Value > > objNewPort.Protocol = 1 > > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > > objNewPort.PortNumber = "9100" > > objNewPort.SNMPEnabled = False > > objNewPort.Put_ > > intRow = intRow + 1 > > Loop > > objExcel.Quit > > > > I appreciate any advice. > > > > Thanks, > > > > Ray > > > |
|
#4
| |||
| |||
| Re: Problem with script to add printers ports, need help.
What version of windows? Do you have admin rights on the machine? What service pack level? -- Jim Vierra "rham" <rham@discussions.microsoft.com> wrote in message news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... > The error is occuring at the objnewPort.Put_ line. The error message > states: > > Line:15 > Char:2 > Error: Access Denied > Code: 80041003 > Source: SWbemObjectEx > > Thanks, > > Ray > > > "Jim Vierra" wrote: > >> What line number. Is it happening on the "Put_". or the new instance. >> >> Put trace statements in file to see. "WScript.Echo "We Are here trace" >> ... >> etc. >> >> Last line to send output is line before failure. Or count lines from top >> of >> notepad starting with "1". >> -- >> Jim Vierra >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... >> >I am trying to add a large quantity of printers to a new printserver. I >> > first want to add the printer ports but I am running into a problem. >> > Whenever I run the script below it errors out with "Access Denied". >> > >> > Just for the heck of it I ran the template script from the script >> > center >> > and >> > I get the same error. Does anyone have an idea why I get that error? >> > Am >> > I >> > missing something in my script? And yes I am admin on the box. >> > >> > Here is the script. >> > >> > Set objExcel = CreateObject("Excel.Application") >> > Set objWorkbook = >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") >> > objExcel.Visible = True >> > intRow = 2 >> > Do Until objExcel.Cells(intRow,1).Value = "" >> > strComputer = "." >> > Set objWMIService = GetObject("winmgmts:") >> > Set objNewPort = objWMIService.Get _ >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ >> > objNewPort.Name = objExcel.Cells(intRow,5).Value >> > objNewPort.Protocol = 1 >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value >> > objNewPort.PortNumber = "9100" >> > objNewPort.SNMPEnabled = False >> > objNewPort.Put_ >> > intRow = intRow + 1 >> > Loop >> > objExcel.Quit >> > >> > I appreciate any advice. >> > >> > Thanks, >> > >> > Ray >> >> >> |
|
#5
| |||
| |||
| Re: Problem with script to add printers ports, need help.
Server 2003 Standard with all current patches except SP1. I am signed on with my domain account that has admin rights. "Jim Vierra" wrote: > What version of windows? > Do you have admin rights on the machine? > What service pack level? > > > -- > Jim Vierra > > "rham" <rham@discussions.microsoft.com> wrote in message > news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... > > The error is occuring at the objnewPort.Put_ line. The error message > > states: > > > > Line:15 > > Char:2 > > Error: Access Denied > > Code: 80041003 > > Source: SWbemObjectEx > > > > Thanks, > > > > Ray > > > > > > "Jim Vierra" wrote: > > > >> What line number. Is it happening on the "Put_". or the new instance. > >> > >> Put trace statements in file to see. "WScript.Echo "We Are here trace" > >> ... > >> etc. > >> > >> Last line to send output is line before failure. Or count lines from top > >> of > >> notepad starting with "1". > >> -- > >> Jim Vierra > >> > >> "rham" <rham@discussions.microsoft.com> wrote in message > >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... > >> >I am trying to add a large quantity of printers to a new printserver. I > >> > first want to add the printer ports but I am running into a problem. > >> > Whenever I run the script below it errors out with "Access Denied". > >> > > >> > Just for the heck of it I ran the template script from the script > >> > center > >> > and > >> > I get the same error. Does anyone have an idea why I get that error? > >> > Am > >> > I > >> > missing something in my script? And yes I am admin on the box. > >> > > >> > Here is the script. > >> > > >> > Set objExcel = CreateObject("Excel.Application") > >> > Set objWorkbook = > >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > >> > objExcel.Visible = True > >> > intRow = 2 > >> > Do Until objExcel.Cells(intRow,1).Value = "" > >> > strComputer = "." > >> > Set objWMIService = GetObject("winmgmts:") > >> > Set objNewPort = objWMIService.Get _ > >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ > >> > objNewPort.Name = objExcel.Cells(intRow,5).Value > >> > objNewPort.Protocol = 1 > >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > >> > objNewPort.PortNumber = "9100" > >> > objNewPort.SNMPEnabled = False > >> > objNewPort.Put_ > >> > intRow = intRow + 1 > >> > Loop > >> > objExcel.Quit > >> > > >> > I appreciate any advice. > >> > > >> > Thanks, > >> > > >> > Ray > >> > >> > >> > > > |
|
#6
| |||
| |||
| Re: Problem with script to add printers ports, need help.
I checked the WMI reference. All properties are read-only. This is probably not the way to create a port. It looks like it is used for getting info and status. You might try doing it with "Security" privilege on the "impersonate" clause. -- Jim Vierra "rham" <rham@discussions.microsoft.com> wrote in message news:E9B75824-9C8D-4D41-8741-25468183B913@microsoft.com... > Server 2003 Standard with all current patches except SP1. I am signed on > with my domain account that has admin rights. > > "Jim Vierra" wrote: > >> What version of windows? >> Do you have admin rights on the machine? >> What service pack level? >> >> >> -- >> Jim Vierra >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... >> > The error is occuring at the objnewPort.Put_ line. The error message >> > states: >> > >> > Line:15 >> > Char:2 >> > Error: Access Denied >> > Code: 80041003 >> > Source: SWbemObjectEx >> > >> > Thanks, >> > >> > Ray >> > >> > >> > "Jim Vierra" wrote: >> > >> >> What line number. Is it happening on the "Put_". or the new instance. >> >> >> >> Put trace statements in file to see. "WScript.Echo "We Are here trace" >> >> ... >> >> etc. >> >> >> >> Last line to send output is line before failure. Or count lines from >> >> top >> >> of >> >> notepad starting with "1". >> >> -- >> >> Jim Vierra >> >> >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... >> >> >I am trying to add a large quantity of printers to a new printserver. >> >> >I >> >> > first want to add the printer ports but I am running into a problem. >> >> > Whenever I run the script below it errors out with "Access Denied". >> >> > >> >> > Just for the heck of it I ran the template script from the script >> >> > center >> >> > and >> >> > I get the same error. Does anyone have an idea why I get that >> >> > error? >> >> > Am >> >> > I >> >> > missing something in my script? And yes I am admin on the box. >> >> > >> >> > Here is the script. >> >> > >> >> > Set objExcel = CreateObject("Excel.Application") >> >> > Set objWorkbook = >> >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") >> >> > objExcel.Visible = True >> >> > intRow = 2 >> >> > Do Until objExcel.Cells(intRow,1).Value = "" >> >> > strComputer = "." >> >> > Set objWMIService = GetObject("winmgmts:") >> >> > Set objNewPort = objWMIService.Get _ >> >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ >> >> > objNewPort.Name = objExcel.Cells(intRow,5).Value >> >> > objNewPort.Protocol = 1 >> >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value >> >> > objNewPort.PortNumber = "9100" >> >> > objNewPort.SNMPEnabled = False >> >> > objNewPort.Put_ >> >> > intRow = intRow + 1 >> >> > Loop >> >> > objExcel.Quit >> >> > >> >> > I appreciate any advice. >> >> > >> >> > Thanks, >> >> > >> >> > Ray >> >> >> >> >> >> >> >> >> |
|
#7
| |||
| |||
| Re: Problem with script to add printers ports, need help.
rham wrote: > I am trying to add a large quantity of printers to a new printserver. I > first want to add the printer ports but I am running into a problem. > Whenever I run the script below it errors out with "Access Denied". > > Just for the heck of it I ran the template script from the script center and > I get the same error. Does anyone have an idea why I get that error? Am I > missing something in my script? And yes I am admin on the box. > > Here is the script. > > Set objExcel = CreateObject("Excel.Application") > Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > objExcel.Visible = True > intRow = 2 > Do Until objExcel.Cells(intRow,1).Value = "" > strComputer = "." > Set objWMIService = GetObject("winmgmts:") > Set objNewPort = objWMIService.Get _ > ("Win32_TCPIPPrinterPort").SpawnInstance_ > objNewPort.Name = objExcel.Cells(intRow,5).Value > objNewPort.Protocol = 1 > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > objNewPort.PortNumber = "9100" > objNewPort.SNMPEnabled = False > objNewPort.Put_ > intRow = intRow + 1 > Loop > objExcel.Quit Hi, You cannot use Win32_TCPIPPrinterPort to add a port, as Jim wrote, all the properties in that class are Read-Only: http://msdn.microsoft.com/library/en...rinterport.asp Another alternative is to use the prnadmin.dll that comes with the MS Windows 2003 Server Resource Kit. With prnadmin.dll you can e.g. do the following port handling from e.g. vbscript: - Adding/deleting ports (standard local ports, TCP LPR/RAW ports) (local or remote) Windows Server 2003 Resource Kit Tools http://www.microsoft.com/downloads/d...DisplayLang=en (The kit will install on WinXP or later, but you can copy needed files over to other computers, and then run regsvr32.exe against prnadmin.dll) More about PrnAdmin (from the RK help file): Printer Administration Objects (PrnAdmin) is a COM-based tool that provides large-scale, noninteractive control of printers, drivers, and ports on local and remote computers. Using PrnAdmin, you can: Add and delete a local or remote printer. Add and delete printer connections. Add and delete a local or remote form. Add and delete a local or remote standard TCP/IP port (of type Line Printer Remote (LPR) or RAW). Add and delete a local or remote driver. View a list of printers, ports, drivers, and forms on a local or remote computer. Control and configure a local or remote printer. PrnAdmin consists of several scriptable COM objects residing in Prnadmin.dll, which functions as a wrapper around Printui.dll. Several Microsoft Visual Basic Script (VBScript) sample files are included with the tool. Note For more detailed information on how to use PrnAdmin.DLL, see Prnadmin.doc. This white paper provides additional information on printer, drivers, ports and forms to help administrators and programmers manage a large number of local and remote printers. Corresponding Operating System Features All the functionality of prnadmin.dll can be duplicated using the printers folder and various wizards. Converting printer ports from LPR to Standard TCP/IP is the only functionality in prnadmin.dll for which there is no corresponding GUI. For more information about PrnAdmin and the Windows Management Instrumentation (WMI) scripts in Windows Server 2003, see Designing and Deploying Print Servers(http://go.microsoft.com/fwlink/?LinkID=4745) in the Windows Server 2003 Deployment Kit. Files Required Prnadmin.dll The following sample VBScript files are also included: Prnadmin.doc Clean.vbs Clone.vbs (there is no WMI equivalent for the cloning script) Conall.vbs Defprn.vbs Drvmgr.vbs Forms.vbs Persist.vbs Portconv.vbs Portmgr.vbs Prncfg.vbs Prnctrl.vbs Prndata.vbs Prnmgr.vbs and HOW TO: Programmatically Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script in Microsoft Windows 2000 http://support.microsoft.com/default...b;en-us;321025 -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scr...r/default.mspx |
|
#8
| |||
| |||
| Re: Problem with script to add printers ports, need help.
I created this script on a WinXP machine without any problems but it doesn't work on 2k3. I basically copied the template from the Script Center that says it works on Windows 2003(See below). Set objWMIService = GetObject("winmgmts:") Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ objNewPort.Name = "IP_169.254.110.14" objNewPort.Protocol = 1 objNewPort.HostAddress = "169.254.110.14" objNewPort.PortNumber = "9999" objNewPort.SNMPEnabled = False objNewPort.Put_ Also, I did try to do the impersonate privilege without success. Very frustrating. "Jim Vierra" wrote: > I checked the WMI reference. All properties are read-only. This is > probably not the way to create a port. It looks like it is used for getting > info and status. > > You might try doing it with "Security" privilege on the "impersonate" > clause. > > -- > Jim Vierra > > "rham" <rham@discussions.microsoft.com> wrote in message > news:E9B75824-9C8D-4D41-8741-25468183B913@microsoft.com... > > Server 2003 Standard with all current patches except SP1. I am signed on > > with my domain account that has admin rights. > > > > "Jim Vierra" wrote: > > > >> What version of windows? > >> Do you have admin rights on the machine? > >> What service pack level? > >> > >> > >> -- > >> Jim Vierra > >> > >> "rham" <rham@discussions.microsoft.com> wrote in message > >> news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... > >> > The error is occuring at the objnewPort.Put_ line. The error message > >> > states: > >> > > >> > Line:15 > >> > Char:2 > >> > Error: Access Denied > >> > Code: 80041003 > >> > Source: SWbemObjectEx > >> > > >> > Thanks, > >> > > >> > Ray > >> > > >> > > >> > "Jim Vierra" wrote: > >> > > >> >> What line number. Is it happening on the "Put_". or the new instance. > >> >> > >> >> Put trace statements in file to see. "WScript.Echo "We Are here trace" > >> >> ... > >> >> etc. > >> >> > >> >> Last line to send output is line before failure. Or count lines from > >> >> top > >> >> of > >> >> notepad starting with "1". > >> >> -- > >> >> Jim Vierra > >> >> > >> >> "rham" <rham@discussions.microsoft.com> wrote in message > >> >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... > >> >> >I am trying to add a large quantity of printers to a new printserver. > >> >> >I > >> >> > first want to add the printer ports but I am running into a problem. > >> >> > Whenever I run the script below it errors out with "Access Denied". > >> >> > > >> >> > Just for the heck of it I ran the template script from the script > >> >> > center > >> >> > and > >> >> > I get the same error. Does anyone have an idea why I get that > >> >> > error? > >> >> > Am > >> >> > I > >> >> > missing something in my script? And yes I am admin on the box. > >> >> > > >> >> > Here is the script. > >> >> > > >> >> > Set objExcel = CreateObject("Excel.Application") > >> >> > Set objWorkbook = > >> >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > >> >> > objExcel.Visible = True > >> >> > intRow = 2 > >> >> > Do Until objExcel.Cells(intRow,1).Value = "" > >> >> > strComputer = "." > >> >> > Set objWMIService = GetObject("winmgmts:") > >> >> > Set objNewPort = objWMIService.Get _ > >> >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ > >> >> > objNewPort.Name = objExcel.Cells(intRow,5).Value > >> >> > objNewPort.Protocol = 1 > >> >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > >> >> > objNewPort.PortNumber = "9100" > >> >> > objNewPort.SNMPEnabled = False > >> >> > objNewPort.Put_ > >> >> > intRow = intRow + 1 > >> >> > Loop > >> >> > objExcel.Quit > >> >> > > >> >> > I appreciate any advice. > >> >> > > >> >> > Thanks, > >> >> > > >> >> > Ray > >> >> > >> >> > >> >> > >> > >> > >> > > > |
|
#9
| |||
| |||
| Re: Problem with script to add printers ports, need help.
rham, Torgeir the following is from WMI docs. I tested on WS2003 SP1 which should have all updates that XP has. I suspect that WMI allows spawn to create extra pieces such as elements of a collection. TCPIPPrinterPorts looks to be a repository of instance pointers but not where they are created. If you manually reset a port it only has a name in it's TCPIPPrinter port instance. The rest of the information is held elsewhere. If we can find which class is actually being created we may be able to do it a different way. In my experience, for security reasons, many things are more tightly controlled on server products. This may account for the difference. For practical use, Torgeirs suggestion to use the RK dll is the best here as it should guarantee that the script will work on all versions of Windows the same way. WMI documentation. Some WMI classes (including Win32_Share and Win32_Process) include a Create method. If a class includes the Create method, that method can be used to create such things as a new shared folder or a new process. (or a new port) Creating a new resource requires you to use the Get method to bind to the actual WMI class (rather than retrieve instances of the class). After you have an object representing the class, use the SpawnInstance_ method to create a new, "blank," instance of the class. Configure properties for the instance, and then call the Create method. TCPIPPrinterPort has no "Create" method in Windows 2003. Interestingly it is marked as "Supports Create=True" on both XP and WS2003 which leads me to believe that it is either security or a bug. If WS2003 is in a Domain or is a DC then perhaps AD is overriding the creation due to schema restrictions; assuming the port exists in AD. The error is "Access Denied" as opposed to an object creation error that comes when the object can't be created due to an underlying missing component in the COM object. I checked DCOM on both XP and WS2003 and found no differences between WMI on either machine. Of course we still have individual security on WMI objects. The object security showed the "Security" permission when I added it to the connect but it may require an extra internal privilege. I tested on a non-domain connected XP machine and it worked correctly and all of the properties fill in unlike WS2003. I suspect security or a bug. Solving this would allow for a more consistent methodology when admins use WMI. Too many external solutions are retro to the MS/WMI philosophy. We need to contact the WMI team and have them respond to this issue. -- Jim Vierra "rham" <rham@discussions.microsoft.com> wrote in message news:028557A8-C202-4458-AB7F-368F7C9A91C5@microsoft.com... >I created this script on a WinXP machine without any problems but it doesn't > work on 2k3. I basically copied the template from the Script Center that > says it works on Windows 2003(See below). > > Set objWMIService = GetObject("winmgmts:") > Set objNewPort = objWMIService.Get _ > ("Win32_TCPIPPrinterPort").SpawnInstance_ > objNewPort.Name = "IP_169.254.110.14" > objNewPort.Protocol = 1 > objNewPort.HostAddress = "169.254.110.14" > objNewPort.PortNumber = "9999" > objNewPort.SNMPEnabled = False > objNewPort.Put_ > > Also, I did try to do the impersonate privilege without success. Very > frustrating. > > "Jim Vierra" wrote: > >> I checked the WMI reference. All properties are read-only. This is >> probably not the way to create a port. It looks like it is used for getting >> info and status. >> >> You might try doing it with "Security" privilege on the "impersonate" >> clause. >> >> -- >> Jim Vierra >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> news:E9B75824-9C8D-4D41-8741-25468183B913@microsoft.com... >> > Server 2003 Standard with all current patches except SP1. I am signed on >> > with my domain account that has admin rights. >> > >> > "Jim Vierra" wrote: >> > >> >> What version of windows? >> >> Do you have admin rights on the machine? >> >> What service pack level? >> >> >> >> >> >> -- >> >> Jim Vierra >> >> >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> >> news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... >> >> > The error is occuring at the objnewPort.Put_ line. The error message >> >> > states: >> >> > >> >> > Line:15 >> >> > Char:2 >> >> > Error: Access Denied >> >> > Code: 80041003 >> >> > Source: SWbemObjectEx >> >> > >> >> > Thanks, >> >> > >> >> > Ray >> >> > >> >> > >> >> > "Jim Vierra" wrote: >> >> > >> >> >> What line number. Is it happening on the "Put_". or the new instance. >> >> >> >> >> >> Put trace statements in file to see. "WScript.Echo "We Are here trace" >> >> >> ... >> >> >> etc. >> >> >> >> >> >> Last line to send output is line before failure. Or count lines from >> >> >> top >> >> >> of >> >> >> notepad starting with "1". >> >> >> -- >> >> >> Jim Vierra >> >> >> >> >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> >> >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... >> >> >> >I am trying to add a large quantity of printers to a new printserver. >> >> >> >I >> >> >> > first want to add the printer ports but I am running into a problem. >> >> >> > Whenever I run the script below it errors out with "Access Denied". >> >> >> > >> >> >> > Just for the heck of it I ran the template script from the script >> >> >> > center >> >> >> > and >> >> >> > I get the same error. Does anyone have an idea why I get that >> >> >> > error? >> >> >> > Am >> >> >> > I >> >> >> > missing something in my script? And yes I am admin on the box. >> >> >> > >> >> >> > Here is the script. >> >> >> > >> >> >> > Set objExcel = CreateObject("Excel.Application") >> >> >> > Set objWorkbook = >> >> >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") >> >> >> > objExcel.Visible = True >> >> >> > intRow = 2 >> >> >> > Do Until objExcel.Cells(intRow,1).Value = "" >> >> >> > strComputer = "." >> >> >> > Set objWMIService = GetObject("winmgmts:") >> >> >> > Set objNewPort = objWMIService.Get _ >> >> >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ >> >> >> > objNewPort.Name = objExcel.Cells(intRow,5).Value >> >> >> > objNewPort.Protocol = 1 >> >> >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value >> >> >> > objNewPort.PortNumber = "9100" >> >> >> > objNewPort.SNMPEnabled = False >> >> >> > objNewPort.Put_ >> >> >> > intRow = intRow + 1 >> >> >> > Loop >> >> >> > objExcel.Quit >> >> >> > >> >> >> > I appreciate any advice. >> >> >> > >> >> >> > Thanks, >> >> >> > >> >> >> > Ray >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> |
|
#10
| |||
| |||
| Re: Problem with script to add printers ports, need help.
Jim and Torgeir, thank you for your help. Ray "Torgeir Bakken (MVP)" wrote: > rham wrote: > > > I am trying to add a large quantity of printers to a new printserver. I > > first want to add the printer ports but I am running into a problem. > > Whenever I run the script below it errors out with "Access Denied". > > > > Just for the heck of it I ran the template script from the script center and > > I get the same error. Does anyone have an idea why I get that error? Am I > > missing something in my script? And yes I am admin on the box. > > > > Here is the script. > > > > Set objExcel = CreateObject("Excel.Application") > > Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") > > objExcel.Visible = True > > intRow = 2 > > Do Until objExcel.Cells(intRow,1).Value = "" > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:") > > Set objNewPort = objWMIService.Get _ > > ("Win32_TCPIPPrinterPort").SpawnInstance_ > > objNewPort.Name = objExcel.Cells(intRow,5).Value > > objNewPort.Protocol = 1 > > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value > > objNewPort.PortNumber = "9100" > > objNewPort.SNMPEnabled = False > > objNewPort.Put_ > > intRow = intRow + 1 > > Loop > > objExcel.Quit > Hi, > > You cannot use Win32_TCPIPPrinterPort to add a port, as Jim wrote, > all the properties in that class are Read-Only: > http://msdn.microsoft.com/library/en...rinterport.asp > > > Another alternative is to use the prnadmin.dll that comes with the > MS Windows 2003 Server Resource Kit. > > With prnadmin.dll you can e.g. do the following port handling from > e.g. vbscript: > > - Adding/deleting ports (standard local ports, TCP LPR/RAW ports) > (local or remote) > > Windows Server 2003 Resource Kit Tools > http://www.microsoft.com/downloads/d...DisplayLang=en > > (The kit will install on WinXP or later, but you can copy needed > files over to other computers, and then run regsvr32.exe against > prnadmin.dll) > > > More about PrnAdmin (from the RK help file): > > Printer Administration Objects (PrnAdmin) is a COM-based tool that > provides large-scale, noninteractive control of printers, drivers, > and ports on local and remote computers. > > Using PrnAdmin, you can: > > Add and delete a local or remote printer. > Add and delete printer connections. > Add and delete a local or remote form. > Add and delete a local or remote standard TCP/IP port (of type > Line Printer Remote (LPR) or RAW). > Add and delete a local or remote driver. > View a list of printers, ports, drivers, and forms on a local or > remote computer. > Control and configure a local or remote printer. > > > PrnAdmin consists of several scriptable COM objects residing in > Prnadmin.dll, which functions as a wrapper around Printui.dll. > Several Microsoft Visual Basic Script (VBScript) sample files are > included with the tool. > > Note > > For more detailed information on how to use PrnAdmin.DLL, see > Prnadmin.doc. This white paper provides additional information on > printer, drivers, ports and forms to help administrators and > programmers manage a large number of local and remote printers. > > Corresponding Operating System Features > > All the functionality of prnadmin.dll can be duplicated using the > printers folder and various wizards. Converting printer ports from > LPR to Standard TCP/IP is the only functionality in prnadmin.dll > for which there is no corresponding GUI. > > For more information about PrnAdmin and the Windows Management > Instrumentation (WMI) scripts in Windows Server 2003, see > Designing and Deploying Print > Servers(http://go.microsoft.com/fwlink/?LinkID=4745) in the > Windows Server 2003 Deployment Kit. > > > Files Required > > Prnadmin.dll > > The following sample VBScript files are also included: > > Prnadmin.doc > Clean.vbs > Clone.vbs (there is no WMI equivalent for the cloning script) > Conall.vbs > Defprn.vbs > Drvmgr.vbs > Forms.vbs > Persist.vbs > Portconv.vbs > Portmgr.vbs > Prncfg.vbs > Prnctrl.vbs > Prndata.vbs > Prnmgr.vbs > > > and > > HOW TO: Programmatically Create a Printer and Printer Port by > Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script > in Microsoft Windows 2000 > http://support.microsoft.com/default...b;en-us;321025 > > > > -- > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway > Administration scripting examples and an ONLINE version of > the 1328 page Scripting Guide: > http://www.microsoft.com/technet/scr...r/default.mspx > |
|
#11
| |||
| |||
| Re: Problem with script to add printers ports, need help.
Added information. Extended error on manual creation using wbemtest shows "abstract class" error and parameter error. Trying to delete instance with wbemtest throws "access denied" error. This seems to point to security as both of these work without error on XP. When checking privileges I find that WS2003 requires "SeLoadDriverPrivilege" and XP does not define any extra privileges. -- Jim Vierra "Jim Vierra" <jvierra@msn.com> wrote in message news:eekCl4aUFHA.4056@TK2MSFTNGP15.phx.gbl... rham, Torgeir the following is from WMI docs. I tested on WS2003 SP1 which should have all updates that XP has. I suspect that WMI allows spawn to create extra pieces such as elements of a collection. TCPIPPrinterPorts looks to be a repository of instance pointers but not where they are created. If you manually reset a port it only has a name in it's TCPIPPrinter port instance. The rest of the information is held elsewhere. If we can find which class is actually being created we may be able to do it a different way. In my experience, for security reasons, many things are more tightly controlled on server products. This may account for the difference. For practical use, Torgeirs suggestion to use the RK dll is the best here as it should guarantee that the script will work on all versions of Windows the same way. WMI documentation. Some WMI classes (including Win32_Share and Win32_Process) include a Create method. If a class includes the Create method, that method can be used to create such things as a new shared folder or a new process. (or a new port) Creating a new resource requires you to use the Get method to bind to the actual WMI class (rather than retrieve instances of the class). After you have an object representing the class, use the SpawnInstance_ method to create a new, "blank," instance of the class. Configure properties for the instance, and then call the Create method. TCPIPPrinterPort has no "Create" method in Windows 2003. Interestingly it is marked as "Supports Create=True" on both XP and WS2003 which leads me to believe that it is either security or a bug. If WS2003 is in a Domain or is a DC then perhaps AD is overriding the creation due to schema restrictions; assuming the port exists in AD. The error is "Access Denied" as opposed to an object creation error that comes when the object can't be created due to an underlying missing component in the COM object. I checked DCOM on both XP and WS2003 and found no differences between WMI on either machine. Of course we still have individual security on WMI objects. The object security showed the "Security" permission when I added it to the connect but it may require an extra internal privilege. I tested on a non-domain connected XP machine and it worked correctly and all of the properties fill in unlike WS2003. I suspect security or a bug. Solving this would allow for a more consistent methodology when admins use WMI. Too many external solutions are retro to the MS/WMI philosophy. We need to contact the WMI team and have them respond to this issue. -- Jim Vierra "rham" <rham@discussions.microsoft.com> wrote in message news:028557A8-C202-4458-AB7F-368F7C9A91C5@microsoft.com... >I created this script on a WinXP machine without any problems but it doesn't > work on 2k3. I basically copied the template from the Script Center that > says it works on Windows 2003(See below). > > Set objWMIService = GetObject("winmgmts:") > Set objNewPort = objWMIService.Get _ > ("Win32_TCPIPPrinterPort").SpawnInstance_ > objNewPort.Name = "IP_169.254.110.14" > objNewPort.Protocol = 1 > objNewPort.HostAddress = "169.254.110.14" > objNewPort.PortNumber = "9999" > objNewPort.SNMPEnabled = False > objNewPort.Put_ > > Also, I did try to do the impersonate privilege without success. Very > frustrating. > > "Jim Vierra" wrote: > >> I checked the WMI reference. All properties are read-only. This is >> probably not the way to create a port. It looks like it is used for getting >> info and status. >> >> You might try doing it with "Security" privilege on the "impersonate" >> clause. >> >> -- >> Jim Vierra >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> news:E9B75824-9C8D-4D41-8741-25468183B913@microsoft.com... >> > Server 2003 Standard with all current patches except SP1. I am signed on >> > with my domain account that has admin rights. >> > >> > "Jim Vierra" wrote: >> > >> >> What version of windows? >> >> Do you have admin rights on the machine? >> >> What service pack level? >> >> >> >> >> >> -- >> >> Jim Vierra >> >> >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> >> news:E885E46B-48B3-42D7-92E7-3F4F724D9BBA@microsoft.com... >> >> > The error is occuring at the objnewPort.Put_ line. The error message >> >> > states: >> >> > >> >> > Line:15 >> >> > Char:2 >> >> > Error: Access Denied >> >> > Code: 80041003 >> >> > Source: SWbemObjectEx >> >> > >> >> > Thanks, >> >> > >> >> > Ray >> >> > >> >> > >> >> > "Jim Vierra" wrote: >> >> > >> >> >> What line number. Is it happening on the "Put_". or the new instance. >> >> >> >> >> >> Put trace statements in file to see. "WScript.Echo "We Are here trace" >> >> >> ... >> >> >> etc. >> >> >> >> >> >> Last line to send output is line before failure. Or count lines from >> >> >> top >> >> >> of >> >> >> notepad starting with "1". >> >> >> -- >> >> >> Jim Vierra >> >> >> >> >> >> "rham" <rham@discussions.microsoft.com> wrote in message >> >> >> news:103C6124-3C6E-45F0-99BB-2F66BE21DA08@microsoft.com... >> >> >> >I am trying to add a large quantity of printers to a new printserver. >> >> >> >I >> >> >> > first want to add the printer ports but I am running into a problem. >> >> >> > Whenever I run the script below it errors out with "Access Denied". >> >> >> > >> >> >> > Just for the heck of it I ran the template script from the script >> >> >> > center >> >> >> > and >> >> >> > I get the same error. Does anyone have an idea why I get that >> >> >> > error? >> >> >> > Am >> >> >> > I >> >> >> > missing something in my script? And yes I am admin on the box. >> >> >> > >> >> >> > Here is the script. >> >> >> > >> >> >> > Set objExcel = CreateObject("Excel.Application") >> >> >> > Set objWorkbook = >> >> >> > objExcel.Workbooks.Open("C:\Scripts\Printer\New_ports.xls") >> >> >> > objExcel.Visible = True >> >> >> > intRow = 2 >> >> >> > Do Until objExcel.Cells(intRow,1).Value = "" >> >> >> > strComputer = "." >> >> >> > Set objWMIService = GetObject("winmgmts:") >> >> >> > Set objNewPort = objWMIService.Get _ >> >> >> > ("Win32_TCPIPPrinterPort").SpawnInstance_ >> >> >> > objNewPort.Name = objExcel.Cells(intRow,5).Value >> >> >> > objNewPort.Protocol = 1 >> >> >> > objNewPort.HostAddress = objExcel.Cells(intRow,1).Value >> >> >> > objNewPort.PortNumber = "9100" >> >> >> > objNewPort.SNMPEnabled = False >> >> >> > objNewPort.Put_ >> >> >> > intRow = intRow + 1 >> >> >> > Loop >> >> >> > objExcel.Quit >> >> >> > >> >> >> > I appreciate any advice. >> >> >> > >> >> >> > Thanks, >> >> >> > >> >> >> > Ray >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> |
|
#12
| |||
| |||
| Same Issue
I have been experiencing the exact same issue. Server: Windows Server 2003 R2, SP1 Workstation: Windows XP Professional, SP2 The script, which I will paste below, works fine on my XP machine. I can create the port AND the printer on my XP workstation. I have found that Win32_TCPIPPrinterPort WILL work on my server. The port will get created just fine, but the printer will not on the server. I am BRAND NEW to VBScript, my experience is limited, and I am learning as I go along. I'd like to know if I have to abandon this script and use the RK as recommended previously, or if I can "fix" this to work properly... Here is my script: Code: Dim Computer, DriverName, DriverInf, IPAddress, PrinterHostName, PortName
Dim WMI, NewPort, NewDriver, NewPrinter
Dim ArgObj, var1
Dim strComputer, objWMIService, objPrinter
Set ArgObj = WScript.Arguments
var1 = ArgObj(0)
Computer = "."
DriverName = "HP Universal Printing PCL 6"
PrinterHostName = var1 & ".fabrikam.loc"
IPAddress = PrinterHostName
' END CALLOUT A
WScript.Echo "PrinterHostName: " & PrinterHostName
PortName = PrinterHostName
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate" _
& ",(LoadDriver)}!//" & Computer & "/root/cimv2")
Set NewPort = WMI.Get("Win32_TCPIPPrinterPort").SpawnInstance_
NewPort.HostAddress = IPAddress
NewPort.Name = PortName
NewPort.Protocol = 1
NewPort.SNMPEnabled = 1
NewPort.SNMPCommunity = "public"
NewPort.Put_
WScript.Echo "Created printer port: " & PortName
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = DriverName
objPrinter.PortName = PortName
objPrinter.DeviceID = var1
objPrinter.Location = var1
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = var1
objPrinter.Default = True
objPrinter.Put_
WScript.Echo "Created printer: " & var1
WScript.Echo " Using Driver: " & DriverName
WScript.Echo " Shared As: " & var1
WScript.Echo " On Port: " & PortName |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Problem with script to add printers ports, need help." | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Printers disappear under Printers & Faxes | flupsie | Hardware Peripherals | 4 | 01-06-2011 10:40 AM |
| how to create printers in login script | Mehbs | Windows Server Help | 6 | 19-08-2009 11:13 AM |
| Problem with USB ports | Lord | Hardware Peripherals | 4 | 09-04-2009 11:08 PM |
| Problem with script in order to open another script in an extra window | Samsher | Software Development | 2 | 14-01-2009 01:25 PM |
| adding tcp/ip printer ports and installing printers on windows 200 | thebucs | Windows Server Help | 4 | 09-06-2006 09:45 AM |