Installazione della stampante di rete senza interazione dell'utente


Risposte:


1

Con un file .VBS, puoi fare questo:

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

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.