'On Error Resume Next'converts to a logon script that runs without user interaction. Add a rem in front of the strComputer = InputBox'line below and remove the rem from the string below that. This will then only check the PC on which'the script runs.
'On Error Resume Next'converts to a logon script that runs without user interaction. Add a rem in front of the strComputer = InputBox'line below and remove the rem from the string below that. This will then only check the PC on which'the script runs.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
'On Error Resume Next'converts to a logon script that runs without user interaction. Add a rem in front of the strComputer = InputBox'line below and remove the rem from the string below that. This will then only check the PC on which'the script runs.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
' To convert to a logon script that runs without user interaction, add a rem in front of the strComputer = InputBox ' line below and remove the rem from the strComputer = "." line below that. This will then only check the PC on which ' the script runs Set WshNetwork = WScript.CreateObject("WScript.Network") 'Disk space sum values Const ConvertKB2GB = 1073741824 Const ConvertKB2MB = 1048576 strComputer = "." 'Type the unc location of the spreadsheet. Needs to exist first. strWorkBook = "\\si-xp-214\test123.xls" ' Create Excel Spreadsheet Set app = CreateObject("Excel.Application") app.Workbooks.Open strWorkBook Set wb = app.ActiveWorkbook app.Visible = False wb.Activate Set ws = wb.Worksheets(1) ws.Cells(1,1).Value = "Computername" ws.Columns(1).ColumnWidth = 20 ws.Cells(1,2).Value = "Username" ws.Columns(2).ColumnWidth = 30 ws.Cells(1,3).Value = "Manufacturer" ws.Columns(3).ColumnWidth = 20 ws.Cells(1,4).Value = "Model" ws.Columns(4).ColumnWidth = 20 ws.Cells(1,5).Value = "Serial Number" ws.Columns(5).ColumnWidth = 30 ws.Cells(1,6).Value = "CPU" ws.Columns(6).ColumnWidth = 30 ws.Cells(1,7).Value = "CPU Speed" ws.Columns(7).ColumnWidth = 10 ws.Cells(1,8).Value = "Operating System" ws.Columns(8).ColumnWidth = 40 ws.Cells(1,9).Value = "Service Pack" ws.Columns(9).ColumnWidth = 20 ws.Cells(1,10).Value = "Total Memory" ws.Columns(10).ColumnWidth = 20 ws.Cells(1,11).Value = "Disk Data" ws.Columns(11).ColumnWidth = 45 ws.Cells(1,12).Value = "Audit Date" ws.Columns(12).ColumnWidth = 20 ws.Rows(1).Font.Bold = True ' Get the serial number first to see if it already exists in the spreadsheet Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48) For Each objItem In colItems strSerialNumber = "" & objItem.SerialNumber Next Set objWMIService = Nothing Set colItems = Nothing intRowToUse = -1 For intRowCount = 2 To ws.UsedRange.Rows.Count If Trim(strSerialNumber) = Trim(ws.Cells(intRowCount,5).Value) Then intRowToUse = intRowCount End If Next If intRowToUse = -1 Then intRowToUse = ws.UsedRange.Rows.Count + 1 End If 'Get Disk usage details Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2 ") Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'") For each objDisk in colDisks sDiskID = objDisk.DeviceID sFree = Round(objDisk.FreeSpace / ConvertKB2GB, 2) sTotal = Round(objDisk.Size / ConvertKB2GB, 2) sUsed = sTotal-sFree sPercent = Round(sUsed / sTotal, 2) * 100 sDisk = sDisk & "Disk " & sDiskID & " " & sFree & " GB Free of " & sTotal & " GB (" & sPercent & "% Full)." & vbCrLf 'Output the disk usage details ws.Cells(intRowToUse,11).Value = sDisk Next Set objWMIService = Nothing Set colItems = Nothing '
' Get Computer System Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each objItem In colItems ws.Cells(intRowToUse,1).Value = "" & objItem.Caption ws.Cells(intRowToUse,2).Value = "" & objItem.UserName ws.Cells(intRowToUse,3).Value = "" & objItem.Manufacturer ws.Cells(intRowToUse,4).Value = "" & objItem.Model Next Set objWMIService = Nothing Set colItems = Nothing ' 'Output the Serial Number ws.Cells(intRowToUse,5).Value = strSerialNumber ' ' Get CPU Details Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48) For Each objItem In colItems ws.Cells(intRowToUse,6).Value = "" & objItem.Name ws.Cells(intRowToUse,7).Value = "" & objItem.CurrentClockSpeed Next Set objWMIService = Nothing Set colItems = Nothing ' ' Get OS Details Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48 ) For Each objItem In colItems ws.Cells(intRowToUse,8).Value = "" & objItem.Caption ws.Cells(intRowToUse,9).Value = "" & objItem.CSDVersion ws.Cells(intRowToUse,10).Value = "" & FormatNumber(objItem.TotalVisibleMemor ySize/1024,0) Next Set objWMIService = Nothing Set colItems = Nothing ' ' Get & Writeout current Date ws.Cells(intRowToUse,12).value = "" & Day(Now) & "-" & Month(Now) & "-" & Year(N ow) 'Autofit all columns app.ActiveSheet.Columns.EntireColumn.AutoFit ' Save Audit File app.DisplayAlerts = False 'wb.Saved = True wb.Close True app.DisplayAlerts = False app.quit MsgBox "Done" '=====================