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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| On Error Resume Next
Const ForReading = 1
Dim strComputer, strExcelPath, objExcel, objSheet, k, objGroup
Dim objWMIService, colItems, ErrState, Sheet
Dim FSO, Fich_A_Lire, WS
Set WS = CreateObject("WScript.Shell")
'Sheet = spreadsheet page, k = row In sheet
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fich_A_Lire = FSO.OpenTextFile("Servers.txt", ForReading, False)
Sheet = 1
k = 1
strExcelPath = "C:\Temp\" ' Chemin de test ici, à modifier selon le besoin et là c'est pour éviter l'InputBox
strExcelPath = strExcelPath & "Printers_" & strComputer & ".xls"
'On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
objExcel.Workbooks.Add
Do While Not Fich_A_Lire.AtEndOfStream
strComputer = TRim(Fich_A_Lire.ReadLine) ' On utilse TRim pour éviter les espaces de début ou de fin inutiles
If strComputer = "" then
MsgBox "Nom de serveur incorrect"
WScript.quit 0
End If
If VerifComputerName(strComputer) Then
k = k + 1
PrintServer K, strComputer
End If
Loop
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
'=============================
Function PrintServer(K, ComputerName)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinterItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
Set objSheet = objExcel.ActiveWorkbook.Worksheets(Sheet)
'objSheet.Name = ComputerName
objSheet.Cells(1, 1).Value = "SERVEUR"
objSheet.Cells(1, 2).Value = "Name"
objSheet.Cells(1, 3).Value = "ShareName"
objSheet.Cells(1, 4).Value = "DriverName"
objSheet.Cells(1, 5).Value = "Location"
objSheet.Cells(1, 6).Value = "PortName"
objSheet.Cells(1, 7).Value = "Published"
objSheet.Cells(1, 8).Value = "Queued"
objSheet.Cells(1, 9).Value = "Shared"
For Each colItem In colPrinterItems
'put error code into human readable form
Select Case colItem.DetectedErrorState
Case 4
ErrState = "Out of Paper"
Case 5
ErrState = "Toner low"
Case 6
ErrState = "Printing"
Case 9
ErrState = "Offline"
Case Else
ErrState = colItem.DetectedErrorState
End Select
'populate the row with this printer's data
objSheet.Cells(k, 1).Value = ComputerName
objSheet.Cells(k, 2).Value = colItem.Name
objSheet.Cells(k, 3).Value = colItem.ShareName
objSheet.Cells(k, 4).Value = colItem.DriverName
objSheet.Cells(k, 5).Value = colItem.Location
objSheet.Cells(k, 6).Value = colItem.PortName
objSheet.Cells(k, 7).Value = colItem.Published
objSheet.Cells(k, 8).Value = colItem.Queued
objSheet.Cells(k, 9).Value = colItem.Shared
Next
objSheet.Range("A1:M1").Font.Bold = True
objSheet.Range("A1:M1").Font.Size = 11
objSheet.Select
objSheet.Range("A2").Select
objExcel.ActiveWindow.FreezePanes = True
objExcel.Columns(3).ColumnWidth = 25
objExcel.Columns(5).ColumnWidth = 25
objExcel.Columns(6).ColumnWidth = 10
objExcel.Columns(8).ColumnWidth = 25
objExcel.Columns(1).ColumnWidth = 20
objExcel.Columns(9).ColumnWidth = 14
objExcel.Columns(2).ColumnWidth = 15
End Function
'==========================================
Function VerifComputerName(strCMPTR)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
If UCase(objItem.Name) = UCase(strCMPTR) Then
VerifComputerName = True
Exit For
End If
Next
End Function
'==========================================
' Quit Excel.
objExcel.Quit
objExcel.Terminate
' Clean Up
Set objUser = Nothing
Set objGroup = Nothing
Set objSheet = Nothing
Set objExcel = Nothing
WS.PopUp "Printer listing is done", 3 ,"Finished", 0 |
Partager