Re: Problem with script to add printers ports, need help.
- From: "rham" <rham@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 May 2005 13:12:06 -0700
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-us/wmisdk/wmi/win32_tcpipprinterport.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/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&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.aspx?scid=kb;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/scriptcenter/default.mspx
>
.
- References:
- Problem with script to add printers ports, need help.
- From: rham
- Re: Problem with script to add printers ports, need help.
- From: Torgeir Bakken \(MVP\)
- Problem with script to add printers ports, need help.
- Prev by Date: WSH code
- Next by Date: RE: Add a domain user group to local computer administrator group
- Previous by thread: Re: Problem with script to add printers ports, need help.
- Next by thread: Add a domain user group to local computer administrator group
- Index(es):
Relevant Pages
|