Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with script not showing printer name and port

Status
Not open for further replies.

rodia87

IS-IT--Management
Nov 25, 2011
3
PL
Can You tell me why this scrpit not showing me a printer name and printer port, I think I add everything what is need, it showing me everyting but this two things are blank. Thx for reply.


Code:
Set colitems6 = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where Win32_Printer")

Code:
 For Each objItem In colItems6
	  PrntrLst = objPrinter.Name
	  vbCrLf = objPrinter.PortName
	 if not ipaddress = "0.0.0.0" then
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Nazwa: " & PrntrLst &"</FONT><BR>"
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Port : " & vbCrLf &"</FONT><BR>"
	 end if


Code:
    On Error Resume Next
    do while strcomputer = "" and a < 2
      strcomputer = Inputbox ("Wprowadz adres IP albo Nazwe Komputera","Informacje o Zdalnym Komputerze","IP jest wskazany do wpisania")
      strcomputer = trim(strcomputer)
      a = a + 1
    loop
    if not strComputer <> "" then
     wscript.echo "Zaden komputer nie zostal wpisany, koniec skryptu"
     wscript.quit
    end if
    On Error Resume Next
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    if err.number <> 0 then
     if err.number = -2147217405 then
      wscript.echo "Nie masz dostepu do danych tego komputera"
      wscript.quit
      else
      wscript.echo "Nie mozna zlokalizowac komputera" &vbcrlf& "Sprawdz IP Address/Nazwe Komputera i sprobuj ponownie"
      wscript.quit
     end if
    end if
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS")
    Set colItems1 = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    Set colItems2 = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    Set colitems3 = objWMIService.ExecQuery("SELECT * FROM Win32_computersystem")
    Set colitems4 = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkLoginProfile")
    Set colitems5 = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DriveType = 3")
    Set colitems6 = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where Win32_Printer")
    Set objExplorer = CreateObject("InternetExplorer.Application")
    objExplorer.Navigate "about:blank"
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Width = 800
    objExplorer.Height = 600
    objExplorer.Left = 100
    objExplorer.Top = 100
    objExplorer.Visible = 1
    Do While (objExplorer.Busy)
    Loop
    Set objDocument = objExplorer.Document
    objDocument.Open
    objDocument.Writeln "<html><head><title>Computer Information</title></head>"
    objDocument.Writeln "<body bgcolor='white'>"
    ' Computer Detals
    For Each objItem In colItems
     serial = objitem.serialnumber
    next
    For Each objItem In colItems1
     hostname = objitem.caption
     make = objitem.manufacturer
     model = objitem.model
    next
    objDocument.Writeln "<FONT color='red' size=4>Computer Information For: " & Ucase(hostname) & "</FONT><BR><BR>"
    objDocument.Writeln "<FONT face='Courier' color='black'>Serial : " & Serial & "</FONT><BR>"
    objDocument.Writeln "<FONT face='Courier' color='black'>Make : " & make & "</FONT><BR>"
    objDocument.Writeln "<FONT face='Courier' color='black'>Model : " & Model & "</FONT><BR>"
    For Each objItem In colItems5
     driveletter = objitem.name
     capacity = ((objitem.size / 1024) / 1024) / 1024
     free = ((objitem.FreeSpace / 1024) / 1024) / 1024
     free = FormatNumber (free,2)
     capacity = FormatNumber (capacity,2)
     
    objDocument.Writeln "<FONT face='Courier' color='black'>Capacity of " &driveletter& " - " & capacity & "GB</FONT><BR>"
    objDocument.Writeln "<FONT face='Courier' color='black'>Free Space on " &driveletter& " - " & Free & "GB</FONT><BR>"
    next
    objDocument.Writeln "<BR><FONT color='Blue' size=4>Please Wait, gathering more information...</FONT><BR><BR>"
    ' User Details
    For Each objItem In colItems3
     loggedon = objitem.username
    next
    For Each objItem In colItems4
     cachedlog = objitem.name
     username = objitem.FullName
     passwordexpire = objitem.passwordexpires
     badpassword = objitem.badpasswordcount
     if loggedon = cachedlog then
      objDocument.Writeln "<FONT color='red' size=4>User Information For...</FONT><BR>"
      objDocument.Writeln "<FONT color='red' size=4>" & username & "</FONT><BR><BR>"
      objDocument.Writeln "<FONT face='Courier' color='black'> User Name :" & loggedon &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Incorrect Password Attempts : " & badpassword &"</FONT><BR>"
      on error resume next
      Set objaccount = GetObject("WinNT://**********/" &objitem.caption & ",user")
      if Err.Number <> 0 Then
       objDocument.Writeln "<FONT face='courier' color='black'>unable to retrieve password expiration information</FONT><BR>"
      Else
       If objAccount.PasswordExpired = 1 Then
        objDocument.Writeln "<FONT face='courier' color='red'>Password has Expired!</FONT><BR>"
       Else
        objDocument.Writeln "<FONT face='courier' color='black'>Password Expires " & objAccount.PasswordExpirationDate & " </FONT><BR><BR>"
       end if
      end if
     end if
    next
    ' Network Adapter Details
    For Each objItem In colItems2
     ipaddress = objitem.ipaddress(0)
     description = objitem.description
     DHCP = objitem.DHCPserver
     Domain = objitem.DNSdomain
	 IPGateway = objItem.DefaultIPGateway(0)
	 mask = objItem.IPSubnet(0)
     mac = objitem.MACaddress
     DNS = objitem.dnsserversearchorder(0)
     DNS1 = objitem.dnsserversearchorder(1)
     DNS2 = objitem.dnsserversearchorder(2)
     wins1 = objitem.winsprimaryserver
     wins2 = objitem.winssecondaryserver
     if not ipaddress = "0.0.0.0" then
      objDocument.Writeln "<FONT color='red' size=4>Network Adapter Details For...</FONT><BR>"
      objDocument.Writeln "<FONT color='red' size=4>" & description & "</FONT><BR><BR>"
      objDocument.Writeln "<FONT face='Courier' color='black'> IP Address :" & ipaddress &"</FONT><BR>"
	  objDocument.Writeln "<FONT face='courier' color='black'> IP Gateway : " & IPGateway &"</FONT><BR>"
	  objDocument.Writeln "<FONT face='courier' color='black'> Maska Podsieci : " & mask &"</FONT><BR>"
	  objDocument.Writeln "<FONT face='courier' color='black'> DHCP Server : " & DHCP &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Domain Name : " & domain &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> MAC Address : " & mac &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Primary DNS : " & DNS &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Secondary DNS : " & DNS1 &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Tertiary DNS : " & DNS2 &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Primary WINS : " & wins1 &"</FONT><BR>"
      objDocument.Writeln "<FONT face='courier' color='black'> Secondary WINS : " & WINS2 &"</FONT><BR><BR>"
     end if
	 next
	 For Each objItem In colItems6
	  PrntrLst = objPrinter.Name
	  vbCrLf = objPrinter.PortName
	 if not ipaddress = "0.0.0.0" then
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Nazwa: " & PrntrLst &"</FONT><BR>"
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Port : " & vbCrLf &"</FONT><BR>"
	 end if
    next
    objDocument.Writeln "<FONT color='Blue' size=4>Script Finished</FONT><BR><BR>"
 
Code:
[blue]Set colitems6 = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where Win32_Printer") [/blue]

I'd look really hard at your WMI query ...
 
Set colitems6 = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where Win32_Printer")
You are right, I am repair this query:
Code:
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
But still this not showing me any details about printers, only show me how many printers is installed, example:

Drukarka Nazwa:
Drukarka Port :
Drukarka Nazwa:
Drukarka Port :
Drukarka Nazwa:
Drukarka Port :
Drukarka Nazwa:
Drukarka Port :
Drukarka Nazwa:
Drukarka Port :
Drukarka Nazwa:
Drukarka Port :

Code:
	 For Each objItem In colPrinters
	  PrntrLst = objPrinter.Name(0)
	  vbCrLf = objPrinter.PortName(0)
	 if not ipaddress = "0.0.0.0" then
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Nazwa: " & PrntrLst &"</FONT><BR>"
	 objDocument.Writeln "<FONT face='courier' color='black'> Drukarka Port : " & vbCrLf &"</FONT><BR>"

How to change this ?
 
I am fix up the script and it works fine. Thx for reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top