Search for share name on a server

Started by jik_ff, June 19, 2012, 01:12:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jik_ff

Ok, this should be the last of the "I don't know where to start" questions...

Long story short, I have the basic name of printer queue shares.  From my data base I have \\ ServerName \ PrinterName.  But on the server, the printers (some have multiple queues) have names like PrinterName_PCL or PrinterName_PS. 

What I am hoping to be able to do is poll the server for PrinterName* and return these values to a string.  I have seen code for file searches, but nothing for UNC stuff.

aledlund

#1
To start you might try to get it via a simple WMI script using vba. There are a lot of example scripts in the 'Script Center' on technet.microsoft.com

' find the installed printers
http://gallery.technet.microsoft.com/scriptcenter/dd99efa1-9959-45cd-b722-44d31978ef8d

There's a sample project over here on Chris' site that goes into some systems management (wmi/snmp) materials.

http://visguy.com/vgforum/index.php?topic=1026.msg4522#msg4522

al



jik_ff

#2
Ah.  Got it.  To share with others possibly looking to do something similar, here is the basic code:
Private Sub CommandButton3_Click()
   
    Dim strComputer: strComputer = "MySever"     ' should be passed
    Dim objWMIService, colShares, objShare
    Dim aStr As String          'more for generic testing to hold the list of printer queues
    Dim baseName As String      'will be passed from data base, using a temp name for now
    Dim strTemp As String       'used when check for specific queue name
   
    aStr = "The print queues on server " & strComputer & " are:" & vbCrLf
   
    baseName = "vort"        'Temp - part of a printer name on the server.  This line should be removed later
   
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer")  ' Where ShareName Like 'vor%'") ', , 48)
   
    For Each objItem In colItems
        If (InStr(UCase(objItem.ShareName), UCase(baseName))) Then
            aStr = aStr & objItem.ShareName & vbCrLf
        End If
    Next
   
    Call MsgBox(aStr, , "Print Queues on \\" & vbCrLf & strComputer)
End Sub



This code will list off all print queues on server MySever that have "vort" in thier name.  This works for me as our printers are all named, but have a suffix based on the printer queue type, and we have a few...

Thanks for pointing me in the right direction.  I've got all I need know to complete the project at hand.