identify print servers in a domain from excel vba?

M

Mad Scientist Jr

I found out how to enumerate all machines on a domain:

Dim sDomainName As String
Dim oDomain As Variant
Dim oComputer As Variant
Dim iRow As Long
Dim sCol As String
iRow = ActiveCell.Row
sCol = NumToColumn(ActiveCell.Column)
sDomainName = "mydomain"
Set oDomain = GetObject("WinNT://" & sDomainName)
oDomain.Filter = Array("computer")
For Each oComputer In oDomain
Worksheets(ActiveSheet.Name).Cells(CStr(iRow), sCol).Value =
oComputer.Name
iRow = iRow + 1
Next
Exit Sub

and if a machine is up

Function UpDownMachine(MachineName) As Boolean
Dim Ping As Variant
Dim Result As Variant

Set Ping = CreateObject("DSPing.Ping")
Result = Ping.DoPing(MachineName)
If Result = 3 Then
UpDownMachine = False
ElseIf Result = 4 Then
UpDownMachine = False
Else
UpDownMachine = True
End If
End Function ' UpDownMachine

however, how would you tell if the machine in question is a print
server, as opposed to someone's personal workstation?

Much appreciated...



PS the code below seems to retrieve user names and groups and might
help with this, I haven't tried it yet:

1. Gary Lumpkin
View profile
I am having a problem setting an Excel column to set vertical
alignment to automatically justify. Any help would be greatly
appreciated. The area is labeled " Problem Area" Thanks Gary
'~~~Author Gary Lumpkin '~~~Date 1/14/2000 '~~~Non Production On
Error Resume Next Dim MsgBoxTip Dim objDom Dim objSrv Dim objXL Dim
objFS Dim objUsrId Dim objUsr Dim strGrp Dim objGrp Dim strGrpe Dim
objColGrp Dim xlJustify Dim List MsgBoxTip = "Server Auditor Beta 2"
objDom = InputBox("Which server do you Audit? ", MsgBoxTip) If
IsEmpty(objDom) Then Wscript.Echo "Audit Canceled!!" wscript.Quit
end If Set objSrv = GetObject("WinNT://" & objDom) Set objXL =
Wscript.CreateObject("Excel.Application") Set objFS =
Wscript.CreateObject("Scripting.FileSystemObject") setupXL()
objSrv.Filter = Array("user") For Each objUsrId in objSrv Set objUsr
= GetObject("WinNT://" & objDom &"/"& objUsrId.Name ) 'Layout
Spreadsheet Local Users objXL.Activecell.Value = "" & objDom
objXL.Activecell.offset(0,1).Activate objXL.Activecell.Value = "" &
objUsrId.Name objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.FullName
objXL.Activecell.offset(0,1).Activate objXL.Activecell.Value = "" &
objUsrId.Description objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.AccountDisabled
objXL.Activecell.offset(0,1).Activate Set strGrp =
objFS.OpenTextFile("c:\temp\Grptxt.txt", 2, True) For Each
objGrp In objUsr.Groups strGrp.write("" & objGrp.Name & ",
" ) Next strGrp.Close Set strGrpe =
objFS.OpenTextFile("c:\temp\Grptxt.txt", 1, True) objColGrp =
strGrpe.readall objXL.Activecell.Value = "" & objColGrp
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.offset(1,-6).Activate next
objXL.Sheets("Sheet1").Select objXL.Sheets("Sheet1").Name = "Local
Accts" objXL.Sheets("Sheet2").Select objXL.Sheets("Sheet2").Name =
"Local Groups" objXL.ActiveSheet.range("A3").Activate
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Layout Spreadsheet Local Groups and Members objSrv.Filter =
Array("group") For Each objGrp In objSrv objXL.Activecell.Value = ""
& objDom objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objGrp.Name
objXL.Activecell.offset(0,1).Activate For each objUsrId in
objGrp.Members List = List & ", " & objUsrId.Name Next
objXL.Activecell.Value = "" & List
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.offset(1,-3).Activate Next
objXL.Sheets("Sheet3").Select objXL.Sheets("Sheet3").Name =
"Policies" '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function setupXL() objXL.Visible = TRUE objXL.WorkBooks.Add
objXL.Columns(1).ColumnWidth = 25 objXL.Columns(2).ColumnWidth =
25 objXL.Columns(3).ColumnWidth = 25 objXL.Columns(4).ColumnWidth
= 25 objXL.Columns(5).ColumnWidth = 8 objXL.Columns(6).ColumnWidth
= 25 objXL.Cells(1, 1).Value = "Server" objXL.Cells(1, 2).Value =
"Local Accounts" objXL.Cells(1, 3).Value = "Full Name"
objXL.Cells(1, 4).Value = "Description" objXL.Cells(1, 5).Value =
"Disabled" objXL.Cells(1, 6).Value = "Group Membership"
'~~~~~~Problem Area~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'objXL.Range("C:C").select 'objXL.Range.Selection.VerticalAlignment
= xlVAlignJustify
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objXL.Range("A1:Z1").Select objXL.Selection.Font.Bold = True
objXL.Sheets("Sheet2").Select objXL.Columns(1).ColumnWidth = 25
objXL.Columns(2).ColumnWidth = 25 objXL.Columns(3).ColumnWidth =
25 objXL.Cells(1, 1).Value = "Server" objXL.Cells(1, 2).Value =
"Local Group" objXL.Cells(1, 3).Value = "Members"
objXL.Range("A1:Z1").Select objXL.Selection.Font.Bold = True
objXL.Sheets("Sheet1").Select objXL.ActiveSheet.range("A3").Activate
End Function
More options Jan 19 2000, 3:00 am
Newsgroups: microsoft.public.scripting.wsh
From: "Gary Lumpkin" <[email protected]>
Date: 2000/01/19
Subject: Syntax problem formating Excel Column - audit script
Reply to author | Forward | Print | Individual message | Show original
| Report this message | Find messages by this author
I am having a problem setting an Excel column to set vertical
alignment to
automatically justify.
Any help would be greatly appreciated. The area is labeled " Problem
Area"

Thanks
Gary

'~~~Author Gary Lumpkin
'~~~Date 1/14/2000
'~~~Non Production

On Error Resume Next

Dim MsgBoxTip
Dim objDom
Dim objSrv
Dim objXL
Dim objFS
Dim objUsrId
Dim objUsr
Dim strGrp
Dim objGrp
Dim strGrpe
Dim objColGrp
Dim xlJustify
Dim List

MsgBoxTip = "Server Auditor Beta 2"

objDom = InputBox("Which server do you Audit? ", MsgBoxTip)

If IsEmpty(objDom) Then
Wscript.Echo "Audit Canceled!!"
wscript.Quit
end If

Set objSrv = GetObject("WinNT://" & objDom)
Set objXL = Wscript.CreateObject("Excel.Application")
Set objFS = Wscript.CreateObject("Scripting.FileSystemObject")

setupXL()
objSrv.Filter = Array("user")

For Each objUsrId in objSrv

Set objUsr = GetObject("WinNT://" & objDom &"/"& objUsrId.Name )

'Layout Spreadsheet Local Users

objXL.Activecell.Value = "" & objDom
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.Name
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.FullName
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.Description
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objUsrId.AccountDisabled
objXL.Activecell.offset(0,1).Activate

Set strGrp = objFS.OpenTextFile("c:\temp\Grptxt.txt", 2, True)
For Each objGrp In objUsr.Groups
strGrp.write("" & objGrp.Name & ", " )
Next
strGrp.Close

Set strGrpe = objFS.OpenTextFile("c:\temp\Grptxt.txt", 1, True)
objColGrp = strGrpe.readall
objXL.Activecell.Value = "" & objColGrp
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.offset(1,-6).Activate

next

objXL.Sheets("Sheet1").Select
objXL.Sheets("Sheet1").Name = "Local Accts"
objXL.Sheets("Sheet2").Select
objXL.Sheets("Sheet2").Name = "Local Groups"
objXL.ActiveSheet.range("A3").Activate
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Layout Spreadsheet Local Groups and Members

objSrv.Filter = Array("group")

For Each objGrp In objSrv

objXL.Activecell.Value = "" & objDom
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.Value = "" & objGrp.Name
objXL.Activecell.offset(0,1).Activate

For each objUsrId in objGrp.Members
List = List & ", " & objUsrId.Name
Next
objXL.Activecell.Value = "" & List
objXL.Activecell.offset(0,1).Activate
objXL.Activecell.offset(1,-3).Activate
Next

objXL.Sheets("Sheet3").Select
objXL.Sheets("Sheet3").Name = "Policies"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function setupXL()
objXL.Visible = TRUE
objXL.WorkBooks.Add
objXL.Columns(1).ColumnWidth = 25
objXL.Columns(2).ColumnWidth = 25
objXL.Columns(3).ColumnWidth = 25
objXL.Columns(4).ColumnWidth = 25
objXL.Columns(5).ColumnWidth = 8
objXL.Columns(6).ColumnWidth = 25
objXL.Cells(1, 1).Value = "Server"
objXL.Cells(1, 2).Value = "Local Accounts"
objXL.Cells(1, 3).Value = "Full Name"
objXL.Cells(1, 4).Value = "Description"
objXL.Cells(1, 5).Value = "Disabled"
objXL.Cells(1, 6).Value = "Group Membership"
'~~~~~~Problem Area~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'objXL.Range("C:C").select
'objXL.Range.Selection.VerticalAlignment = xlVAlignJustify
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objXL.Range("A1:Z1").Select
objXL.Selection.Font.Bold = True
objXL.Sheets("Sheet2").Select
objXL.Columns(1).ColumnWidth = 25
objXL.Columns(2).ColumnWidth = 25
objXL.Columns(3).ColumnWidth = 25
objXL.Cells(1, 1).Value = "Server"
objXL.Cells(1, 2).Value = "Local Group"
objXL.Cells(1, 3).Value = "Members"
objXL.Range("A1:Z1").Select
objXL.Selection.Font.Bold = True
objXL.Sheets("Sheet1").Select
objXL.ActiveSheet.range("A3").Activate

End Function
 
M

Mad Scientist Jr

Assuming you are not just trying to enumerate printes, this article might help:
http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_fktg.mspx...

Hi and thanks for your reply. I already have code that enumerates
printers (see below). The problem is, it requires a server name and I
would like it to find the print servers as well.

'ENUM.VBS
'Jeffery Hicks
'(e-mail address removed)
'USAGE: cscript ENUM.VBS servername
'DESC: Enumerate printers on specified server and show print
configuration
'NOTES: If you want, you can redirect the output to a text file
' cscript enum.vbs servername > printers.txt

'*******************************************************
'* THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED
AS *
'* NECESSARY TO MEET YOUR NEEDS. *
'* THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, EXPRESS, IMPLIED OR
OF ANY *
'* OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS *
'* DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A
SECURED LAB *
'* ENVIRONMENT. USE AT YOUR OWN RISK. *
'**********************************************************

ON ERROR RESUME NEXT
dim cont,oArgs

If LCase(ChkEngine)="wscript.exe" then
wscript.echo "You should really run this script using CSCRIPT.EXE" &
VBCRLF & "The output is formatted for screen display. If you want, you
can redirect the output to a text file: " & VBCRLF & VBCRLF & "
cscript enum.vbs servername >servername_printers.txt"
wscript.quit
End If

Set oArgs=wscript.Arguments

If oArgs.Count<1 then
msg=" Syntax Error - Missing Parameter "
wscript.echo VBCRLF & String(Len(msg),CHR(22))& VBCRLF & msg & VBCRLF
& String(Len(msg),CHR(22))&VBCRLF
Usage
End If

If InStr(oArgs(0),"?")<>0 Then
msg=" Help - " & wscript.scriptname & " "
wscript.echo VBCRLF & String(Len(msg),CHR(22))& VBCRLF & msg & VBCRLF
& String(Len(msg),CHR(22))& VBCRLF & VBCRLF & "Enumerate printers on
specified server and show print configuration." & VBCRLF
Usage
End If

Set cont = GetObject("WinNT://"&oArgs(0)&",computer")
If err.number<>0 Then
wscript.echo "Could not connect to " & oArgs(0) & ". Verify server
name and/or that you have correct permissions."
wscript.quit
End If

msg=" Printer Information: " & oArgs(0) & " "
wscript.echo VBCRLF & String(Len(msg),CHR(22))& VBCRLF & msg & VBCRLF
& String(Len(msg),CHR(22))& VBCRLF

wscript.echo "Connecting to " & oArgs(0)& "..." & VBCRLF

cont.Filter = Array("PrintQueue")


For Each p In cont
Set pq = GetObject(p.ADsPath)
pinfo=pinfo & String(50,CHR(22)) & VBCRLF ' *** THE PROBLEM WAS
PROBABLY THAT IT WAS RESETTING THE OUTPUT FOR EACH PRINTER ***
pinfo=pinfo & "Shared as: " & VBTAB & pq.name & VBCRLF
pinfo=pinfo & "Printer Name: " & VBTAB & pq.PrinterName & VBCRLF
pinfo=pinfo & "Model: " & VBTAB & VBTAB & pq.Model & VBCRLF
pinfo=pinfo & "Comments: " & VBTAB & pq.Description & VBCRLF
pinfo=pinfo & "Location: " & VBTAB & pq.Location & VBCRLF
pinfo=pinfo & "Processor: " & VBTAB & pq.PrintProcessor & VBCRLF
pinfo=pinfo & "Devices: " & VBTAB & pq.PrintDevices & VBCRLF
pinfo=pinfo & "Path: " & VBTAB & VBTAB & pq.PrinterPath & VBCRLF
pinfo=pinfo & "Available: " & VBTAB & pq.Starttime & " to " &
pq.UntilTime & VBCRLF
Select Case pq.Status
Case "0" CurStatus="Online"
Case "1" CurStatus="Paused"
Case "2" CurStatus="Pending Deletion"
Case "3" CurStatus="Error"
Case "4" CurStatus="Paper Jam"
Case "5" CurStatus="Paper Out"
Case "6" CurStatus="Manual Feed"
Case "7" CurStatus="Paper Problem"
Case "8" CurStatus="Offline"
Case "256" CurStatus="IO Active"
Case "512" CurStatus="Busy"
Case "1024" CurStatus="Printing"
Case "2048" CurStatus="Output Bin Full"
Case "4096" CurStatus="Not Available"
Case "8192" CurStatus="Waiting"
Case "6384" CurStatus="Processing"
Case "32768" CurStatus="Initializing"
Case "65536" CurStatus="Warming Up"
Case "131072" CurStatus="Toner Low"
Case "262144" CurStatus="No Toner"
Case "524288" CurStatus="Page Punt"
Case "1048576" CurStatus="User Intervention"
Case "2097152" CurStatus="Out of Memory"
Case "4194304" CurStatus="Door Open"
Case "8388608" CurStatus="Server Unknown"
Case "16777216" CurStatus="Power Save"
Case Else CurStatus="Can't evaluate current status"
End Select

pinfo=pinfo & "Currently: " & VBTAB & CurStatus & VBCRLF
Next

pinfo=pinfo & VBCRLF & "If nothing is displayed or some information is
missing, it is either not configured" & VBCRLF & "or you don't have
permission to view it."

wscript.echo pinfo

Set cont=Nothing
Set oArgs=Nothing

wscript.quit

'************************
'* Usage Subroutine *
'************************
Sub Usage()
msg="Usage: cscript enum.vbs servername" & VBCRLF & "DO NOT use \\
before the server name. " & VBCRLF & " Example: " & VBCRLF & " cscript
enum.vbs PrintSrv01" & VBCRLF & VBCRLF & "cscript enum.vbs /?|-? will
display this message."

wscript.echo msg

wscript.quit

End Sub

'************************
'* ChkEngine Function *
'************************
Function ChkEngine()

ON ERROR RESUME NEXT

strEngine=Wscript.FullName

if Err.Number <>0 then
wscript.echo "Error!"
wscript.echo "Error (" & Err.Number & ") Description: " &
Err.Description
wscript.quit
end if

PosX=InStrRev(strEngine,"\",-1,vbTextCompare)
ChkEngine=Mid(strEngine,PosX+1)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top