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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
   | 'Declaration des constantes
Const ForReading = 1 ' means: open for reading
Const TristateDefault = -2 ' means: read as ASCII
 
Set objShell = WScript.CreateObject ("WSCript.shell")
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
 
'-- Recupération de répertoire courant
fullPath = WScript.ScriptFullName 
Set objFile = objFSO.GetFile(fullPath)
 
'-- Définition du répertoire Courant
StrCurrentDir = objFSO.GetParentFolderName(objFile) 
 
'Chemin du fichier csv
Dim fso
Path = Left(WScript.ScriptFullName, InStr(WScript.ScriptFullName, WScript.ScriptName)-1)
INPUT_PATH =  PATH & "Printer_list_2017.csv"
 
'-- Reccuperation des arguments
strSite = Wscript.Arguments(0)
'strSite = "TOTO"
 
'Search  in CSV file
Set inputFile = objFSO.GetFile(INPUT_PATH)
Set inputFileStream = inputFile.OpenAsTextStream(ForReading, TristateDefault)
 
Do until (inputFileStream.atEndOfStream)
    aktInputLine = inputFileStream.ReadLine
    entries = Split(aktInputLine, ",")  
 
	'Parcours le fichier csv pour reccuperer les informations relative aux imprimantes du site
	For Each line In entries
		If line = strSite Then
			strModel = entries (1)
			strPrinterName = entries (2)
			strIpPrinter = entries (3)
 
			Select Case strModel
				Case "CANON": 
					strDriver = "Canon Generic PCL6 Driver"
					'Windows 7
					'strDrivePath = "C:\Windows\System32\DriverStore\FileRepository\cnp60ma64.inf_amd64_neutral_da93e7535d5504d9\CNP60MA64.INF"
					 strDrivePath = "C:\Temp\Drivers Canon\Install new driver\Driver\CNP60MA64.INF"
				Case Else 
					'wscript.echo "Model not found"
					wscript.quit
			End Select
 
			'Configuration du port
			objShell.run "cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_" & strIpPrinter & " -h " & strIpPrinter & " -o raw", 6, True
 
			'Check if exist
			printerExists (str)
 
			'Configuration de l'imprimante
			objShell.run "rundll32 printui.dll,PrintUIEntry /if /b " & strPrinterName & " /f """ & strDrivePath &""" /r IP_" & strIpPrinter & " /m """ & strDriver & Chr(34), 6, True
		End if
	Next
Loop
 
Function printerExists(str)
    printerExists = "L'imprimante  " & str & "  va être installé"
    Dim objWMIService
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 
    Dim colPrinters
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
 
    Dim objPrinter
    For Each objPrinter In colPrinters
        If objPrinter.Name = str Then 
		printerExists = "L'imprimante  " & str & "  existe déjà"
		Wscript.Quit
            Exit For
        End If
    Next
End Function | 
Partager