Non tutti sanno che con Windows si possono creare degli script alternativi a più noti file batch, per intenderci i file punto bat e punto cmd. Gli script a cui mi riferiscono sono in VB Script e la sua estenzione è punto vbs.
Quest'articolo andrebbe categorizzato in una categoria VB Script, ma essendo il primo ed essendo strettamente legato al sistema operativo ho preferito registrarlo in System.
Ecco alcuni esempi .
1 2 3 4 5 6 7 8 9 10 11 12 13 |
' Visualizza le stampanti e i driver Set WshNetwork = WScript.CreateObject("WScript.Network") Set oDrives = WshNetwork.EnumNetworkDrives Set oPrinters = WshNetwork.EnumPrinterConnections WScript.Echo "Network drive mappings:" For i = 0 to oDrives.Count - 1 Step 2 WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) Next WScript.Echo WScript.Echo "Network printer mappings:" For i = 0 to oPrinters.Count - 1 Step 2 WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1) Next |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
' ************************************************************** ' Crea Stampanti ' ************************************************************** 'WshNetwork.AddWindowsPrinterConnection "\\vmsrvprinter\Xerox-Pro238_pcl6_dx" Set WshNetWork = CreateObject("WScript.Network") ' cPrinter="\\vmsrvprint\Xerox WorkCentre Pro 238 PCL6 DX" ' Crea Stampante call CreaStampante("\\vmsrvprint\Xerox WorkCentre Pro 238 PCL6 DX") call CreaStampante("\\vmsrvprint\Xerox WorkCentre Pro 238 PCL6 SX") ' call CreaStampante("\\vmsrvprint\DocuColor 260 PCL6") WScript.Quit ' ************************************************************** ' CreaStampante ' ************************************************************** sub CreaStampante(cPrinter) test=0 test=esiste(cPrinter) ' WScript.Echo test if test=0 then ' WScript.Echo "printer " & cPrinter &" NOT found! Creating..." WshNetwork.AddWindowsPrinterConnection cPrinter WshNetwork.SetDefaultPrinter cPrinter else ' WScript.Echo "printer " & cPrinter &" found!" end if end sub ' ************************************************************** ' Esiste ' ************************************************************** function esiste(pPrinter) ' pPrinterspazi=Replace(pPrinter, "_", " ") Set network = CreateObject("WScript.Network") esiste=0 Set X = network.EnumPrinterConnections For Each printers In X ' WScript.Echo printers & chr(10) & pPrinter If ucase(printers) = ucase(pPrinter) Then esiste=1 ' WScript.Echo "printer found...." End If next end function |
- have fun -