Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to determine in VBScript, if a print share is in existence on a print server? The idea is to remove the connection to that printer in the event the share is removed from the server.

A file share is a matter if checking for an existing folder, but what about a print share?

share|improve this question
1  
I'd suggest using Group Policy Preferences to manage printer mappings instead of VBScripts. –  ThatGraemeGuy Jul 17 '12 at 15:33
    
We already do, but using GPP must be abandoned for printer policy purposes. We have around 1000 printers in this particular facility and it slows Logins considerably (5-6min). So scripting is necessary to process printer policy post login. –  TheHockeyGeek Jul 17 '12 at 16:16

1 Answer 1

The following VBScript uses WMI to connect to the PC and list all of the print queues on your local Windows machine. To query a remote machine, just type that machine's name in place of the . in the strComputer variable.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter in colPrinters
    If objPrinter.Attributes And 64 Then 
        strPrinterType = "Local"
    Else
        strPrinterType = "Network"
    End If
    Wscript.Echo objPrinter.Name & " -- " & strPrinterType
Next

To remove a printer from a machine use something like:

Set objNet = CreateObject("WScript.Network")
objNet.RemovePrinterConnection "\\SERVER\Printer"

For more info see MS TechNet: Managing Network Printers.

Bear in mind that some printers may be installed at the system level, and available to all users all the time, but on client PCs queues might only be installed in the user's profile and only available to their account, while they're logged in.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.