Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can i install a network printer from a .BAT or some other automatic method?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

With a .VBS file, you can do this:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

'DETERMINE OPERATING SYSTEM
For Each objOperatingSystem in colOperatingSystems               
    sOS = objOperatingSystem.Caption
    objLogFile.WriteLine "OS defined as: " & objOperatingSystem.Caption
Next

'DETERMINE THE DEFAULT PRINTER
If InStr(sOS,"2000") <> 0 Then
    For Each oPrinter in colItems 
        If oPrinter.Attributes And ATTR_DEFAULT Then
            sDefaultPrinter = oPrinter.ShareName 
        End If 
    Next
Else
    For Each objPrinter In colItems
          If objPrinter.Default Then
            sDefaultPrinter = objPrinter.ShareName
          End If
    Next
End If


'INITIALIZE THE LOCAL PRINTER OBJECTS
Set objNetwork = CreateObject("WScript.Network") 
Set objLocalPrinters = objNetwork.EnumPrinterConnections

'LOOP THROUGH YOUR PRINTERS
For iCount = 0 to objLocalPrinters.Count - 1 Step 2
If InStr(UCase(Trim(objLocalPrinters.Item(iCount+1))), "PRINTERNAMETOREMOVE") <> 0

'REMOVES PRINTERS
objNetwork.RemovePrinterConnection objLocalPrinters.Item(iCount+1)

'ADDS PRINTERS
objNetwork.AddWindowsPrinterConnection "\\[PRINT SERVER]\[PRINTER NAME]"

'IF THE PRINTER WE REMOVED WAS THE DEFAULT PRINTER, SET THE NEW ONE AS THE DEFAULT
If InStr(UCase(Trim(objLocalPrinters.Item(iCount+1))), UCase(Trim(sDefaultPrinter))) <> 0 Then
objNetwork.SetDefaultPrinter "\\[PRINT SERVER]\[PRINTER NAME]"
End If

End If
Next
share|improve this answer
add comment

Looks like this is the command you want to use in your batch script:

prncfg

Check the documentation beforehand:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prncnfg.mspx

share|improve this answer
add comment

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.