I made this script. Hope it helps someone like me who has the same problem. ' *************************************************************************************** ' ' Nome routine: InstallRicohDriver ' --------------------------------------------------------------------------------------- ' Descrizione routine: ' La routine, esegue la creazione delle tre porte (192.168.42.203, 192.168.42.217 ' e 192.168.42.244), dopo averne controllato l'eventuale esistenza; quindi procede ' con l'installazione dei driver e delle relative stampanti per i piani 1, 2 e 5. ' ' Piano 1 - IP 192.168.42.217 ' Piano 2 - IP 192.168.42.244 ' Piano 5 - IP 192.168.42.203 ' ' - step1: controllo esistenza porte stampanti ' - step2: aggiunta porta ed installazione driver stampante ' - step3: impostazione stampante predefinita ' --------------------------------------------------------------------------------------- ' Created by Fiscella Fabrizio on 20/02/2007 ' *************************************************************************************** ' ' ' costanti contenenti i nomi delle stampanti ' prnPiano1 = "RICOH Aficio 2035 PCL 6 - P1" prnPiano2 = "RICOH Aficio 2035 PCL 6 - P2" prnPiano5 = "RICOH Aficio 2035 PCL 6 - P5" nomeStampante = "RICOH Aficio 2035 PCL 6" ' ' -------------------------------------------- ' ' STEP 1 - controllo esistenza porte stampanti ' ' -------------------------------------------- ' strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colPorts = objWMIService.ExecQuery _ ("Select * from Win32_TCPIPPrinterPort") ' Inizializzo le variabili che memorizzeranno l'eventuale esistenza di alcune porte flg217trovata = 0 flg244trovata = 0 flg203trovata = 0 Wscript.Echo "." Wscript.Echo " CONTROLLO ESISTENZA PORTE" Wscript.Echo "." ' Ciclo per reperire quali porte siano già esistenti For Each objPort in colPorts if objPort.Name = "IP_192.168.42.217" then Wscript.Echo "TROVATA PORTA: IP_192.168.42.217" flg217trovata = 1 stampantiGiaEsistenti=stampantiGiaEsistenti+1 elseif objPort.Name = "IP_192.168.42.244" then Wscript.Echo "TROVATA PORTA: IP_192.168.42.244" flg244trovata = 1 stampantiGiaEsistenti=stampantiGiaEsistenti+1 elseif objPort.Name = "IP_192.168.42.203" then Wscript.Echo "TROVATA PORTA: IP_192.168.42.203" flg203trovata = 1 stampantiGiaEsistenti=stampantiGiaEsistenti+1 end if Next if stampantiGiaEsistenti = 3 then ' tutte le stampanti sono gia' installate Wscript.Echo "TUTTE LE STAMPANTI SONO GIA' INSTALLATE",0,"123" else ' --------------------------------------------------------- ' ' STEP 2 - aggiunta porta ed installazione driver stampante ' ' --------------------------------------------------------- ' Set objShell = CreateObject("Wscript.Shell") if flg217trovata <> 1 then ' ------- ' ' PIANO 1 ' ' ------- ' AddPort "IP_192.168.42.217","192.168.42.217" Wscript.Echo "." Wscript.Echo " AGGIUNTA PORTA 192.168.42.217" Wscript.Echo "." ' installo driver e stampante stringa = "rundll32 printui.dll,PrintUIEntry /if /b " + """" + prnPiano1 + """" + " /f ""%systemdrive%\drivers\printer\ricoh2035\oemsetup.inf"" /r ""IP_192.168.42.217"" /m " + """" + nomeStampante + """" objShell.Run stringa Wscript.Echo "." Wscript.Echo " AGGIUNTA STAMPANTE RICOH AFICIO PCL 6 - P1" Wscript.Echo "." end if if flg244trovata <> 1 then ' ------- ' ' PIANO 2 ' ' ------- ' AddPort "IP_192.168.42.244","192.168.42.244" Wscript.Echo "." Wscript.Echo " AGGIUNTA PORTA 192.168.42.244" Wscript.Echo "." ' prima di installare la stampante del piano 2, controllo che sia ' già stata installata quella del piano 1 chkPrnExist("1") stringa = "rundll32 printui.dll,PrintUIEntry /if /b " + """" + prnPiano2 + """" + " /f ""%systemdrive%\drivers\printer\ricoh2035\oemsetup.inf"" /r ""IP_192.168.42.244"" /m " + """" + nomeStampante + """" objShell.Run stringa Wscript.Echo "." Wscript.Echo " AGGIUNTA STAMPANTE RICOH AFICIO PCL 6 - P2" Wscript.Echo "." end if if flg203trovata <> 1 then ' ------- ' ' PIANO 5 ' ' ------- ' AddPort "IP_192.168.42.203","192.168.42.203" Wscript.Echo "." Wscript.Echo " AGGIUNTA PORTA 192.168.42.203" Wscript.Echo "." ' prima di installare la stampante del piano 2, controllo che sia ' già stata installata quella del piano 1 chkPrnExist("2") stringa = "rundll32 printui.dll,PrintUIEntry /if /b " + """" + prnPiano5 + """" + " /f ""%systemdrive%\drivers\printer\ricoh2035\oemsetup.inf"" /r ""IP_192.168.42.203"" /m " + """" + nomeStampante + """" objShell.Run stringa ' prima di installare la stampante del piano 5, controllo che sia ' già stata installata quella del piano 2 chkPrnExist("5") Wscript.Echo "." Wscript.Echo " AGGIUNTA STAMPANTE RICOH AFICIO PCL 6 - P5" Wscript.Echo "." end if end if ' ------------------------------------------- ' ' STEP 3 - impostazione stampante predefinita ' ' ------------------------------------------- ' pianoSelezionato = inputbox ("Digitare il piano nel quale si trova la stampante da settare come predefinita","Piano di appartenenza","1, 2 o 5") ' flag per gestione uscita dal loop successivo pianoOk = 0 ' ' ciclo finchè non si setta la stampante predefinita oppure si clicca su ANNULLA ' do while pianoOk = 0 if trim(pianoSelezionato) = "" then 'msgbox "Nessun piano selezionato." & vbcrlf & _ '"Non è stata impostata la stampante predefinita", 0, "Inserisci piano" 'exit do else if isNumeric(pianoSelezionato) then select case pianoSelezionato case 1 ' prima di impostare la stampante predefinita, ' mi accerto che sia stata correttamente creata chkPrnExist("1") ' imposto la stampante predefinita SetDefaultPrinter (prnPiano1) 'msgbox "Stampante selezionata: piano" & pianoSelezionato, 0, "Inserisci piano" pianoOk = 1 case 2 ' prima di impostare la stampante predefinita, ' mi accerto che sia stata correttamente creata chkPrnExist("2") ' imposto la stampante predefinita SetDefaultPrinter (prnPiano2) 'msgbox "Stampante selezionata: piano" & pianoSelezionato, 0, "Inserisci piano" pianoOk = 1 case 5 ' prima di impostare la stampante predefinita, ' mi accerto che sia stata correttamente creata chkPrnExist("5") ' imposto la stampante predefinita SetDefaultPrinter (prnPiano5) 'msgbox "Stampante selezionata: piano" & pianoSelezionato, 0, "Inserisci piano" pianoOk = 1 case else msgbox "Piano non corretto" & vbcrlf & _ "Scegliere tra i seguenti piani: 1, 2 o 5", 0, "Inserisci piano" pianoSelezionato = inputbox ("Digitare il piano nel quale si trova la stampante da settare come predefinita","Piano di appartenenza","1, 2 o 5") pianoOk = 0 end select else msgbox "Valore non valido!" & vbcrlf & _ "Scegliere tra i seguenti piani: 1, 2 o 5", 0, "Inserisci piano" pianoSelezionato = inputbox ("Digitare il piano nel quale si trova la stampante da settare come predefinita","Piano di appartenenza","1, 2 o 5") pianoOk = 0 end if end if loop function chkPrnExist(piano) ' ****************************************** ' Funzione per controllo esistenza stampante ' ****************************************** ' strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") ' ' ciclo fino a quando non ho trovato la stampante richiesta ' prnTrovata = 0 do while prnTrovata = 0 ' in ciclo reperisco la lista aggiornata delle stampanti presenti Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters ' in ciclo reperisco la lista aggiornata delle stampanti presenti Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") if IsLike(objPrinter.Name, "*ricoh*") = true then if piano = 1 then if IsLike(objPrinter.Name, "*P1*") = true then prnTrovata = 1 end if elseif piano = 2 then if IsLike(objPrinter.Name, "*P2*") then prnTrovata = 1 end if elseif piano = 5 then if IsLike(objPrinter.Name, "*P5*") then prnTrovata = 1 end if end if end if Next loop end function Function IsLike(strText, match) ' ************************************************* ' Funzione LIKE - per controllo esistenza stampante ' ************************************************* ' Dim i, str, spec, temp, token, nPos ' Turn strings to lower case str = LCase(strText) spec = LCase(match) ' Split the various components of the match string aInput = split(spec, "*") ' "c*.*m" becomes Array("c", ".", "m") ' Walk the array of specification sub-components i = 0 For Each token In aInput ' The first token plays an important role: the file name must begin ' with a substring identical to the token. If i = 0 Then temp = Left(str, Len(token)) ' Don't match... If temp <> token Then IsLike = False Exit Function End If ' Removes the leading substring before next step str = Right(str, Len(str) - Len(token)) Else temp = str ' For each asterisk we come accross, we chack that what remains of ' the filename contains the next token of the match string. nPos = Instr(1, temp, token) ' Don't match... If nPos = 0 Then IsLike = False Exit Function End If ' Removes the leading substring before next step str = Right(str, Len(str) - nPos + 1) End If i = i + 1 Next IsLike = True End Function function AddPort(nomePorta,indIp) ' -------------------------------------------------------------------------- ' ' AGGIUNTA PORTA ' ' ______________ ' ' PARAMETRI: ' ' nomePorta: nome della porta da creare (es.: "IP_192.168.42.217") ' ' indIp : indirizzo della porta da creare (es.: "192.168.42.217") ' ' ' ' -------------------------------------------------------------------------- ' if nomePorta <>"" then Set objWMIService = GetObject("winmgmts:") Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ objNewPort.Name = nomePorta objNewPort.Protocol = 1 objNewPort.HostAddress = indIp objNewPort.PortNumber = "9100" objNewPort.SNMPEnabled = False objNewPort.Put_ end if end function Function SetDefaultPrinter(prnDefault) ' *********************************************** ' ' FUNZIONA PER IMPOSTARE LA STAMPANTE PREDEFINITA ' ' *********************************************** ' ' Set WshNet = CreateObject("Wscript.Network") WshNet.SetDefaultPrinter prnDefault Set WshNet = Nothing Wscript.Echo "." Wscript.Echo " STAMPANTE PREDEFINITA: " + prnDefault Wscript.Echo "." end function ' *************************************************************************************** '