strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Printer share name"
objExcel.Cells(1, 2).Value = "printer IP address"
objExcel.Cells(1, 3).Value = "Driver installed"
objExcel.Cells(1, 4).Value = "location"
x = 2
For Each objPrinter in colInstalledPrinters
'Wscript.Echo "Name: " & objPrinter.ShareName
'Wscript.Echo "Location: " & objPrinter.PortName
'Wscript.Echo "Default: " & objPrinter.DriverName
'Wscript.Echo "Default: " & objPrinter.Location
objExcel.Cells(x, 1).Value = objPrinter.ShareName
objExcel.Cells(x, 2).Value = objPrinter.PortName
objExcel.Cells(x, 3).Value = objPrinter.DriverName
objExcel.Cells(x, 4).Value = objPrinter.Location
x = x + 1
Next
Set objRange = objExcel.Range("A1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("B1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("D1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
|