Advice on using Win32_Printer



Hello everyone,

Could someone tell me if this script would do what I want,
which is to enumarate the printers attached to each Server.

I get an error, which I think indicates that I do not have admin rights on
these servers.
Is that correct?

If I know that this script would work, then I can add what I need it to do
(create a web page with some of the results returned),
then ask someone else, in another country, to run it for me.
TIA

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp
On Error Resume Next

Dim arrPrSrv(7)
Dim i
'arrPrSrv(0) = "." '. local computer
arrPrSrv(1) = "PrtSrv1"
arrPrSrv(2) = "PrtSrv2"
arrPrSrv(3) = "PrtSrv3"
arrPrSrv(4) = "PrtSrv4"
arrPrSrv(5) = "PrtSrv5"
arrPrSrv(6) = "PrtSrv6"
arrPrSrv(7) = "PrtSrv7"

For i = 1 To 7

strComputer = arrPrSrv(i)
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Printer",,48)

' WScript.Echo strComputer
For Each objItem In colItems
WScript.Echo "Name: " & objItem.Name & Chr(13) _
& "ServerName: " & objItem.ServerName & Chr(13) _
& "ShareName: " & objItem.ShareName & Chr(13) _
& "Port Name: " & objItem.PortName ' what I'm after - as this
can be used to work out the htm address:
'
Note that the 'Web Page Address' as displayed by AD
'
does not work, http://<IP_Address> does
Next

Next

If Err <> 0 Then

If err.Code = 80041003 Then ' 0x0080041003 = admin rights required
' MsgBox Err.number & Chr(13) _
' & err.description
WScript.Echo Err.number & Chr(13) _
& err.description
End If

End If


.



Relevant Pages

  • Re: WMI query question
    ... Set colItems = objWMIService.ExecQuery("Select * from ... & "Where OwnerName Like '%admin.domain.com%'") ... Running the script on WinXP SP2 against a Win2003 AD/DNS server. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: server checking script to save time
    ... I also have a flaky Microsoft Server 2003 cluster which i would LOVE ... leaving work on time if this script saves me time, ... for each strComputer in arrServers ... For Each objDisk in colDisks ...
    (microsoft.public.scripting.wsh)
  • Re: Microsoft SWORE TO MARY this Drive space script would work but Mary must have been busy.
    ... StrComputer = RS.Value ... ''' First try to ping the server. ... ''' If getting the list of drives fails, log it to the errors table. ... Microsoft guarantees this script to work but all I can say is "Algun ...
    (microsoft.public.scripting.vbscript)
  • Loop with out Do
    ... structures in the script I get a "loop with out do error". ... strComputer = objFile.ReadLine ... Set colItems = objWMIService.ExecQuery("Select * from ... & vbNewLine & vbNewLine ...
    (microsoft.public.windows.server.scripting)
  • Re: VBS Shutdown script loop not working
    ... I want a script to ... First I wrote a batch file using the shutdown command. ... server was shutdown before it returned to the script to get the next ... strComputer = Trim ...
    (microsoft.public.scripting.vbscript)

Loading