Welcome to ServerForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Problem with script to add printers ports, need help.

 
   Windows Server (Home) -> Windows Server Scripting RSS
Next:  Automate VPN and Remote Desktop ??  
Author Message
rham

External


Since: May 05, 2005
Posts: 4



(Msg. 1) Posted: Thu May 05, 2005 9:12 am
Post subject: Problem with script to add printers ports, need help.
Archived from groups: microsoft>public>windows>server>scripting (more info?)

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

 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
Jim Vierra

External


Since: Apr 21, 2005
Posts: 76



(Msg. 2) Posted: Thu May 05, 2005 1:07 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.DeleteThis@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

 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
rham

External


Since: May 05, 2005
Posts: 4



(Msg. 3) Posted: Thu May 05, 2005 1:07 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.DeleteThis@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
>
>
>
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
Jim Vierra

External


Since: Apr 21, 2005
Posts: 76



(Msg. 4) Posted: Thu May 05, 2005 2:06 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

What version of windows?
Do you have admin rights on the machine?
What service pack level?


--
Jim Vierra

"rham" <rham.TakeThisOut@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.TakeThisOut@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
>>
>>
>>
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
rham

External


Since: May 05, 2005
Posts: 4



(Msg. 5) Posted: Thu May 05, 2005 2:06 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 DeleteThis @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 DeleteThis @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
> >>
> >>
> >>
>
>
>
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
Jim Vierra

External


Since: Apr 21, 2005
Posts: 76



(Msg. 6) Posted: Thu May 05, 2005 3:08 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.TakeThisOut@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.TakeThisOut@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.TakeThisOut@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
>> >>
>> >>
>> >>
>>
>>
>>
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
rham

External


Since: May 05, 2005
Posts: 4



(Msg. 7) Posted: Thu May 05, 2005 3:08 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.DeleteThis@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.DeleteThis@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.DeleteThis@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
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
greggplatinum

External


Since: Jun 27, 2007
Posts: 1



(Msg. 8) Posted: Wed Jun 27, 2007 8:16 pm
Post subject: Re: Problem with script to add printers ports, need help. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

--------------------


--
greggplatinum
------------------------------------------------------------------------
greggplatinum's Profile: http://forums.techarena.in/member.php?userid=27212
View this thread: http://forums.techarena.in/showthread.php?t=92376

http://forums.techarena.in
 >> Stay informed about: Problem with script to add printers ports, need help. 
Back to top
Login to vote
Display posts from previous:   
   Windows Server (Home) -> Windows Server Scripting All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]