Dhiraj Mutha
asked on
Computer Info Tool
Hi,
I have the below code which gives me the complete system details. I want some modifications in this.
1) We use all dell systems here, i want to get the Service Tag also in the Tool
2) Button to Extract the details in Excel Sheet.
I have the below code which gives me the complete system details. I want some modifications in this.
1) We use all dell systems here, i want to get the Service Tag also in the Tool
2) Button to Extract the details in Excel Sheet.
<html >
<head>
<title>Computer Info Tool - By Dhiraj Mutha</title>
<hta:application applicationname="Prem's Computer Info Tool" scroll="yes" singleinstance="no"
windowstate="normal">
<style type="text/css">
body {
margin:0px;
background-color:#CBCBCB; /*#F6F6F6;*/
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#595959;
}
h1 {
font-size:24px;
font-weight:bold;
color:#FFFFFF;
background-color:#2886C8;
text-align:center;
border-style:solid;
border-width:thin;
border-color:#C9E0F1;
padding:5px;
}
h2 {
font-size:18px;
font-weight:bold;
}
h3 {
font-size:16px;
font-weight:bold;
}
a {
color:#2886C8;
}
#Main {
margin-left:20px;
margin-right:20px;
}
#DisplayError {
color:red;
margin-left:20px;
margin-right:20px;
}
#Footer {
margin:20px;
font-weight:bold;
font-size:16px;
}
#Header {
margin-left:20px;
margin-right:20px;
text-align:center;
}
#Tools {
text-align:center;
border-color:#595959;
border-style:dotted;
border-width:1px;
background-color:#F6F6F6;
margin-left:20px;
margin-right:20px;
margin-top:20px;
padding:5px;
}
.Button {
color: #444444;
}
.InfoSectionHeader {
font-size:20px;
font-weight:bold;
background-color:#595959;
color:#FFFFFF;
text-align:center;
padding:5px;
margin-top:0px;
cursor:pointer;
}
.InfoSection {
text-align:center;
margin-bottom:10px;
background-color:#FFFFFF;
border-color:#595959;
border-style:dotted;
border-width:1px;
}
.InfoSectionBody {
padding:10px;
}
.Link {
text-decoration: underline;
cursor:pointer;
color:#2886C8;
}
.HeaderLink {
text-decoration: underline;
cursor:pointer;
color:#FFFFFF;
}
.Table {
/*width:90%;*/
border: 2px solid;
border-collapse: collapse;
border-color: #696969;
}
.Table th {
border: 1px dotted #111111;
border-color: #787878;
color: #FFFFFF;
font: bold 12pt arial, sans-serif;
background-color: #595959; /* #787878;*/
text-align: left;
padding=3px;
}
.Table td {
border: 1px dotted #111111;
border-color: #787878;
font: bold 10pt arial, sans-serif;
color: #787878;
padding=5px;
}
</style>
</head>
<body>
<script language="VBScript">
Option Explicit
Const bytesToMB = 1048576
Const bytesToGB = 1073741824
Const bytesToTB = 1099511627776
Const adVarChar = 200
Const adDate = 7
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adInteger = 3
Const adBigInt = 20
Const blnConfirmKillProcess = true
Private objWMIService
Private strComputer
private intProcessTimerID
' ***************************************
' Get Service Tag
' ***************************************
Sub ServiceTag
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Next
End Sub
' ***************************************
' Open Windows explorer to a given path
' Used when clicking a link in the "Shares" section
' ***************************************
Sub OpenUNC(ByVal strPath)
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
strPath = "explorer.exe /e," & strPath
objShell.Run strPath
End Sub
' ***************************************
' Reboot computer
' ***************************************
sub RebootComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to reboot '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Reboot") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Reboot()
Next
msgbox "Computer '" & strComputer & "' has been rebooted",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Shutdown computer
' ***************************************
sub ShutDownComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to shutdown '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Shutdown") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Win32Shutdown(1)
Next
msgbox "Computer '" & strComputer & "' has been shutdown",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Kills the specified process
' Called when "Kill Process" link is clicked in the Running Processes section
' ***************************************
Sub KillProcess(ByVal intProcessID, ByVal strName)
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if blnConfirmKillProcess = True then
if msgbox("Are you sure you want to kill the '" & strName & "' process on '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Kill Process") = vbNo then
exit sub
end if
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = '" & _
intProcessID & "' AND Name = '" & strName & "'")
For Each objItem In colItems
objItem.Terminate()
Next
RefreshProcesses
End Sub
' ***************************************
' Refreshes list of processes in the "Running Processes" section
' ***************************************
Sub RefreshProcesses
strComputer = CurrentComputer.InnerHTML
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
ProcessesData.InnerHTML = RunningProcesses_HTML
End Sub
' ***************************************
' Enables/Disables the auto refresh feature in the "Running Processes" section
' ***************************************
sub SetProcessAutoRefresh
dim intInterval
' Get the refresh interval
intInterval = ProcessAutoRefresh.Value
' Remove the current auto-refresh
window.clearInterval(intProcessTimerID)
' Add an auto-refresh if specified
if intInterval > 0 then
intProcessTimerID = window.setInterval("RefreshProcesses", intInterval)
end if
end sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' and refreshes the processes list with the new sort value
' ***************************************
Sub SortProcesses(byval strSort)
' If sort link is clicked twice on the same column, sort descending
if ProcessSort.InnerHTML = strSort then
ProcessSort.InnerHTML = strSort & " DESC"
else
ProcessSort.InnerHTML = strSort
end if
RefreshProcesses()
End Sub
' ***************************************
' Map as network drive on this computer to a share on another computer
' Called from the "Shares" section. User is prompted for a drive letter
' ***************************************
Sub MapDrive(ByVal strPath)
Dim objNetwork
Dim strDrive
strDrive = InputBox("Enter drive letter:","Drive Letter","Z")
If strDrive <> "" Then
strDrive = Left(strDrive,1) & ":"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive,strPath
End If
End Sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' ***************************************
Sub MapPrinter(ByVal strPath)
Dim objNetwork
Set objNetwork = createobject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection(strPath)
If MsgBox("Make Printer Default?",vbYesNo+vbQuestion,"Default Printer") = vbYes Then
objNetwork.SetDefaultPrinter strPath
End If
End Sub
' ***************************************
' Replace special HTML characters
' ***************************************
Function HTMLEncode(strValue)
HTMLEncode= REplace(Replace(strValue,"<","<"),">",">")
End Function
' ***************************************
' Convert Bytes to MB,GB or TB as appropriate
' ***************************************
function ConvertToDiskUnit(ByVal value)
IF (value/bytesToTb) > 1 Then
ConvertToDiskUnit = round(value / bytesToTB,1) & " TB"
ELSEIF (value/bytesToGb) > 1 Then
ConvertToDiskUnit = round(value / bytesToGB,1) & " GB"
Else
ConvertToDiskUnit = round(value / bytesToMB,1) & " MB"
END If
end Function
' ***************************************
' Convert integer value to string
' ***************************************
Function GetMemoryType(ByVal intType)
Dim strType
Select case intType
Case 0
strType = "Unknown"
Case 1
strType = "Other"
Case 2
strType = "DRAM"
Case 3
strType = "Synchronous DRAM"
Case 4
strType = "Cache DRAM"
Case 5
strType = "EDO"
Case 6
strType = "EDRAM"
Case 7
strType = "VRAM"
Case 8
strType = "SRAM"
Case 9
strType = "RAM"
Case 10
strType = "ROM"
Case 11
strType = " Flash"
Case 12
strType = "EEPROM"
Case 13
strType = "FEPROM"
Case 14
strType = " EPROM"
Case 15
strType = " CDRAM"
Case 16
strType = "3DRAM"
Case 17
strType = " SDRAM"
Case 18
strType = " SGRAM"
Case 19
strType = " RDRAM"
Case 20
strType = " DDR"
Case 21
strType = " DDR-2"
Case Else
strType = "Unknown"
End Select
GetMemoryType=strType
End Function
' ***************************************
' Convert Integer value to string
' ***************************************
Function GetMemoryFormFactor(ByVal intFormFactor)
Dim strFormFactor
Select Case intFormFactor
Case 0
strFormFactor = "Unknown"
Case 1
strFormFactor = "Other"
Case 2
strFormFactor = "SIP"
Case 3
strFormFactor = "DIP"
Case 4
strFormFactor = "ZIP"
Case 5
strFormFactor = "SOJ"
Case 6
strFormFactor = "Proprietary"
Case 7
strFormFactor = "SIMM"
Case 8
strFormFactor = "DIMM"
Case 9
strFormFactor = "TSOP"
Case 10
strFormFactor = "PGA"
Case 11
strFormFactor = "RIMM"
Case 12
strFormFactor = "SODIMM"
Case 13
strFormFactor = "SRIMM"
Case 14
strFormFactor = "SMD"
Case 15
strFormFactor = "SSMP"
Case 16
strFormFactor = "QFP"
Case 17
strFormFactor = "TQFP"
Case 18
strFormFactor = "SOIC"
Case 19
strFormFactor = "LCC"
Case 20
strFormFactor = "PLCC"
Case 21
strFormFactor = "BGA"
Case 22
strFormFactor = "FPBGA"
Case 23
strFormFactor = "LGA"
case Else
strFormFactor = "Unknown"
End Select
GetMemoryFormFactor=strFormFactor
End Function
' ***************************************
' Convert date string to a more readable format
' ***************************************
Function FormatDate(ByVal strValue)
Dim strDate
If ISNULL(strValue) Or strValue = "" Then
strDate = ""
Else
strDate = Left(strValue,4) & "-" & MID(strValue,5,2) & "-" & MID(strValue,7,2) & " " & _
Mid(strValue,9,2) & ":" & Mid(strValue,11,2)
End If
FormatDate = strDate
End Function
' ***************************************
' Clear existing report data
' ***************************************
Sub Reset
ProcessAutoRefresh.Value="0"
window.clearInterval(intProcessTimerID)
Main.Style.Display = "none"
Tools.Style.Display = "none"
LogicalDisk.InnerHTML=""
PhysicalDisk.InnerHTML=""
Processor.InnerHTML =""
Memory.InnerHTML = ""
OS.InnerHTML =""
Shares.InnerHTML=""
DisplayError.InnerHTML=""
End Sub
' ***************************************
' Main procedure used to generate report
' Calls other procedures that generate the HTML for each section
' ***************************************
Sub GenerateReport
Reset()
strComputer = txtComputer.Value
if strComputer = "" Then
Dim objNetwork
set objNetwork = createobject("wscript.network")
strComputer = objNetwork.ComputerName
txtComputer.Value = strComputer
End If
CurrentComputer.InnerHTML = strComputer
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Exit Sub
End If
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
ProcessesData.InnerHTML = RunningProcesses_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
PhysicalDisk.InnerHTML = PhysicalDisk_HTML
Processor.InnerHTML = Processor_HTML
Memory.InnerHTML = Memory_HTML
OS.InnerHTML = OS_HTML
Shares.InnerHTML = Shares_HTML
End Sub
' ***************************************
' Gets a list of running processes and returns HTML for the "Running Processes" section
' ***************************************
Function RunningProcesses_HTML
Dim row,strHTML,strFilter
Dim DataList,colItems,objItem,strUser,strDomain
Dim strWMIQuery
strFilter = txtProcessFilter.Value
' Recordset is used to sort data from WMI
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Name", adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "WorkingSet", adInteger, adFldIsNullable
DataList.Fields.Append "CreationDate",adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "Description",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "ProcessID",adInteger, adFldIsNullable
DataList.Fields.Append "CPUTime",adInteger, adFldIsNullable
DataList.Fields.Append "Caption",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Owner",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Path",adVarChar,MaxCharacters, adFldIsNullable
DataList.Open
strWMIQuery = "Select * From Win32_Process"
' Add filter if required
if strFilter <> "" then
strWMIQuery = strWMIQuery & " WHERE Name LIKE '%" & strFilter & "%'"
end if
Set colItems = objWMIService.ExecQuery(strWMIQuery)
' Load WMI data into recordset
For Each objItem in colItems
Dim strOwner
DataList.AddNew
on error resume next
DataList("Name") = HTMLEncode(objItem.Name)
DataList("WorkingSet") = objItem.WorkingSetSize
DataList("CreationDate") = objItem.CreationDate
DataList("Description") = HTMLEncode(objItem.Description)
DataList("ProcessID") = objItem.ProcessID
DataList("Caption") = objItem.Caption
DataList("CPUTime") = (CSng(objItem.KernelModeTime) + CSng(objItem.UserModeTime)) / 10000000
If objItem.GetOwner (strUser, strDomain) = 0 Then
strOwner = strDomain & "\" & strUser
End If
DataList("Owner") = strOwner
on error goto 0
DataList.Update
Next
' Sort recordset
DataList.Sort = ProcessSort.InnerHTML
' Check if recordset is not empty
If DataList.BOF = FALSE then
DataList.MoveFirst
' Generate HTML table report with running processes
strHTML = strHTML & "<table class=""Table"">"
strHTML = strHTML & "<tr><th><span onclick=""SortProcesses('Name')"" class=""HeaderLink"">Name</span></th>" & _
"<th><span onclick=""SortProcesses('CreationDate')"" class=""HeaderLink"">Creation Date</span></th>" & _
"<th><span onclick=""SortProcesses('Owner')"" class=""HeaderLink"">Owner</span></th>" & _
"<th><span onclick=""SortProcesses('WorkingSet')"" class=""HeaderLink"">Working Set</span></th>" & _
"<th><span onclick=""SortProcesses('CPUTime')"" class=""HeaderLink"">Total CPU Time(s)</span></th>" & _
"<th> </th></tr>"
Do Until DataList.EOF
Dim strCaption,strCreationDate,strPath,intProcessID,strDescription
Dim strWorkingSet
strHTML = strHTML & "<tr>" & _
"<td><div title=""" & DataList("Path") & """>" & DataList("Name") & "</div></td>" & _
"<td>" & FormatDate(DataList("CreationDate")) & "</td>" & _
"<td>" & DataList("Owner") & "</td>" & _
"<td>" & ConvertToDiskUnit(DataList("WorkingSet")) & "</td>" & _
"<td>" & DataList("CPUTime") & "</td>" & _
"<td><span onclick=""KillProcess '" & DataList("ProcessID") & "','" & DataList("Name") & "'"" class=""Link"">Kill Process</span></td>" & _
"</tr>"
DataList.MoveNext
Loop
strHTML = strHTML & "</table>"
end if
DataList.Close
strHTML = strHTML & "<br>Last Refresh:" & Now()
RunningProcesses_HTML=strHTML
End Function
' ***************************************
' Gets a list of shared folders and shared printers and
' returns HTML for the "Shares" section
' ***************************************
Function Shares_HTML
Dim objItem, colItems
Dim strHTML
' Query to return shared folders
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483648 OR Type = 0")
strHTML = strHTML & "<table><tr><td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Folder Shares</th></tr>"
For Each objItem In colItems
Dim strShare
strShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strShare & "')"">" & strShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapDrive('\\" & strComputer & "\" & strShare & "')"" value=""Map Drive""></input></td></tr>"
Next
strHTML = strHTML & "</table></td>"
' Query to return shared printers
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483649 OR Type = 1")
strHTML = strHTML & "<td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Printer Shares</th></tr>"
For Each objItem In colItems
Dim strPrinterShare
strPrinterShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strPrinterShare & "')"">" & strPrinterShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapPrinter('\\" & strComputer & "\" & strPrinterShare & "')"" value=""Connect Printer""></input></td></tr>"
Next
strHTML = strHTML & "</table></td></table>"
Shares_HTML = strHTML
End Function
' ***************************************
' Gets computer system info to be included in the "OS / General" section
' ***************************************
Sub GetComputerSystemInfo(BYRef strobjSMBIOS,ByRef strDomain,ByRef strDomainRole, _
ByRef strManufacturer,ByRef strModel,ByRef strUserName)
Dim objItem, colItems
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem In colItems
On Error Resume Next
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
strDomain = HTMLEncode(objItem.Domain)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strModel = HTMLEncode(objItem.Model)
strUserName = HTMLEncode(objItem.UserName)
On Error GoTo 0
If strUserName = "" Then
strUserName = "No one logged in"
End If
Select Case objItem.DomainRole
Case 0
strDomainRole="Standalone Workstation"
Case 1
strDomainRole="Member Workstation"
Case 2
strDomainRole="Standalone Server"
Case 3
strDomainRole="Member Server"
Case 4
strDomainRole="Backup Domain Controller"
Case 5
strDomainRole="Primary Domain Controller"
Case Else
strDomainRole = "Unknown (" & strDomainRole & ")"
End Select
Next
End Sub
' ***************************************
' Returns a HTML report for the "Operating System/General" section
' ***************************************
Function OS_HTML()
Dim objItem, colItems
Dim strHTML
Dim strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
GetComputerSystemInfo strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
strHTML = "<h3>Current User: " & strUserName & "</h3>"
For Each objItem In colItems
Dim strComputerRole
Dim strCaption,strBuildNumber,strInstallDate,strBootDate
Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
Dim intFreePhysicalMemory,intTotalVirtualMemorySize,intFreeVirtualMemory
On Error Resume Next
strCaption = HTMLEncode(objItem.Caption)
strBuildNumber = HTMLEncode(objItem.BuildNumber)
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
intServicePackMajor = objItem.ServicePackMajorVersion
intServicePackMinor = objItem.ServicePackMinorVersion
intTotalVisibleMemorySize = objItem.TotalVisibleMemorySize
intFreePhysicalMemory = objItem.FreePhysicalMemory
intFreeVirtualMemory = objItem.FreeVirtualMemory
intTotalVirtualMemorySize = objItem.TotalVirtualMemorySize
strInstallDate = FormatDate(objItem.InstallDate)
strBootDate = FormatDate(objItem.LastBootUpTime)
On Error GoTo 0
strHTML = strHTML & "<table class=""Table"">" & _
"<tr>" & _
"<th>Operating System:</th><td>" & strCaption & "</td>" & _
"<th>Build Number:</th><td>" & strBuildNumber & "</td>" & _
"</tr><tr>" & _
"<th>Service Pack:</th><td>" & intServicePackMajor & "." & intServicePackMinor & "</td>" & _
"<th>Role:</th><td>" & strDomainRole & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strobjSMBIOS & "</td>" & _
"<th>Domain:</th><td>" & strDomain & "</td>" & _
"</tr><tr>" & _
"<th>Manufacturer:</th><td>" & strManufacturer & "</td>" & _
"<th>Model:</th><td>" & strModel & "</td>" & _
"</tr><tr>" & _
"<th>Total Physical Memory:</th><td>" & intTotalVisibleMemorySize & "KB</td>" & _
"<th>Free Physical Memory:</th><td>" & intFreePhysicalMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Total Virtual Memory:</th><td>" & intTotalVirtualMemorySize & "KB</td>" & _
"<th>Free Virtual Memory:</th><td>" & intFreeVirtualMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Install Date:</th><td>" & strInstallDate & "</td>" & _
"<th>Last BootUp Time:</th><td>" & strBootDate & "</td>" & _
"</tr>" & _
"</table>"
Exit For
Next
OS_HTML = strHTML
End Function
' ***************************************
' Get the number of memory slots and memory arrays
' for the memory section
' ***************************************
Function GetMemoryArrayInfo(ByRef intSlots,ByRef intArrays)
Dim objItem, colItems
intSlots = 0
intArrays = 0
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray WHERE Use=3")
For Each objItem In colItems
intSlots = intSlots + objItem.MemoryDevices
intArrays = intArrays + 1
Next
End Function
' ***************************************
' Returns a HTML report for the "Memory" section
' ***************************************
Function Memory_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>BankLabel</th>" & _
"<th>Capacity</th>" & _
"<th>Caption</th>" & _
"<th>Description</th>" & _
"<th>DeviceLocator </th>" & _
"<th>Manufacturer</th>" & _
"<th>Memory Type</th>" & _
"<th>Form Factor</th>" & _
"<th>Model</th>" & _
"<th>Speed</th>" & _
"</tr>"
For Each objItem In colItems
Dim strBankLabel,strCaption,strDescription,strDeviceLocator
Dim strManufacturer,strMemoryType,strFormFactor,strModel
Dim strCapacity,intSpeed
On Error Resume Next
strBankLabel = HTMLEncode(objItem.BankLabel)
strCapacity = ConvertToDiskUnit(objItem.Capacity)
strCaption = HTMLEncode(objItem.Caption)
strDescription = HTMLEncode(objItem.Description)
strDeviceLocator = HTMLEncode(objItem.DeviceLocator)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strMemoryType = GetMemoryType(objItem.MemoryType)
strFormFactor = GetMemoryFormFactor(objItem.FormFactor)
strModel = HTMLEncode(objItem.Model)
intSpeed = objItem.Speed
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strBankLabel & "</td>" & _
"<td>" & strCapacity & "</td>" & _
"<td>" & strCaption & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & strDeviceLocator & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strMemoryType & "</td>" & _
"<td>" & strFormFactor & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & intSpeed & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Dim intSlots,intArrays
GetMemoryArrayInfo intSlots,intArrays
strHTML = strHTML & "Total Memory Slots:" & intSlots & ", Memory Arrays:" & intArrays
Memory_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Processor" section
' ***************************************
Function Processor_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>Name</th>" & _
"<th>Manufacturer</th>" & _
"<th>Description</th>" & _
"<th>Address Width</th>" & _
"<th>Current Clock Speed</th>" & _
"<th>Data Width</th>" & _
"<th>Device ID</th>" & _
"<th>Ext Clock</th>" & _
"<th>L2 Cache</th>" & _
"<th>Max Clock Speed</th>" & _
"<th>#Cores</th>" & _
"<th>#Logical Processors</th>" & _
"</tr>"
For Each objItem in colItems
Dim strName,strManufacturer,strDescription,strDeviceID
Dim intAddressWidth,intCurrentClockSpeed,intDataWidth,intExtClock
Dim intL2CacheSize,intMaxClockSpeed, intNumberOfCores,intNumberOfLogicalProcessors
On Error Resume Next
strName = HTMLEncode(objItem.Name)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strDescription = HTMLEncode(objItem.Description)
intAddressWidth = objItem.AddressWidth
intCurrentClockSpeed = objItem.CurrentClockSpeed
intDataWidth = objItem.DataWidth
strDeviceID = HTMLEncode(objItem.DeviceID)
intExtClock = objItem.ExtClock
intL2CacheSize = objItem.L2CacheSize
intMaxClockSpeed = objItem.MaxClockSpeed
intNumberOfCores = objItem.NumberOfCores
intNumberOfLogicalProcessors= objItem.NumberOfLogicalProcessors
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strName & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & intAddressWidth & "</td>" & _
"<td>" & intCurrentClockSpeed & "</td>" & _
"<td>" & intDataWidth & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & intExtClock & "</td>" & _
"<td>" & intL2CacheSize & "</td>" & _
"<td>" & intMaxClockSpeed & "</td>" & _
"<td>" & intNumberOfCores & "</td>" & _
"<td>" & intNumberOfLogicalProcessors & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Processor_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Physical Disk" section
' ***************************************
Function PhysicalDisk_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
strHTML = "<table class=""Table""><tr><th>Caption</th><th>Manufacturer</th>" & _
"<th>Model</th><th>Size</th><th>Serial</th><th>Media Type</th><th>#Partitions</th><th>DeviceID</th><th>Firmware</th><th>Interface</th></tr>"
For Each objItem in colItems
Dim intSize,intPartitions
Dim strSize,strCaption,strManufacturer,strModel,strMediaType
Dim strDeviceID,strFirmwareRevision,strInterfaceType, strSerialNumber
intSize = objItem.Size
If IsNumeric(intSize) = False Then
intSize = 0
End If
On Error Resume Next
strCaption= HTMLEncode(objItem.Caption)
strSize = ConvertToDiskUnit(intSize)
strSerialNumber = HTMLEncode(objItem.SerialNumber)
strMediaType = HTMLEncode(objItem.MediaType)
intPartitions = HTMLEncode(objItem.Partitions)
strDeviceID = HTMLEncode(objItem.DeviceID)
strFirmwareRevision = HTMLEncode(objItem.FirmwareRevision)
strInterfaceType = HTMLEncode(objItem.InterfaceType)
strModel = HTMLEncode(objItem.Model)
strManufacturer = HTMLEncode(objItem.Manufacturer)
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strCaption & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & strSize & "</td>" & _
"<td>" & strSerialNumber & "</td>" & _
"<td>" & strMediaType & "</td>" & _
"<td>" & intPartitions & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & strFirmwareRevision & "</td>" & _
"<td>" & strInterfaceType & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
PhysicalDisk_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Logical Disk" section
' ***************************************
Function LogicalDisk_HTML()
Dim objItem, colItems
Dim strDriveType, strDiskSize, strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType = 3")
strHTML = "<table class=""Table""><tr><th>Drive</th><th>Name</th><th>File System</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>"
For Each objItem in colItems
Dim pctFreeSpace,strFreeSpace,strusedSpace,strName,strFileSystem,strVolumeName
Dim intFreeSpace, intSize
On Error Resume Next
intFreeSpace = objItem.FreeSpace
intSize = objItem.Size
If ISNUMERIC(intFreeSpace) = False Then
intFreeSpace=0
End If
If IsNumeric(intSize) = False Then
intSize = 0
End If
If objItem.FreeSpace > 0 Then
pctFreeSpace = round(((intFreeSpace / intSize) * 100),0)
Else
pctFreeSpace=0
End If
strDiskSize = ConvertToDiskUnit(intSize)
strFreeSpace = ConvertToDiskUnit(intFreeSpace)
strUsedSpace = ConvertToDiskUnit(intSize-intFreeSpace)
strName = HTMLEncode(objItem.Name)
strVolumeName = HTMLEncode(objItem.VolumeName)
strFileSystem = HTMLEncode(objItem.FileSystem)
On Error GoTo 0
dim strChart
strChart = "<div width=100%;""><span style=""padding:0px;margin:0px;width=" & 100-pctFreeSpace & _
"%;background-color:blue;""> </span><span style=""padding:0px;margin:0px;width=" & pctFreeSpace & _
"%;background-color:#FF00FF;""> </span></div>"
strHTML = strHTML & "<tr><td>" & strName & "</td><td>" & _
strVolumeName & "</td><td>" & strFileSystem & "</td><td>" & _
strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _
strFreeSpace & "</td><td>" & pctFreeSpace & "%</td></tr>" & _
"<tr><td colspan=""7"">" & strChart & "</td></tr>"
Next
strHTML = strHTML + "</table></br>"
LogicalDisk_HTML = strHTML
End Function
</script>
<script type="text/javascript">
/* Toggle expand/collapse state for specified section */
function toggleDisplay(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
/* Toggle expand/collapse state for all sections */
function toggleAll() {
var el = document.getElementById("OS");
var display = ''
if ( el.style.display != 'none' ) {
display = 'none';
}
el.style.display = display;
el = document.getElementById("Memory");
el.style.display = display;
el = document.getElementById("LogicalDisk");
el.style.display = display;
el = document.getElementById("PhysicalDisk");
el.style.display = display;
el = document.getElementById("Processor");
el.style.display = display;
el = document.getElementById("Shares");
el.style.display = display;
el = document.getElementById("Processes");
el.style.display = display;
}
</script>
<h1>Computer Info Tool</h1>
<div id="Header" style="padding-bottom:0px;margin-bottom:0px;">
<span style="font-weight:bold;">Connect To Computer:<span><input id="txtComputer"></input>
<input class="Button" style="font-weight:bold;" onClick="GenerateReport()" type="submit" value="Generate Report">
</input>
</div>
<div id="Tools" style="display:none;margin-bottom:0px;">
<span class="Link" onClick="RebootComputer">Reboot Computer</span> |
<span class="Link" onClick="ShutDownComputer">Shutdown Computer</span>
</div>
<div id="Main" style="display:none;">
<div id="CurrentComputer" style="display:none"></div>
<div style="text-align:right;">
<span class="Link" style="font-weight:bold;" onclick="javascript:toggleAll();">Expand/Collapse All</span>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('OS');" class="InfoSectionHeader">Operating System / General</div>
<div id="OS" class="InfoSectionBody" ></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processes');" class="InfoSectionHeader">Running Processes</div>
<div id="Processes" class="InfoSectionBody">
Auto Refresh Interval:<select id="ProcessAutoRefresh" onchange="SetProcessAutoRefresh">
<option value ="0">None</option>
<option value ="1000">1 second</option>
<option value ="2000">2 seconds</option>
<option value ="3000">3 seconds</option>
<option value ="5000">5 seconds</option>
<option value ="10000">10 seconds</option>
<option value ="20000">20 seconds</option>
<option value ="30000">30 seconds</option>
<option value ="60000">1 minute</option>
</select>
Filter (Optional):<input id="txtProcessFilter"></input>
<br/><br/>
<span onclick="RefreshProcesses()" style=""font-weight:bold"" class="Link">Refresh Processes</span>
<br/><br/>
<div id="ProcessesData"></div>
</div>
<div id="ProcessSort" style="display:none">Name</div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Memory');" class="InfoSectionHeader">Memory</div>
<div id="Memory" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('LogicalDisk');" class="InfoSectionHeader">Logical Disk</div>
<div id="LogicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('PhysicalDisk');" class="InfoSectionHeader">Physical Disk</div>
<div id="PhysicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processor');" class="InfoSectionHeader">Processor</div>
<div id="Processor" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Shares');" class="InfoSectionHeader">Shares</div>
<div id="Shares" class="InfoSectionBody"></div>
</div>
</div>
<div id="DisplayError"></div>
<div id="Footer">
<hr/>
<div style="float:left;">Version 1.0</div>
<div style="float:right;">By Dhiraj Mutha<br />
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
you would be better off putting this in the Javascript zone instead of the Java zone
javascipt is different from java
ASKER
I will also require this to get the details on bulk computers as well. I am not good in JavaScript, Intermidiate in VBScript. I am ready to change the tool itself if it completes my requirements. Does anyone as one?
Hi there. Try this. It will show the service tag, and output the HTML code to Excel, which picks it up mostly, without any changing...
Change this line:
strOutputFile = "C:\Temp\Report.xls"
Regards,
Rob.
Change this line:
strOutputFile = "C:\Temp\Report.xls"
Regards,
Rob.
<html >
<head>
<title>Computer Info Tool - By Dhiraj Mutha</title>
<hta:application applicationname="Prem's Computer Info Tool" scroll="yes" singleinstance="no"
windowstate="normal">
<style type="text/css">
body {
margin:0px;
background-color:#CBCBCB; /*#F6F6F6;*/
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#595959;
}
h1 {
font-size:24px;
font-weight:bold;
color:#FFFFFF;
background-color:#2886C8;
text-align:center;
border-style:solid;
border-width:thin;
border-color:#C9E0F1;
padding:5px;
}
h2 {
font-size:18px;
font-weight:bold;
}
h3 {
font-size:16px;
font-weight:bold;
}
a {
color:#2886C8;
}
#Main {
margin-left:20px;
margin-right:20px;
}
#DisplayError {
color:red;
margin-left:20px;
margin-right:20px;
}
#Footer {
margin:20px;
font-weight:bold;
font-size:16px;
}
#Header {
margin-left:20px;
margin-right:20px;
text-align:center;
}
#Tools {
text-align:center;
border-color:#595959;
border-style:dotted;
border-width:1px;
background-color:#F6F6F6;
margin-left:20px;
margin-right:20px;
margin-top:20px;
padding:5px;
}
.Button {
color: #444444;
}
.InfoSectionHeader {
font-size:20px;
font-weight:bold;
background-color:#595959;
color:#FFFFFF;
text-align:center;
padding:5px;
margin-top:0px;
cursor:pointer;
}
.InfoSection {
text-align:center;
margin-bottom:10px;
background-color:#FFFFFF;
border-color:#595959;
border-style:dotted;
border-width:1px;
}
.InfoSectionBody {
padding:10px;
}
.Link {
text-decoration: underline;
cursor:pointer;
color:#2886C8;
}
.HeaderLink {
text-decoration: underline;
cursor:pointer;
color:#FFFFFF;
}
.Table {
/*width:90%;*/
border: 2px solid;
border-collapse: collapse;
border-color: #696969;
}
.Table th {
border: 1px dotted #111111;
border-color: #787878;
color: #FFFFFF;
font: bold 12pt arial, sans-serif;
background-color: #595959; /* #787878;*/
text-align: left;
padding=3px;
}
.Table td {
border: 1px dotted #111111;
border-color: #787878;
font: bold 10pt arial, sans-serif;
color: #787878;
padding=5px;
}
</style>
</head>
<body>
<script language="VBScript">
Option Explicit
Const bytesToMB = 1048576
Const bytesToGB = 1073741824
Const bytesToTB = 1099511627776
Const adVarChar = 200
Const adDate = 7
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adInteger = 3
Const adBigInt = 20
Const blnConfirmKillProcess = true
Private objWMIService
Private strComputer
private intProcessTimerID
' ***************************************
' Get Service Tag
' ***************************************
Sub ServiceTag
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Next
End Sub
' ***************************************
' Open Windows explorer to a given path
' Used when clicking a link in the "Shares" section
' ***************************************
Sub OpenUNC(ByVal strPath)
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
strPath = "explorer.exe /e," & strPath
objShell.Run strPath
End Sub
' ***************************************
' Reboot computer
' ***************************************
sub RebootComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to reboot '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Reboot") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Reboot()
Next
msgbox "Computer '" & strComputer & "' has been rebooted",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Shutdown computer
' ***************************************
sub ShutDownComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to shutdown '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Shutdown") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Win32Shutdown(1)
Next
msgbox "Computer '" & strComputer & "' has been shutdown",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Kills the specified process
' Called when "Kill Process" link is clicked in the Running Processes section
' ***************************************
Sub KillProcess(ByVal intProcessID, ByVal strName)
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if blnConfirmKillProcess = True then
if msgbox("Are you sure you want to kill the '" & strName & "' process on '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Kill Process") = vbNo then
exit sub
end if
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = '" & _
intProcessID & "' AND Name = '" & strName & "'")
For Each objItem In colItems
objItem.Terminate()
Next
RefreshProcesses
End Sub
' ***************************************
' Refreshes list of processes in the "Running Processes" section
' ***************************************
Sub RefreshProcesses
strComputer = CurrentComputer.InnerHTML
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
ProcessesData.InnerHTML = RunningProcesses_HTML
End Sub
' ***************************************
' Enables/Disables the auto refresh feature in the "Running Processes" section
' ***************************************
sub SetProcessAutoRefresh
dim intInterval
' Get the refresh interval
intInterval = ProcessAutoRefresh.Value
' Remove the current auto-refresh
window.clearInterval(intProcessTimerID)
' Add an auto-refresh if specified
if intInterval > 0 then
intProcessTimerID = window.setInterval("RefreshProcesses", intInterval)
end if
end sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' and refreshes the processes list with the new sort value
' ***************************************
Sub SortProcesses(byval strSort)
' If sort link is clicked twice on the same column, sort descending
if ProcessSort.InnerHTML = strSort then
ProcessSort.InnerHTML = strSort & " DESC"
else
ProcessSort.InnerHTML = strSort
end if
RefreshProcesses()
End Sub
' ***************************************
' Map as network drive on this computer to a share on another computer
' Called from the "Shares" section. User is prompted for a drive letter
' ***************************************
Sub MapDrive(ByVal strPath)
Dim objNetwork
Dim strDrive
strDrive = InputBox("Enter drive letter:","Drive Letter","Z")
If strDrive <> "" Then
strDrive = Left(strDrive,1) & ":"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive,strPath
End If
End Sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' ***************************************
Sub MapPrinter(ByVal strPath)
Dim objNetwork
Set objNetwork = createobject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection(strPath)
If MsgBox("Make Printer Default?",vbYesNo+vbQuestion,"Default Printer") = vbYes Then
objNetwork.SetDefaultPrinter strPath
End If
End Sub
' ***************************************
' Replace special HTML characters
' ***************************************
Function HTMLEncode(strValue)
HTMLEncode= REplace(Replace(strValue,"<","<"),">",">")
End Function
' ***************************************
' Convert Bytes to MB,GB or TB as appropriate
' ***************************************
function ConvertToDiskUnit(ByVal value)
IF (value/bytesToTb) > 1 Then
ConvertToDiskUnit = round(value / bytesToTB,1) & " TB"
ELSEIF (value/bytesToGb) > 1 Then
ConvertToDiskUnit = round(value / bytesToGB,1) & " GB"
Else
ConvertToDiskUnit = round(value / bytesToMB,1) & " MB"
END If
end Function
' ***************************************
' Convert integer value to string
' ***************************************
Function GetMemoryType(ByVal intType)
Dim strType
Select case intType
Case 0
strType = "Unknown"
Case 1
strType = "Other"
Case 2
strType = "DRAM"
Case 3
strType = "Synchronous DRAM"
Case 4
strType = "Cache DRAM"
Case 5
strType = "EDO"
Case 6
strType = "EDRAM"
Case 7
strType = "VRAM"
Case 8
strType = "SRAM"
Case 9
strType = "RAM"
Case 10
strType = "ROM"
Case 11
strType = " Flash"
Case 12
strType = "EEPROM"
Case 13
strType = "FEPROM"
Case 14
strType = " EPROM"
Case 15
strType = " CDRAM"
Case 16
strType = "3DRAM"
Case 17
strType = " SDRAM"
Case 18
strType = " SGRAM"
Case 19
strType = " RDRAM"
Case 20
strType = " DDR"
Case 21
strType = " DDR-2"
Case Else
strType = "Unknown"
End Select
GetMemoryType=strType
End Function
' ***************************************
' Convert Integer value to string
' ***************************************
Function GetMemoryFormFactor(ByVal intFormFactor)
Dim strFormFactor
Select Case intFormFactor
Case 0
strFormFactor = "Unknown"
Case 1
strFormFactor = "Other"
Case 2
strFormFactor = "SIP"
Case 3
strFormFactor = "DIP"
Case 4
strFormFactor = "ZIP"
Case 5
strFormFactor = "SOJ"
Case 6
strFormFactor = "Proprietary"
Case 7
strFormFactor = "SIMM"
Case 8
strFormFactor = "DIMM"
Case 9
strFormFactor = "TSOP"
Case 10
strFormFactor = "PGA"
Case 11
strFormFactor = "RIMM"
Case 12
strFormFactor = "SODIMM"
Case 13
strFormFactor = "SRIMM"
Case 14
strFormFactor = "SMD"
Case 15
strFormFactor = "SSMP"
Case 16
strFormFactor = "QFP"
Case 17
strFormFactor = "TQFP"
Case 18
strFormFactor = "SOIC"
Case 19
strFormFactor = "LCC"
Case 20
strFormFactor = "PLCC"
Case 21
strFormFactor = "BGA"
Case 22
strFormFactor = "FPBGA"
Case 23
strFormFactor = "LGA"
case Else
strFormFactor = "Unknown"
End Select
GetMemoryFormFactor=strFormFactor
End Function
' ***************************************
' Convert date string to a more readable format
' ***************************************
Function FormatDate(ByVal strValue)
Dim strDate
If ISNULL(strValue) Or strValue = "" Then
strDate = ""
Else
strDate = Left(strValue,4) & "-" & MID(strValue,5,2) & "-" & MID(strValue,7,2) & " " & _
Mid(strValue,9,2) & ":" & Mid(strValue,11,2)
End If
FormatDate = strDate
End Function
' ***************************************
' Clear existing report data
' ***************************************
Sub Reset
ProcessAutoRefresh.Value="0"
window.clearInterval(intProcessTimerID)
Main.Style.Display = "none"
Tools.Style.Display = "none"
LogicalDisk.InnerHTML=""
PhysicalDisk.InnerHTML=""
Processor.InnerHTML =""
Memory.InnerHTML = ""
OS.InnerHTML =""
Shares.InnerHTML=""
DisplayError.InnerHTML=""
End Sub
' ***************************************
' Main procedure used to generate report
' Calls other procedures that generate the HTML for each section
' ***************************************
Sub GenerateReport
Reset()
strComputer = txtComputer.Value
if strComputer = "" Then
Dim objNetwork
set objNetwork = createobject("wscript.network")
strComputer = objNetwork.ComputerName
txtComputer.Value = strComputer
End If
CurrentComputer.InnerHTML = strComputer
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Exit Sub
End If
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
ProcessesData.InnerHTML = RunningProcesses_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
PhysicalDisk.InnerHTML = PhysicalDisk_HTML
Processor.InnerHTML = Processor_HTML
Memory.InnerHTML = Memory_HTML
OS.InnerHTML = OS_HTML
Shares.InnerHTML = Shares_HTML
End Sub
' ***************************************
' Gets a list of running processes and returns HTML for the "Running Processes" section
' ***************************************
Function RunningProcesses_HTML
Dim row,strHTML,strFilter
Dim DataList,colItems,objItem,strUser,strDomain
Dim strWMIQuery
strFilter = txtProcessFilter.Value
' Recordset is used to sort data from WMI
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Name", adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "WorkingSet", adInteger, adFldIsNullable
DataList.Fields.Append "CreationDate",adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "Description",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "ProcessID",adInteger, adFldIsNullable
DataList.Fields.Append "CPUTime",adInteger, adFldIsNullable
DataList.Fields.Append "Caption",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Owner",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Path",adVarChar,MaxCharacters, adFldIsNullable
DataList.Open
strWMIQuery = "Select * From Win32_Process"
' Add filter if required
if strFilter <> "" then
strWMIQuery = strWMIQuery & " WHERE Name LIKE '%" & strFilter & "%'"
end if
Set colItems = objWMIService.ExecQuery(strWMIQuery)
' Load WMI data into recordset
For Each objItem in colItems
Dim strOwner
DataList.AddNew
on error resume next
DataList("Name") = HTMLEncode(objItem.Name)
DataList("WorkingSet") = objItem.WorkingSetSize
DataList("CreationDate") = objItem.CreationDate
DataList("Description") = HTMLEncode(objItem.Description)
DataList("ProcessID") = objItem.ProcessID
DataList("Caption") = objItem.Caption
DataList("CPUTime") = (CSng(objItem.KernelModeTime) + CSng(objItem.UserModeTime)) / 10000000
If objItem.GetOwner (strUser, strDomain) = 0 Then
strOwner = strDomain & "\" & strUser
End If
DataList("Owner") = strOwner
on error goto 0
DataList.Update
Next
' Sort recordset
DataList.Sort = ProcessSort.InnerHTML
' Check if recordset is not empty
If DataList.BOF = FALSE then
DataList.MoveFirst
' Generate HTML table report with running processes
strHTML = strHTML & "<table class=""Table"">"
strHTML = strHTML & "<tr><th><span onclick=""SortProcesses('Name')"" class=""HeaderLink"">Name</span></th>" & _
"<th><span onclick=""SortProcesses('CreationDate')"" class=""HeaderLink"">Creation Date</span></th>" & _
"<th><span onclick=""SortProcesses('Owner')"" class=""HeaderLink"">Owner</span></th>" & _
"<th><span onclick=""SortProcesses('WorkingSet')"" class=""HeaderLink"">Working Set</span></th>" & _
"<th><span onclick=""SortProcesses('CPUTime')"" class=""HeaderLink"">Total CPU Time(s)</span></th>" & _
"<th> </th></tr>"
Do Until DataList.EOF
Dim strCaption,strCreationDate,strPath,intProcessID,strDescription
Dim strWorkingSet
strHTML = strHTML & "<tr>" & _
"<td><div title=""" & DataList("Path") & """>" & DataList("Name") & "</div></td>" & _
"<td>" & FormatDate(DataList("CreationDate")) & "</td>" & _
"<td>" & DataList("Owner") & "</td>" & _
"<td>" & ConvertToDiskUnit(DataList("WorkingSet")) & "</td>" & _
"<td>" & DataList("CPUTime") & "</td>" & _
"<td><span onclick=""KillProcess '" & DataList("ProcessID") & "','" & DataList("Name") & "'"" class=""Link"">Kill Process</span></td>" & _
"</tr>"
DataList.MoveNext
Loop
strHTML = strHTML & "</table>"
end if
DataList.Close
strHTML = strHTML & "<br>Last Refresh:" & Now()
RunningProcesses_HTML=strHTML
End Function
' ***************************************
' Gets a list of shared folders and shared printers and
' returns HTML for the "Shares" section
' ***************************************
Function Shares_HTML
Dim objItem, colItems
Dim strHTML
' Query to return shared folders
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483648 OR Type = 0")
strHTML = strHTML & "<table><tr><td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Folder Shares</th></tr>"
For Each objItem In colItems
Dim strShare
strShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strShare & "')"">" & strShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapDrive('\\" & strComputer & "\" & strShare & "')"" value=""Map Drive""></input></td></tr>"
Next
strHTML = strHTML & "</table></td>"
' Query to return shared printers
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483649 OR Type = 1")
strHTML = strHTML & "<td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Printer Shares</th></tr>"
For Each objItem In colItems
Dim strPrinterShare
strPrinterShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strPrinterShare & "')"">" & strPrinterShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapPrinter('\\" & strComputer & "\" & strPrinterShare & "')"" value=""Connect Printer""></input></td></tr>"
Next
strHTML = strHTML & "</table></td></table>"
Shares_HTML = strHTML
End Function
' ***************************************
' Gets computer system info to be included in the "OS / General" section
' ***************************************
Sub GetComputerSystemInfo(BYRef strobjSMBIOS,ByRef strDomain,ByRef strDomainRole, _
ByRef strManufacturer,ByRef strModel,ByRef strUserName)
Dim objItem, colItems
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem In colItems
On Error Resume Next
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
strDomain = HTMLEncode(objItem.Domain)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strModel = HTMLEncode(objItem.Model)
strUserName = HTMLEncode(objItem.UserName)
On Error GoTo 0
If strUserName = "" Then
strUserName = "No one logged in"
End If
Select Case objItem.DomainRole
Case 0
strDomainRole="Standalone Workstation"
Case 1
strDomainRole="Member Workstation"
Case 2
strDomainRole="Standalone Server"
Case 3
strDomainRole="Member Server"
Case 4
strDomainRole="Backup Domain Controller"
Case 5
strDomainRole="Primary Domain Controller"
Case Else
strDomainRole = "Unknown (" & strDomainRole & ")"
End Select
Next
End Sub
' ***************************************
' Returns a HTML report for the "Operating System/General" section
' ***************************************
Function OS_HTML()
Dim objItem, colItems
Dim strHTML
Dim strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
GetComputerSystemInfo strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
Dim strServiceTag
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
For Each objItem In colItems
strServiceTag = objItem.SerialNumber
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
strHTML = "<h3>Current User: " & strUserName & "</h3>"
For Each objItem In colItems
Dim strComputerRole
Dim strCaption,strBuildNumber,strInstallDate,strBootDate
Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
Dim intFreePhysicalMemory,intTotalVirtualMemorySize,intFreeVirtualMemory
On Error Resume Next
strCaption = HTMLEncode(objItem.Caption)
strBuildNumber = HTMLEncode(objItem.BuildNumber)
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
intServicePackMajor = objItem.ServicePackMajorVersion
intServicePackMinor = objItem.ServicePackMinorVersion
intTotalVisibleMemorySize = objItem.TotalVisibleMemorySize
intFreePhysicalMemory = objItem.FreePhysicalMemory
intFreeVirtualMemory = objItem.FreeVirtualMemory
intTotalVirtualMemorySize = objItem.TotalVirtualMemorySize
strInstallDate = FormatDate(objItem.InstallDate)
strBootDate = FormatDate(objItem.LastBootUpTime)
On Error GoTo 0
strHTML = strHTML & "<table class=""Table"">" & _
"<tr>" & _
"<th>Operating System:</th><td>" & strCaption & "</td>" & _
"<th>Build Number:</th><td>" & strBuildNumber & "</td>" & _
"</tr><tr>" & _
"<th>Service Pack:</th><td>" & intServicePackMajor & "." & intServicePackMinor & "</td>" & _
"<th>Role:</th><td>" & strDomainRole & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strobjSMBIOS & "</td>" & _
"<th>Domain:</th><td>" & strDomain & "</td>" & _
"</tr><tr>" & _
"<th>Manufacturer:</th><td>" & strManufacturer & "</td>" & _
"<th>Model:</th><td>" & strModel & "</td>" & _
"</tr><tr>" & _
"<th>Total Physical Memory:</th><td>" & intTotalVisibleMemorySize & "KB</td>" & _
"<th>Free Physical Memory:</th><td>" & intFreePhysicalMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Total Virtual Memory:</th><td>" & intTotalVirtualMemorySize & "KB</td>" & _
"<th>Free Virtual Memory:</th><td>" & intFreeVirtualMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Install Date:</th><td>" & strInstallDate & "</td>" & _
"<th>Last BootUp Time:</th><td>" & strBootDate & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strServiceTag & "</td>" & _
"<th></th><td></td>" & _
"</tr>" & _
"</table>"
Exit For
Next
OS_HTML = strHTML
End Function
' ***************************************
' Get the number of memory slots and memory arrays
' for the memory section
' ***************************************
Function GetMemoryArrayInfo(ByRef intSlots,ByRef intArrays)
Dim objItem, colItems
intSlots = 0
intArrays = 0
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray WHERE Use=3")
For Each objItem In colItems
intSlots = intSlots + objItem.MemoryDevices
intArrays = intArrays + 1
Next
End Function
' ***************************************
' Returns a HTML report for the "Memory" section
' ***************************************
Function Memory_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>BankLabel</th>" & _
"<th>Capacity</th>" & _
"<th>Caption</th>" & _
"<th>Description</th>" & _
"<th>DeviceLocator </th>" & _
"<th>Manufacturer</th>" & _
"<th>Memory Type</th>" & _
"<th>Form Factor</th>" & _
"<th>Model</th>" & _
"<th>Speed</th>" & _
"</tr>"
For Each objItem In colItems
Dim strBankLabel,strCaption,strDescription,strDeviceLocator
Dim strManufacturer,strMemoryType,strFormFactor,strModel
Dim strCapacity,intSpeed
On Error Resume Next
strBankLabel = HTMLEncode(objItem.BankLabel)
strCapacity = ConvertToDiskUnit(objItem.Capacity)
strCaption = HTMLEncode(objItem.Caption)
strDescription = HTMLEncode(objItem.Description)
strDeviceLocator = HTMLEncode(objItem.DeviceLocator)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strMemoryType = GetMemoryType(objItem.MemoryType)
strFormFactor = GetMemoryFormFactor(objItem.FormFactor)
strModel = HTMLEncode(objItem.Model)
intSpeed = objItem.Speed
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strBankLabel & "</td>" & _
"<td>" & strCapacity & "</td>" & _
"<td>" & strCaption & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & strDeviceLocator & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strMemoryType & "</td>" & _
"<td>" & strFormFactor & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & intSpeed & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Dim intSlots,intArrays
GetMemoryArrayInfo intSlots,intArrays
strHTML = strHTML & "Total Memory Slots:" & intSlots & ", Memory Arrays:" & intArrays
Memory_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Processor" section
' ***************************************
Function Processor_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>Name</th>" & _
"<th>Manufacturer</th>" & _
"<th>Description</th>" & _
"<th>Address Width</th>" & _
"<th>Current Clock Speed</th>" & _
"<th>Data Width</th>" & _
"<th>Device ID</th>" & _
"<th>Ext Clock</th>" & _
"<th>L2 Cache</th>" & _
"<th>Max Clock Speed</th>" & _
"<th>#Cores</th>" & _
"<th>#Logical Processors</th>" & _
"</tr>"
For Each objItem in colItems
Dim strName,strManufacturer,strDescription,strDeviceID
Dim intAddressWidth,intCurrentClockSpeed,intDataWidth,intExtClock
Dim intL2CacheSize,intMaxClockSpeed, intNumberOfCores,intNumberOfLogicalProcessors
On Error Resume Next
strName = HTMLEncode(objItem.Name)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strDescription = HTMLEncode(objItem.Description)
intAddressWidth = objItem.AddressWidth
intCurrentClockSpeed = objItem.CurrentClockSpeed
intDataWidth = objItem.DataWidth
strDeviceID = HTMLEncode(objItem.DeviceID)
intExtClock = objItem.ExtClock
intL2CacheSize = objItem.L2CacheSize
intMaxClockSpeed = objItem.MaxClockSpeed
intNumberOfCores = objItem.NumberOfCores
intNumberOfLogicalProcessors= objItem.NumberOfLogicalProcessors
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strName & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & intAddressWidth & "</td>" & _
"<td>" & intCurrentClockSpeed & "</td>" & _
"<td>" & intDataWidth & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & intExtClock & "</td>" & _
"<td>" & intL2CacheSize & "</td>" & _
"<td>" & intMaxClockSpeed & "</td>" & _
"<td>" & intNumberOfCores & "</td>" & _
"<td>" & intNumberOfLogicalProcessors & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Processor_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Physical Disk" section
' ***************************************
Function PhysicalDisk_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
strHTML = "<table class=""Table""><tr><th>Caption</th><th>Manufacturer</th>" & _
"<th>Model</th><th>Size</th><th>Serial</th><th>Media Type</th><th>#Partitions</th><th>DeviceID</th><th>Firmware</th><th>Interface</th></tr>"
For Each objItem in colItems
Dim intSize,intPartitions
Dim strSize,strCaption,strManufacturer,strModel,strMediaType
Dim strDeviceID,strFirmwareRevision,strInterfaceType, strSerialNumber
intSize = objItem.Size
If IsNumeric(intSize) = False Then
intSize = 0
End If
On Error Resume Next
strCaption= HTMLEncode(objItem.Caption)
strSize = ConvertToDiskUnit(intSize)
strSerialNumber = HTMLEncode(objItem.SerialNumber)
strMediaType = HTMLEncode(objItem.MediaType)
intPartitions = HTMLEncode(objItem.Partitions)
strDeviceID = HTMLEncode(objItem.DeviceID)
strFirmwareRevision = HTMLEncode(objItem.FirmwareRevision)
strInterfaceType = HTMLEncode(objItem.InterfaceType)
strModel = HTMLEncode(objItem.Model)
strManufacturer = HTMLEncode(objItem.Manufacturer)
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strCaption & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & strSize & "</td>" & _
"<td>" & strSerialNumber & "</td>" & _
"<td>" & strMediaType & "</td>" & _
"<td>" & intPartitions & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & strFirmwareRevision & "</td>" & _
"<td>" & strInterfaceType & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
PhysicalDisk_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Logical Disk" section
' ***************************************
Function LogicalDisk_HTML()
Dim objItem, colItems
Dim strDriveType, strDiskSize, strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType = 3")
strHTML = "<table class=""Table""><tr><th>Drive</th><th>Name</th><th>File System</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>"
For Each objItem in colItems
Dim pctFreeSpace,strFreeSpace,strusedSpace,strName,strFileSystem,strVolumeName
Dim intFreeSpace, intSize
On Error Resume Next
intFreeSpace = objItem.FreeSpace
intSize = objItem.Size
If ISNUMERIC(intFreeSpace) = False Then
intFreeSpace=0
End If
If IsNumeric(intSize) = False Then
intSize = 0
End If
If objItem.FreeSpace > 0 Then
pctFreeSpace = round(((intFreeSpace / intSize) * 100),0)
Else
pctFreeSpace=0
End If
strDiskSize = ConvertToDiskUnit(intSize)
strFreeSpace = ConvertToDiskUnit(intFreeSpace)
strUsedSpace = ConvertToDiskUnit(intSize-intFreeSpace)
strName = HTMLEncode(objItem.Name)
strVolumeName = HTMLEncode(objItem.VolumeName)
strFileSystem = HTMLEncode(objItem.FileSystem)
On Error GoTo 0
dim strChart
strChart = "<div width=100%;""><span style=""padding:0px;margin:0px;width=" & 100-pctFreeSpace & _
"%;background-color:blue;""> </span><span style=""padding:0px;margin:0px;width=" & pctFreeSpace & _
"%;background-color:#FF00FF;""> </span></div>"
strHTML = strHTML & "<tr><td>" & strName & "</td><td>" & _
strVolumeName & "</td><td>" & strFileSystem & "</td><td>" & _
strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _
strFreeSpace & "</td><td>" & pctFreeSpace & "%</td></tr>" & _
"<tr><td colspan=""7"">" & strChart & "</td></tr>"
Next
strHTML = strHTML + "</table></br>"
LogicalDisk_HTML = strHTML
End Function
Sub OutputToExcel
Dim objFSO, objFile, objShell, strOutputFile
strOutputFile = "C:\Temp\Report.xls"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutputFile, True)
objFile.WriteLine OS.InnerHTML
objFile.WriteLine ProcessesData.InnerHTML
objFile.WriteLine Memory.InnerHTML
objFile.WriteLine LogicalDisk.InnerHTML
objFile.WriteLine PhysicalDisk.InnerHTML
objFile.WriteLine Processor.InnerHTML
objFile.WriteLine Shares.InnerHTML
objFile.Close
Set objShell = CreateObject("WScript.Shell")
objShell.Run "excel """ & strOutputFile & """", 1, False
End Sub
</script>
<script type="text/javascript">
/* Toggle expand/collapse state for specified section */
function toggleDisplay(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
/* Toggle expand/collapse state for all sections */
function toggleAll() {
var el = document.getElementById("OS");
var display = ''
if ( el.style.display != 'none' ) {
display = 'none';
}
el.style.display = display;
el = document.getElementById("Memory");
el.style.display = display;
el = document.getElementById("LogicalDisk");
el.style.display = display;
el = document.getElementById("PhysicalDisk");
el.style.display = display;
el = document.getElementById("Processor");
el.style.display = display;
el = document.getElementById("Shares");
el.style.display = display;
el = document.getElementById("Processes");
el.style.display = display;
}
</script>
<h1>Computer Info Tool</h1>
<div id="Header" style="padding-bottom:0px;margin-bottom:0px;">
<span style="font-weight:bold;">Connect To Computer:<span><input id="txtComputer"></input>
<input class="Button" style="font-weight:bold;" onClick="GenerateReport()" type="submit" value="Generate Report">
<input class="Button" style="font-weight:bold;" onClick="OutputToExcel()" type="button" value="Output To Excel">
</input>
</div>
<div id="Tools" style="display:none;margin-bottom:0px;">
<span class="Link" onClick="RebootComputer">Reboot Computer</span> |
<span class="Link" onClick="ShutDownComputer">Shutdown Computer</span>
</div>
<div id="Main" style="display:none;">
<div id="CurrentComputer" style="display:none"></div>
<div style="text-align:right;">
<span class="Link" style="font-weight:bold;" onclick="javascript:toggleAll();">Expand/Collapse All</span>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('OS');" class="InfoSectionHeader">Operating System / General</div>
<div id="OS" class="InfoSectionBody" ></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processes');" class="InfoSectionHeader">Running Processes</div>
<div id="Processes" class="InfoSectionBody">
Auto Refresh Interval:<select id="ProcessAutoRefresh" onchange="SetProcessAutoRefresh">
<option value ="0">None</option>
<option value ="1000">1 second</option>
<option value ="2000">2 seconds</option>
<option value ="3000">3 seconds</option>
<option value ="5000">5 seconds</option>
<option value ="10000">10 seconds</option>
<option value ="20000">20 seconds</option>
<option value ="30000">30 seconds</option>
<option value ="60000">1 minute</option>
</select>
Filter (Optional):<input id="txtProcessFilter"></input>
<br/><br/>
<span onclick="RefreshProcesses()" style=""font-weight:bold"" class="Link">Refresh Processes</span>
<br/><br/>
<div id="ProcessesData"></div>
</div>
<div id="ProcessSort" style="display:none">Name</div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Memory');" class="InfoSectionHeader">Memory</div>
<div id="Memory" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('LogicalDisk');" class="InfoSectionHeader">Logical Disk</div>
<div id="LogicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('PhysicalDisk');" class="InfoSectionHeader">Physical Disk</div>
<div id="PhysicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processor');" class="InfoSectionHeader">Processor</div>
<div id="Processor" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Shares');" class="InfoSectionHeader">Shares</div>
<div id="Shares" class="InfoSectionBody"></div>
</div>
</div>
<div id="DisplayError"></div>
<div id="Footer">
<hr/>
<div style="float:left;">Version 1.0</div>
<div style="float:right;">By Dhiraj Mutha<br />
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
ASKER
Thanks a lot... i will test it and let you know.... what about bluk requests... suppose i want to scan 10 systems and output it to excel.... Cant it be displayed in a tabular manner in excel.... i am ok if i get specific details also... I dont want the processes, physical disks, processor and shares, what i only require is General OS Details with service Tag, Memory, Logical disk detials.... Can you help plz...
ASKER
Hi Rob,
Any updates on this mate?
Any updates on this mate?
ASKER
Rob, please look into this mate....
Hey mate...wow, I've been busy....try this...
Regards,
Rob.
Regards,
Rob.
<html >
<head>
<title>Computer Info Tool - By Dhiraj Mutha</title>
<hta:application applicationname="Prem's Computer Info Tool" scroll="yes" singleinstance="no"
windowstate="normal">
<style type="text/css">
body {
margin:0px;
background-color:#CBCBCB; /*#F6F6F6;*/
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#595959;
}
h1 {
font-size:24px;
font-weight:bold;
color:#FFFFFF;
background-color:#2886C8;
text-align:center;
border-style:solid;
border-width:thin;
border-color:#C9E0F1;
padding:5px;
}
h2 {
font-size:18px;
font-weight:bold;
}
h3 {
font-size:16px;
font-weight:bold;
}
a {
color:#2886C8;
}
#Main {
margin-left:20px;
margin-right:20px;
}
#DisplayError {
color:red;
margin-left:20px;
margin-right:20px;
}
#Footer {
margin:20px;
font-weight:bold;
font-size:16px;
}
#Header {
margin-left:20px;
margin-right:20px;
text-align:center;
}
#Tools {
text-align:center;
border-color:#595959;
border-style:dotted;
border-width:1px;
background-color:#F6F6F6;
margin-left:20px;
margin-right:20px;
margin-top:20px;
padding:5px;
}
.Button {
color: #444444;
}
.InfoSectionHeader {
font-size:20px;
font-weight:bold;
background-color:#595959;
color:#FFFFFF;
text-align:center;
padding:5px;
margin-top:0px;
cursor:pointer;
}
.InfoSection {
text-align:center;
margin-bottom:10px;
background-color:#FFFFFF;
border-color:#595959;
border-style:dotted;
border-width:1px;
}
.InfoSectionBody {
padding:10px;
}
.Link {
text-decoration: underline;
cursor:pointer;
color:#2886C8;
}
.HeaderLink {
text-decoration: underline;
cursor:pointer;
color:#FFFFFF;
}
.Table {
/*width:90%;*/
border: 2px solid;
border-collapse: collapse;
border-color: #696969;
}
.Table th {
border: 1px dotted #111111;
border-color: #787878;
color: #FFFFFF;
font: bold 12pt arial, sans-serif;
background-color: #595959; /* #787878;*/
text-align: left;
padding=3px;
}
.Table td {
border: 1px dotted #111111;
border-color: #787878;
font: bold 10pt arial, sans-serif;
color: #787878;
padding=5px;
}
</style>
</head>
<body>
<script language="VBScript">
Option Explicit
Const bytesToMB = 1048576
Const bytesToGB = 1073741824
Const bytesToTB = 1099511627776
Const adVarChar = 200
Const adDate = 7
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adInteger = 3
Const adBigInt = 20
Const blnConfirmKillProcess = true
Const intForReading = 1
Private objWMIService
Private strComputer
private intProcessTimerID
' ***************************************
' Get Service Tag
' ***************************************
Sub ServiceTag
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Next
End Sub
' ***************************************
' Open Windows explorer to a given path
' Used when clicking a link in the "Shares" section
' ***************************************
Sub OpenUNC(ByVal strPath)
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
strPath = "explorer.exe /e," & strPath
objShell.Run strPath
End Sub
' ***************************************
' Reboot computer
' ***************************************
sub RebootComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to reboot '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Reboot") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Reboot()
Next
msgbox "Computer '" & strComputer & "' has been rebooted",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Shutdown computer
' ***************************************
sub ShutDownComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to shutdown '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Shutdown") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Win32Shutdown(1)
Next
msgbox "Computer '" & strComputer & "' has been shutdown",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Kills the specified process
' Called when "Kill Process" link is clicked in the Running Processes section
' ***************************************
Sub KillProcess(ByVal intProcessID, ByVal strName)
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if blnConfirmKillProcess = True then
if msgbox("Are you sure you want to kill the '" & strName & "' process on '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Kill Process") = vbNo then
exit sub
end if
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = '" & _
intProcessID & "' AND Name = '" & strName & "'")
For Each objItem In colItems
objItem.Terminate()
Next
RefreshProcesses
End Sub
' ***************************************
' Refreshes list of processes in the "Running Processes" section
' ***************************************
Sub RefreshProcesses
strComputer = CurrentComputer.InnerHTML
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
ProcessesData.InnerHTML = RunningProcesses_HTML
End Sub
' ***************************************
' Enables/Disables the auto refresh feature in the "Running Processes" section
' ***************************************
sub SetProcessAutoRefresh
dim intInterval
' Get the refresh interval
intInterval = ProcessAutoRefresh.Value
' Remove the current auto-refresh
window.clearInterval(intProcessTimerID)
' Add an auto-refresh if specified
if intInterval > 0 then
intProcessTimerID = window.setInterval("RefreshProcesses", intInterval)
end if
end sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' and refreshes the processes list with the new sort value
' ***************************************
Sub SortProcesses(byval strSort)
' If sort link is clicked twice on the same column, sort descending
if ProcessSort.InnerHTML = strSort then
ProcessSort.InnerHTML = strSort & " DESC"
else
ProcessSort.InnerHTML = strSort
end if
RefreshProcesses()
End Sub
' ***************************************
' Map as network drive on this computer to a share on another computer
' Called from the "Shares" section. User is prompted for a drive letter
' ***************************************
Sub MapDrive(ByVal strPath)
Dim objNetwork
Dim strDrive
strDrive = InputBox("Enter drive letter:","Drive Letter","Z")
If strDrive <> "" Then
strDrive = Left(strDrive,1) & ":"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive,strPath
End If
End Sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' ***************************************
Sub MapPrinter(ByVal strPath)
Dim objNetwork
Set objNetwork = createobject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection(strPath)
If MsgBox("Make Printer Default?",vbYesNo+vbQuestion,"Default Printer") = vbYes Then
objNetwork.SetDefaultPrinter strPath
End If
End Sub
' ***************************************
' Replace special HTML characters
' ***************************************
Function HTMLEncode(strValue)
HTMLEncode= REplace(Replace(strValue,"<","<"),">",">")
End Function
' ***************************************
' Convert Bytes to MB,GB or TB as appropriate
' ***************************************
function ConvertToDiskUnit(ByVal value)
IF (value/bytesToTb) > 1 Then
ConvertToDiskUnit = round(value / bytesToTB,1) & " TB"
ELSEIF (value/bytesToGb) > 1 Then
ConvertToDiskUnit = round(value / bytesToGB,1) & " GB"
Else
ConvertToDiskUnit = round(value / bytesToMB,1) & " MB"
END If
end Function
' ***************************************
' Convert integer value to string
' ***************************************
Function GetMemoryType(ByVal intType)
Dim strType
Select case intType
Case 0
strType = "Unknown"
Case 1
strType = "Other"
Case 2
strType = "DRAM"
Case 3
strType = "Synchronous DRAM"
Case 4
strType = "Cache DRAM"
Case 5
strType = "EDO"
Case 6
strType = "EDRAM"
Case 7
strType = "VRAM"
Case 8
strType = "SRAM"
Case 9
strType = "RAM"
Case 10
strType = "ROM"
Case 11
strType = " Flash"
Case 12
strType = "EEPROM"
Case 13
strType = "FEPROM"
Case 14
strType = " EPROM"
Case 15
strType = " CDRAM"
Case 16
strType = "3DRAM"
Case 17
strType = " SDRAM"
Case 18
strType = " SGRAM"
Case 19
strType = " RDRAM"
Case 20
strType = " DDR"
Case 21
strType = " DDR-2"
Case Else
strType = "Unknown"
End Select
GetMemoryType=strType
End Function
' ***************************************
' Convert Integer value to string
' ***************************************
Function GetMemoryFormFactor(ByVal intFormFactor)
Dim strFormFactor
Select Case intFormFactor
Case 0
strFormFactor = "Unknown"
Case 1
strFormFactor = "Other"
Case 2
strFormFactor = "SIP"
Case 3
strFormFactor = "DIP"
Case 4
strFormFactor = "ZIP"
Case 5
strFormFactor = "SOJ"
Case 6
strFormFactor = "Proprietary"
Case 7
strFormFactor = "SIMM"
Case 8
strFormFactor = "DIMM"
Case 9
strFormFactor = "TSOP"
Case 10
strFormFactor = "PGA"
Case 11
strFormFactor = "RIMM"
Case 12
strFormFactor = "SODIMM"
Case 13
strFormFactor = "SRIMM"
Case 14
strFormFactor = "SMD"
Case 15
strFormFactor = "SSMP"
Case 16
strFormFactor = "QFP"
Case 17
strFormFactor = "TQFP"
Case 18
strFormFactor = "SOIC"
Case 19
strFormFactor = "LCC"
Case 20
strFormFactor = "PLCC"
Case 21
strFormFactor = "BGA"
Case 22
strFormFactor = "FPBGA"
Case 23
strFormFactor = "LGA"
case Else
strFormFactor = "Unknown"
End Select
GetMemoryFormFactor=strFormFactor
End Function
' ***************************************
' Convert date string to a more readable format
' ***************************************
Function FormatDate(ByVal strValue)
Dim strDate
If ISNULL(strValue) Or strValue = "" Then
strDate = ""
Else
strDate = Left(strValue,4) & "-" & MID(strValue,5,2) & "-" & MID(strValue,7,2) & " " & _
Mid(strValue,9,2) & ":" & Mid(strValue,11,2)
End If
FormatDate = strDate
End Function
' ***************************************
' Clear existing report data
' ***************************************
Sub Reset
ProcessAutoRefresh.Value="0"
window.clearInterval(intProcessTimerID)
Main.Style.Display = "none"
Tools.Style.Display = "none"
LogicalDisk.InnerHTML=""
PhysicalDisk.InnerHTML=""
Processor.InnerHTML =""
Memory.InnerHTML = ""
OS.InnerHTML =""
Shares.InnerHTML=""
DisplayError.InnerHTML=""
End Sub
' ***************************************
' Main procedure used to generate report
' Calls other procedures that generate the HTML for each section
' ***************************************
Sub GenerateReport
Reset()
strComputer = txtComputer.Value
if strComputer = "" Then
Dim objNetwork
set objNetwork = createobject("wscript.network")
strComputer = objNetwork.ComputerName
txtComputer.Value = strComputer
End If
If Right(LCase(txtComputer.Value), 4) <> ".txt" Then
CurrentComputer.InnerHTML = strComputer
If Ping(CurrentComputer.InnerHTML) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Exit Sub
End If
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
ProcessesData.InnerHTML = RunningProcesses_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
PhysicalDisk.InnerHTML = PhysicalDisk_HTML
Processor.InnerHTML = Processor_HTML
Memory.InnerHTML = Memory_HTML
OS.InnerHTML = OS_HTML
Shares.InnerHTML = Shares_HTML
Else
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
End If
Else
Dim objFSO, objFile
MsgBox "You have selected a text file. Results will not be shown to screen," & VbCrLf & _
"but each machine will have a CSV file generated."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(txtComputer.Value, intForReading, False)
While Not objFile.AtEndOfStream
strComputer = objFile.ReadLine
CurrentComputer.InnerHTML = strComputer
If Ping(CurrentComputer.InnerHTML) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Else
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
ProcessesData.InnerHTML = RunningProcesses_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
PhysicalDisk.InnerHTML = PhysicalDisk_HTML
Processor.InnerHTML = Processor_HTML
Memory.InnerHTML = Memory_HTML
OS.InnerHTML = OS_HTML
Shares.InnerHTML = Shares_HTML
OutputToExcel
Reset()
End If
Else
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
End If
Wend
objFile.Close
MsgBox "Finished inspecting computers from text file."
End If
End Sub
' ***************************************
' Gets a list of running processes and returns HTML for the "Running Processes" section
' ***************************************
Function RunningProcesses_HTML
Dim row,strHTML,strFilter
Dim DataList,colItems,objItem,strUser,strDomain
Dim strWMIQuery
strFilter = txtProcessFilter.Value
' Recordset is used to sort data from WMI
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Name", adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "WorkingSet", adInteger, adFldIsNullable
DataList.Fields.Append "CreationDate",adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "Description",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "ProcessID",adInteger, adFldIsNullable
DataList.Fields.Append "CPUTime",adInteger, adFldIsNullable
DataList.Fields.Append "Caption",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Owner",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Path",adVarChar,MaxCharacters, adFldIsNullable
DataList.Open
strWMIQuery = "Select * From Win32_Process"
' Add filter if required
if strFilter <> "" then
strWMIQuery = strWMIQuery & " WHERE Name LIKE '%" & strFilter & "%'"
end if
Set colItems = objWMIService.ExecQuery(strWMIQuery)
' Load WMI data into recordset
For Each objItem in colItems
Dim strOwner
DataList.AddNew
on error resume next
DataList("Name") = HTMLEncode(objItem.Name)
DataList("WorkingSet") = objItem.WorkingSetSize
DataList("CreationDate") = objItem.CreationDate
DataList("Description") = HTMLEncode(objItem.Description)
DataList("ProcessID") = objItem.ProcessID
DataList("Caption") = objItem.Caption
DataList("CPUTime") = (CSng(objItem.KernelModeTime) + CSng(objItem.UserModeTime)) / 10000000
If objItem.GetOwner (strUser, strDomain) = 0 Then
strOwner = strDomain & "\" & strUser
End If
DataList("Owner") = strOwner
on error goto 0
DataList.Update
Next
' Sort recordset
DataList.Sort = ProcessSort.InnerHTML
' Check if recordset is not empty
If DataList.BOF = FALSE then
DataList.MoveFirst
' Generate HTML table report with running processes
strHTML = strHTML & "<table class=""Table"">"
strHTML = strHTML & "<tr><th><span onclick=""SortProcesses('Name')"" class=""HeaderLink"">Name</span></th>" & _
"<th><span onclick=""SortProcesses('CreationDate')"" class=""HeaderLink"">Creation Date</span></th>" & _
"<th><span onclick=""SortProcesses('Owner')"" class=""HeaderLink"">Owner</span></th>" & _
"<th><span onclick=""SortProcesses('WorkingSet')"" class=""HeaderLink"">Working Set</span></th>" & _
"<th><span onclick=""SortProcesses('CPUTime')"" class=""HeaderLink"">Total CPU Time(s)</span></th>" & _
"<th> </th></tr>"
Do Until DataList.EOF
Dim strCaption,strCreationDate,strPath,intProcessID,strDescription
Dim strWorkingSet
strHTML = strHTML & "<tr>" & _
"<td><div title=""" & DataList("Path") & """>" & DataList("Name") & "</div></td>" & _
"<td>" & FormatDate(DataList("CreationDate")) & "</td>" & _
"<td>" & DataList("Owner") & "</td>" & _
"<td>" & ConvertToDiskUnit(DataList("WorkingSet")) & "</td>" & _
"<td>" & DataList("CPUTime") & "</td>" & _
"<td><span onclick=""KillProcess '" & DataList("ProcessID") & "','" & DataList("Name") & "'"" class=""Link"">Kill Process</span></td>" & _
"</tr>"
DataList.MoveNext
Loop
strHTML = strHTML & "</table>"
end if
DataList.Close
strHTML = strHTML & "<br>Last Refresh:" & Now()
RunningProcesses_HTML=strHTML
End Function
' ***************************************
' Gets a list of shared folders and shared printers and
' returns HTML for the "Shares" section
' ***************************************
Function Shares_HTML
Dim objItem, colItems
Dim strHTML
' Query to return shared folders
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483648 OR Type = 0")
strHTML = strHTML & "<table><tr><td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Folder Shares</th></tr>"
For Each objItem In colItems
Dim strShare
strShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strShare & "')"">" & strShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapDrive('\\" & strComputer & "\" & strShare & "')"" value=""Map Drive""></input></td></tr>"
Next
strHTML = strHTML & "</table></td>"
' Query to return shared printers
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483649 OR Type = 1")
strHTML = strHTML & "<td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Printer Shares</th></tr>"
For Each objItem In colItems
Dim strPrinterShare
strPrinterShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strPrinterShare & "')"">" & strPrinterShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapPrinter('\\" & strComputer & "\" & strPrinterShare & "')"" value=""Connect Printer""></input></td></tr>"
Next
strHTML = strHTML & "</table></td></table>"
Shares_HTML = strHTML
End Function
' ***************************************
' Gets computer system info to be included in the "OS / General" section
' ***************************************
Sub GetComputerSystemInfo(BYRef strobjSMBIOS,ByRef strDomain,ByRef strDomainRole, _
ByRef strManufacturer,ByRef strModel,ByRef strUserName)
Dim objItem, colItems
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem In colItems
On Error Resume Next
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
strDomain = HTMLEncode(objItem.Domain)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strModel = HTMLEncode(objItem.Model)
strUserName = HTMLEncode(objItem.UserName)
On Error GoTo 0
If strUserName = "" Then
strUserName = "No one logged in"
End If
Select Case objItem.DomainRole
Case 0
strDomainRole="Standalone Workstation"
Case 1
strDomainRole="Member Workstation"
Case 2
strDomainRole="Standalone Server"
Case 3
strDomainRole="Member Server"
Case 4
strDomainRole="Backup Domain Controller"
Case 5
strDomainRole="Primary Domain Controller"
Case Else
strDomainRole = "Unknown (" & strDomainRole & ")"
End Select
Next
End Sub
' ***************************************
' Returns a HTML report for the "Operating System/General" section
' ***************************************
Function OS_HTML()
Dim objItem, colItems
Dim strHTML
Dim strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
GetComputerSystemInfo strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
Dim strServiceTag
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
For Each objItem In colItems
strServiceTag = objItem.SerialNumber
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
strHTML = "<h3>Current User: " & strUserName & "</h3>"
For Each objItem In colItems
Dim strComputerRole
Dim strCaption,strBuildNumber,strInstallDate,strBootDate
Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
Dim intFreePhysicalMemory,intTotalVirtualMemorySize,intFreeVirtualMemory
On Error Resume Next
strCaption = HTMLEncode(objItem.Caption)
strBuildNumber = HTMLEncode(objItem.BuildNumber)
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
intServicePackMajor = objItem.ServicePackMajorVersion
intServicePackMinor = objItem.ServicePackMinorVersion
intTotalVisibleMemorySize = objItem.TotalVisibleMemorySize
intFreePhysicalMemory = objItem.FreePhysicalMemory
intFreeVirtualMemory = objItem.FreeVirtualMemory
intTotalVirtualMemorySize = objItem.TotalVirtualMemorySize
strInstallDate = FormatDate(objItem.InstallDate)
strBootDate = FormatDate(objItem.LastBootUpTime)
On Error GoTo 0
strHTML = strHTML & "<table class=""Table"">" & _
"<tr>" & _
"<th>Operating System:</th><td>" & strCaption & "</td>" & _
"<th>Build Number:</th><td>" & strBuildNumber & "</td>" & _
"</tr><tr>" & _
"<th>Service Pack:</th><td>" & intServicePackMajor & "." & intServicePackMinor & "</td>" & _
"<th>Role:</th><td>" & strDomainRole & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strobjSMBIOS & "</td>" & _
"<th>Domain:</th><td>" & strDomain & "</td>" & _
"</tr><tr>" & _
"<th>Manufacturer:</th><td>" & strManufacturer & "</td>" & _
"<th>Model:</th><td>" & strModel & "</td>" & _
"</tr><tr>" & _
"<th>Total Physical Memory:</th><td>" & intTotalVisibleMemorySize & "KB</td>" & _
"<th>Free Physical Memory:</th><td>" & intFreePhysicalMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Total Virtual Memory:</th><td>" & intTotalVirtualMemorySize & "KB</td>" & _
"<th>Free Virtual Memory:</th><td>" & intFreeVirtualMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Install Date:</th><td>" & strInstallDate & "</td>" & _
"<th>Last BootUp Time:</th><td>" & strBootDate & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strServiceTag & "</td>" & _
"<th></th><td></td>" & _
"</tr>" & _
"</table>"
Exit For
Next
OS_HTML = strHTML
End Function
' ***************************************
' Get the number of memory slots and memory arrays
' for the memory section
' ***************************************
Function GetMemoryArrayInfo(ByRef intSlots,ByRef intArrays)
Dim objItem, colItems
intSlots = 0
intArrays = 0
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray WHERE Use=3")
For Each objItem In colItems
intSlots = intSlots + objItem.MemoryDevices
intArrays = intArrays + 1
Next
End Function
' ***************************************
' Returns a HTML report for the "Memory" section
' ***************************************
Function Memory_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>BankLabel</th>" & _
"<th>Capacity</th>" & _
"<th>Caption</th>" & _
"<th>Description</th>" & _
"<th>DeviceLocator </th>" & _
"<th>Manufacturer</th>" & _
"<th>Memory Type</th>" & _
"<th>Form Factor</th>" & _
"<th>Model</th>" & _
"<th>Speed</th>" & _
"</tr>"
For Each objItem In colItems
Dim strBankLabel,strCaption,strDescription,strDeviceLocator
Dim strManufacturer,strMemoryType,strFormFactor,strModel
Dim strCapacity,intSpeed
On Error Resume Next
strBankLabel = HTMLEncode(objItem.BankLabel)
strCapacity = ConvertToDiskUnit(objItem.Capacity)
strCaption = HTMLEncode(objItem.Caption)
strDescription = HTMLEncode(objItem.Description)
strDeviceLocator = HTMLEncode(objItem.DeviceLocator)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strMemoryType = GetMemoryType(objItem.MemoryType)
strFormFactor = GetMemoryFormFactor(objItem.FormFactor)
strModel = HTMLEncode(objItem.Model)
intSpeed = objItem.Speed
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strBankLabel & "</td>" & _
"<td>" & strCapacity & "</td>" & _
"<td>" & strCaption & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & strDeviceLocator & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strMemoryType & "</td>" & _
"<td>" & strFormFactor & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & intSpeed & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Dim intSlots,intArrays
GetMemoryArrayInfo intSlots,intArrays
strHTML = strHTML & "Total Memory Slots:" & intSlots & ", Memory Arrays:" & intArrays
Memory_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Processor" section
' ***************************************
Function Processor_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>Name</th>" & _
"<th>Manufacturer</th>" & _
"<th>Description</th>" & _
"<th>Address Width</th>" & _
"<th>Current Clock Speed</th>" & _
"<th>Data Width</th>" & _
"<th>Device ID</th>" & _
"<th>Ext Clock</th>" & _
"<th>L2 Cache</th>" & _
"<th>Max Clock Speed</th>" & _
"<th>#Cores</th>" & _
"<th>#Logical Processors</th>" & _
"</tr>"
For Each objItem in colItems
Dim strName,strManufacturer,strDescription,strDeviceID
Dim intAddressWidth,intCurrentClockSpeed,intDataWidth,intExtClock
Dim intL2CacheSize,intMaxClockSpeed, intNumberOfCores,intNumberOfLogicalProcessors
On Error Resume Next
strName = HTMLEncode(objItem.Name)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strDescription = HTMLEncode(objItem.Description)
intAddressWidth = objItem.AddressWidth
intCurrentClockSpeed = objItem.CurrentClockSpeed
intDataWidth = objItem.DataWidth
strDeviceID = HTMLEncode(objItem.DeviceID)
intExtClock = objItem.ExtClock
intL2CacheSize = objItem.L2CacheSize
intMaxClockSpeed = objItem.MaxClockSpeed
intNumberOfCores = objItem.NumberOfCores
intNumberOfLogicalProcessors= objItem.NumberOfLogicalProcessors
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strName & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & intAddressWidth & "</td>" & _
"<td>" & intCurrentClockSpeed & "</td>" & _
"<td>" & intDataWidth & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & intExtClock & "</td>" & _
"<td>" & intL2CacheSize & "</td>" & _
"<td>" & intMaxClockSpeed & "</td>" & _
"<td>" & intNumberOfCores & "</td>" & _
"<td>" & intNumberOfLogicalProcessors & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Processor_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Physical Disk" section
' ***************************************
Function PhysicalDisk_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
strHTML = "<table class=""Table""><tr><th>Caption</th><th>Manufacturer</th>" & _
"<th>Model</th><th>Size</th><th>Serial</th><th>Media Type</th><th>#Partitions</th><th>DeviceID</th><th>Firmware</th><th>Interface</th></tr>"
For Each objItem in colItems
Dim intSize,intPartitions
Dim strSize,strCaption,strManufacturer,strModel,strMediaType
Dim strDeviceID,strFirmwareRevision,strInterfaceType, strSerialNumber
intSize = objItem.Size
If IsNumeric(intSize) = False Then
intSize = 0
End If
On Error Resume Next
strCaption= HTMLEncode(objItem.Caption)
strSize = ConvertToDiskUnit(intSize)
strSerialNumber = HTMLEncode(objItem.SerialNumber)
strMediaType = HTMLEncode(objItem.MediaType)
intPartitions = HTMLEncode(objItem.Partitions)
strDeviceID = HTMLEncode(objItem.DeviceID)
strFirmwareRevision = HTMLEncode(objItem.FirmwareRevision)
strInterfaceType = HTMLEncode(objItem.InterfaceType)
strModel = HTMLEncode(objItem.Model)
strManufacturer = HTMLEncode(objItem.Manufacturer)
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strCaption & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & strSize & "</td>" & _
"<td>" & strSerialNumber & "</td>" & _
"<td>" & strMediaType & "</td>" & _
"<td>" & intPartitions & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & strFirmwareRevision & "</td>" & _
"<td>" & strInterfaceType & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
PhysicalDisk_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Logical Disk" section
' ***************************************
Function LogicalDisk_HTML()
Dim objItem, colItems
Dim strDriveType, strDiskSize, strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType = 3")
strHTML = "<table class=""Table""><tr><th>Drive</th><th>Name</th><th>File System</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>"
For Each objItem in colItems
Dim pctFreeSpace,strFreeSpace,strusedSpace,strName,strFileSystem,strVolumeName
Dim intFreeSpace, intSize
On Error Resume Next
intFreeSpace = objItem.FreeSpace
intSize = objItem.Size
If ISNUMERIC(intFreeSpace) = False Then
intFreeSpace=0
End If
If IsNumeric(intSize) = False Then
intSize = 0
End If
If objItem.FreeSpace > 0 Then
pctFreeSpace = round(((intFreeSpace / intSize) * 100),0)
Else
pctFreeSpace=0
End If
strDiskSize = ConvertToDiskUnit(intSize)
strFreeSpace = ConvertToDiskUnit(intFreeSpace)
strUsedSpace = ConvertToDiskUnit(intSize-intFreeSpace)
strName = HTMLEncode(objItem.Name)
strVolumeName = HTMLEncode(objItem.VolumeName)
strFileSystem = HTMLEncode(objItem.FileSystem)
On Error GoTo 0
dim strChart
strChart = "<div width=100%;""><span style=""padding:0px;margin:0px;width=" & 100-pctFreeSpace & _
"%;background-color:blue;""> </span><span style=""padding:0px;margin:0px;width=" & pctFreeSpace & _
"%;background-color:#FF00FF;""> </span></div>"
strHTML = strHTML & "<tr><td>" & strName & "</td><td>" & _
strVolumeName & "</td><td>" & strFileSystem & "</td><td>" & _
strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _
strFreeSpace & "</td><td>" & pctFreeSpace & "%</td></tr>" & _
"<tr><td colspan=""7"">" & strChart & "</td></tr>"
Next
strHTML = strHTML + "</table></br>"
LogicalDisk_HTML = strHTML
End Function
Sub OutputToExcel
Dim strHTAPath, strReportPath, objFSO, objFile, objShell, strOutputFile
If Mid(document.location, 6, 3) = "///" Then
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
Else
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
End If
strReportPath = Left(strHTAPath, InStrRev(strHTAPath, "\") - 1) & "\Reports"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strReportPath) = False Then objFSO.CreateFolder strReportPath
strOutputFile = strReportPath & "\" & CurrentComputer.InnerHTML & "_Report.xls"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutputFile, True)
objFile.WriteLine OS.InnerHTML
objFile.WriteLine ProcessesData.InnerHTML
objFile.WriteLine Memory.InnerHTML
objFile.WriteLine LogicalDisk.InnerHTML
objFile.WriteLine PhysicalDisk.InnerHTML
objFile.WriteLine Processor.InnerHTML
objFile.WriteLine Shares.InnerHTML
objFile.Close
Set objShell = CreateObject("WScript.Shell")
objShell.Run "excel """ & strOutputFile & """", 1, False
End Sub
Sub Browse_For_File()
Dim objDialog, intResult
Const intForReading = 1
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "."
intResult = objDialog.ShowOpen
If intResult = 0 Then
Exit Sub
End If
txtComputer.Value = objDialog.FileName
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
</script>
<script type="text/javascript">
/* Toggle expand/collapse state for specified section */
function toggleDisplay(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
/* Toggle expand/collapse state for all sections */
function toggleAll() {
var el = document.getElementById("OS");
var display = ''
if ( el.style.display != 'none' ) {
display = 'none';
}
el.style.display = display;
el = document.getElementById("Memory");
el.style.display = display;
el = document.getElementById("LogicalDisk");
el.style.display = display;
el = document.getElementById("PhysicalDisk");
el.style.display = display;
el = document.getElementById("Processor");
el.style.display = display;
el = document.getElementById("Shares");
el.style.display = display;
el = document.getElementById("Processes");
el.style.display = display;
}
</script>
<h1>Computer Info Tool</h1>
<div id="Header" style="padding-bottom:0px;margin-bottom:0px;">
<span style="font-weight:bold;">Connect To Computer:<span><input id="txtComputer"></input>
<input type='button' value='Browse...' name='btnBrowse' onClick='vbs:Browse_For_File()'>
<input class="Button" style="font-weight:bold;" onClick="GenerateReport()" type="submit" value="Generate Report">
<input class="Button" style="font-weight:bold;" onClick="OutputToExcel()" type="button" value="Output To Excel">
</input>
</div>
<div id="Tools" style="display:none;margin-bottom:0px;">
<span class="Link" onClick="RebootComputer">Reboot Computer</span> |
<span class="Link" onClick="ShutDownComputer">Shutdown Computer</span>
</div>
<div id="Main" style="display:none;">
<div id="CurrentComputer" style="display:none"></div>
<div style="text-align:right;">
<span class="Link" style="font-weight:bold;" onclick="javascript:toggleAll();">Expand/Collapse All</span>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('OS');" class="InfoSectionHeader">Operating System / General</div>
<div id="OS" class="InfoSectionBody" ></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processes');" class="InfoSectionHeader">Running Processes</div>
<div id="Processes" class="InfoSectionBody">
Auto Refresh Interval:<select id="ProcessAutoRefresh" onchange="SetProcessAutoRefresh">
<option value ="0">None</option>
<option value ="1000">1 second</option>
<option value ="2000">2 seconds</option>
<option value ="3000">3 seconds</option>
<option value ="5000">5 seconds</option>
<option value ="10000">10 seconds</option>
<option value ="20000">20 seconds</option>
<option value ="30000">30 seconds</option>
<option value ="60000">1 minute</option>
</select>
Filter (Optional):<input id="txtProcessFilter"></input>
<br/><br/>
<span onclick="RefreshProcesses()" style=""font-weight:bold"" class="Link">Refresh Processes</span>
<br/><br/>
<div id="ProcessesData"></div>
</div>
<div id="ProcessSort" style="display:none">Name</div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Memory');" class="InfoSectionHeader">Memory</div>
<div id="Memory" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('LogicalDisk');" class="InfoSectionHeader">Logical Disk</div>
<div id="LogicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('PhysicalDisk');" class="InfoSectionHeader">Physical Disk</div>
<div id="PhysicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processor');" class="InfoSectionHeader">Processor</div>
<div id="Processor" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Shares');" class="InfoSectionHeader">Shares</div>
<div id="Shares" class="InfoSectionBody"></div>
</div>
</div>
<div id="DisplayError"></div>
<div id="Footer">
<hr/>
<div style="float:left;">Version 1.0</div>
<div style="float:right;">By Dhiraj Mutha<br />
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
ASKER
Thanks for the reply. I will have a check and update you.
ASKER
Hi Rob. This is working fine. Except one thing... the excel sheet... that is also working but its like a screenshot of the details in excel. I want the excel to be something like this.
Sr. No. | Hostname | Logged in User | IP Address | MAC Address | Service Tag | RAM | HDD Size | Free space on C |
Is it possible to get something like this? Rest all is fine.
Sr. No. | Hostname | Logged in User | IP Address | MAC Address | Service Tag | RAM | HDD Size | Free space on C |
Is it possible to get something like this? Rest all is fine.
Some of the information is not gathered by this script. Try this though for the information that is coded into it.
Regards,
Rob.
Regards,
Rob.
<html >
<head>
<title>Computer Info Tool - By Dhiraj Mutha</title>
<hta:application applicationname="Prem's Computer Info Tool" scroll="yes" singleinstance="no"
windowstate="normal">
<style type="text/css">
body {
margin:0px;
background-color:#CBCBCB; /*#F6F6F6;*/
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#595959;
}
h1 {
font-size:24px;
font-weight:bold;
color:#FFFFFF;
background-color:#2886C8;
text-align:center;
border-style:solid;
border-width:thin;
border-color:#C9E0F1;
padding:5px;
}
h2 {
font-size:18px;
font-weight:bold;
}
h3 {
font-size:16px;
font-weight:bold;
}
a {
color:#2886C8;
}
#Main {
margin-left:20px;
margin-right:20px;
}
#DisplayError {
color:red;
margin-left:20px;
margin-right:20px;
}
#Footer {
margin:20px;
font-weight:bold;
font-size:16px;
}
#Header {
margin-left:20px;
margin-right:20px;
text-align:center;
}
#Tools {
text-align:center;
border-color:#595959;
border-style:dotted;
border-width:1px;
background-color:#F6F6F6;
margin-left:20px;
margin-right:20px;
margin-top:20px;
padding:5px;
}
.Button {
color: #444444;
}
.InfoSectionHeader {
font-size:20px;
font-weight:bold;
background-color:#595959;
color:#FFFFFF;
text-align:center;
padding:5px;
margin-top:0px;
cursor:pointer;
}
.InfoSection {
text-align:center;
margin-bottom:10px;
background-color:#FFFFFF;
border-color:#595959;
border-style:dotted;
border-width:1px;
}
.InfoSectionBody {
padding:10px;
}
.Link {
text-decoration: underline;
cursor:pointer;
color:#2886C8;
}
.HeaderLink {
text-decoration: underline;
cursor:pointer;
color:#FFFFFF;
}
.Table {
/*width:90%;*/
border: 2px solid;
border-collapse: collapse;
border-color: #696969;
}
.Table th {
border: 1px dotted #111111;
border-color: #787878;
color: #FFFFFF;
font: bold 12pt arial, sans-serif;
background-color: #595959; /* #787878;*/
text-align: left;
padding=3px;
}
.Table td {
border: 1px dotted #111111;
border-color: #787878;
font: bold 10pt arial, sans-serif;
color: #787878;
padding=5px;
}
</style>
</head>
<body>
<script language="VBScript">
Option Explicit
Const bytesToMB = 1048576
Const bytesToGB = 1073741824
Const bytesToTB = 1099511627776
Const adVarChar = 200
Const adDate = 7
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adInteger = 3
Const adBigInt = 20
Const blnConfirmKillProcess = true
Const intForReading = 1
Private objWMIService
Private strComputer
private intProcessTimerID
Private strResults
' ***************************************
' Get Service Tag
' ***************************************
Sub ServiceTag
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Next
End Sub
' ***************************************
' Open Windows explorer to a given path
' Used when clicking a link in the "Shares" section
' ***************************************
Sub OpenUNC(ByVal strPath)
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
strPath = "explorer.exe /e," & strPath
objShell.Run strPath
End Sub
' ***************************************
' Reboot computer
' ***************************************
sub RebootComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to reboot '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Reboot") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Reboot()
Next
msgbox "Computer '" & strComputer & "' has been rebooted",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Shutdown computer
' ***************************************
sub ShutDownComputer()
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if MsgBox("Are you sure you want to shutdown '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Shutdown") = vbYes then
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
objItem.Win32Shutdown(1)
Next
msgbox "Computer '" & strComputer & "' has been shutdown",vbOKOnly+vbInformation
end if
end sub
' ***************************************
' Kills the specified process
' Called when "Kill Process" link is clicked in the Running Processes section
' ***************************************
Sub KillProcess(ByVal intProcessID, ByVal strName)
Dim objItem, colItems
strComputer = CurrentComputer.InnerHTML
if blnConfirmKillProcess = True then
if msgbox("Are you sure you want to kill the '" & strName & "' process on '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Kill Process") = vbNo then
exit sub
end if
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = '" & _
intProcessID & "' AND Name = '" & strName & "'")
For Each objItem In colItems
objItem.Terminate()
Next
RefreshProcesses
End Sub
' ***************************************
' Refreshes list of processes in the "Running Processes" section
' ***************************************
Sub RefreshProcesses
strComputer = CurrentComputer.InnerHTML
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
ProcessesData.InnerHTML = RunningProcesses_HTML
End Sub
' ***************************************
' Enables/Disables the auto refresh feature in the "Running Processes" section
' ***************************************
sub SetProcessAutoRefresh
dim intInterval
' Get the refresh interval
intInterval = ProcessAutoRefresh.Value
' Remove the current auto-refresh
window.clearInterval(intProcessTimerID)
' Add an auto-refresh if specified
if intInterval > 0 then
intProcessTimerID = window.setInterval("RefreshProcesses", intInterval)
end if
end sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' and refreshes the processes list with the new sort value
' ***************************************
Sub SortProcesses(byval strSort)
' If sort link is clicked twice on the same column, sort descending
if ProcessSort.InnerHTML = strSort then
ProcessSort.InnerHTML = strSort & " DESC"
else
ProcessSort.InnerHTML = strSort
end if
RefreshProcesses()
End Sub
' ***************************************
' Map as network drive on this computer to a share on another computer
' Called from the "Shares" section. User is prompted for a drive letter
' ***************************************
Sub MapDrive(ByVal strPath)
Dim objNetwork
Dim strDrive
strDrive = InputBox("Enter drive letter:","Drive Letter","Z")
If strDrive <> "" Then
strDrive = Left(strDrive,1) & ":"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive,strPath
End If
End Sub
' ***************************************
' Stores the sort value for "Running Processes" section in a hidden div
' ***************************************
Sub MapPrinter(ByVal strPath)
Dim objNetwork
Set objNetwork = createobject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection(strPath)
If MsgBox("Make Printer Default?",vbYesNo+vbQuestion,"Default Printer") = vbYes Then
objNetwork.SetDefaultPrinter strPath
End If
End Sub
' ***************************************
' Replace special HTML characters
' ***************************************
Function HTMLEncode(strValue)
HTMLEncode= REplace(Replace(strValue,"<","<"),">",">")
End Function
' ***************************************
' Convert Bytes to MB,GB or TB as appropriate
' ***************************************
function ConvertToDiskUnit(ByVal value)
IF (value/bytesToTb) > 1 Then
ConvertToDiskUnit = round(value / bytesToTB,1) & " TB"
ELSEIF (value/bytesToGb) > 1 Then
ConvertToDiskUnit = round(value / bytesToGB,1) & " GB"
Else
ConvertToDiskUnit = round(value / bytesToMB,1) & " MB"
END If
end Function
' ***************************************
' Convert integer value to string
' ***************************************
Function GetMemoryType(ByVal intType)
Dim strType
Select case intType
Case 0
strType = "Unknown"
Case 1
strType = "Other"
Case 2
strType = "DRAM"
Case 3
strType = "Synchronous DRAM"
Case 4
strType = "Cache DRAM"
Case 5
strType = "EDO"
Case 6
strType = "EDRAM"
Case 7
strType = "VRAM"
Case 8
strType = "SRAM"
Case 9
strType = "RAM"
Case 10
strType = "ROM"
Case 11
strType = " Flash"
Case 12
strType = "EEPROM"
Case 13
strType = "FEPROM"
Case 14
strType = " EPROM"
Case 15
strType = " CDRAM"
Case 16
strType = "3DRAM"
Case 17
strType = " SDRAM"
Case 18
strType = " SGRAM"
Case 19
strType = " RDRAM"
Case 20
strType = " DDR"
Case 21
strType = " DDR-2"
Case Else
strType = "Unknown"
End Select
GetMemoryType=strType
End Function
' ***************************************
' Convert Integer value to string
' ***************************************
Function GetMemoryFormFactor(ByVal intFormFactor)
Dim strFormFactor
Select Case intFormFactor
Case 0
strFormFactor = "Unknown"
Case 1
strFormFactor = "Other"
Case 2
strFormFactor = "SIP"
Case 3
strFormFactor = "DIP"
Case 4
strFormFactor = "ZIP"
Case 5
strFormFactor = "SOJ"
Case 6
strFormFactor = "Proprietary"
Case 7
strFormFactor = "SIMM"
Case 8
strFormFactor = "DIMM"
Case 9
strFormFactor = "TSOP"
Case 10
strFormFactor = "PGA"
Case 11
strFormFactor = "RIMM"
Case 12
strFormFactor = "SODIMM"
Case 13
strFormFactor = "SRIMM"
Case 14
strFormFactor = "SMD"
Case 15
strFormFactor = "SSMP"
Case 16
strFormFactor = "QFP"
Case 17
strFormFactor = "TQFP"
Case 18
strFormFactor = "SOIC"
Case 19
strFormFactor = "LCC"
Case 20
strFormFactor = "PLCC"
Case 21
strFormFactor = "BGA"
Case 22
strFormFactor = "FPBGA"
Case 23
strFormFactor = "LGA"
case Else
strFormFactor = "Unknown"
End Select
GetMemoryFormFactor=strFormFactor
End Function
' ***************************************
' Convert date string to a more readable format
' ***************************************
Function FormatDate(ByVal strValue)
Dim strDate
If ISNULL(strValue) Or strValue = "" Then
strDate = ""
Else
strDate = Left(strValue,4) & "-" & MID(strValue,5,2) & "-" & MID(strValue,7,2) & " " & _
Mid(strValue,9,2) & ":" & Mid(strValue,11,2)
End If
FormatDate = strDate
End Function
' ***************************************
' Clear existing report data
' ***************************************
Sub Reset
ProcessAutoRefresh.Value="0"
window.clearInterval(intProcessTimerID)
Main.Style.Display = "none"
Tools.Style.Display = "none"
LogicalDisk.InnerHTML=""
PhysicalDisk.InnerHTML=""
Processor.InnerHTML =""
Memory.InnerHTML = ""
OS.InnerHTML =""
Shares.InnerHTML=""
DisplayError.InnerHTML=""
End Sub
' ***************************************
' Main procedure used to generate report
' Calls other procedures that generate the HTML for each section
' ***************************************
Sub GenerateReport
Reset()
strComputer = txtComputer.Value
if strComputer = "" Then
Dim objNetwork
set objNetwork = createobject("wscript.network")
strComputer = objNetwork.ComputerName
txtComputer.Value = strComputer
End If
If Right(LCase(txtComputer.Value), 4) <> ".txt" Then
CurrentComputer.InnerHTML = strComputer
If Ping(CurrentComputer.InnerHTML) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Exit Sub
End If
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
ProcessesData.InnerHTML = RunningProcesses_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
PhysicalDisk.InnerHTML = PhysicalDisk_HTML
Processor.InnerHTML = Processor_HTML
Memory.InnerHTML = Memory_HTML
OS.InnerHTML = OS_HTML
Shares.InnerHTML = Shares_HTML
Else
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
End If
Else
Dim objFSO, objFile
MsgBox "You have selected a text file. Results will not be shown to screen," & VbCrLf & _
"but each machine will have a CSV file generated."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(txtComputer.Value, intForReading, False)
strResults = """Sr. No."",""Hostname"",""Logged in User"",""Service Tag"",""RAM"",""HDD Size"",""Free space on C"""
While Not objFile.AtEndOfStream
strComputer = objFile.ReadLine
CurrentComputer.InnerHTML = strComputer
If Ping(CurrentComputer.InnerHTML) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
On Error GoTo 0
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
Err.Clear
Else
On Error GoTo 0
Main.Style.Display = ""
Tools.Style.Display = ""
OS.InnerHTML = OS_HTML
Memory.InnerHTML = Memory_HTML
LogicalDisk.InnerHTML = LogicalDisk_HTML
'OutputToExcel
Reset()
End If
Else
DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
End If
Wend
objFile.Close
Dim strHTAPath, strReportPath, objReport, objShell
If Mid(document.location, 6, 3) = "///" Then
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
Else
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
End If
strReportPath = Left(strHTAPath, InStrRev(strHTAPath, "\") - 1) & "\ComputerReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.CreateTextFile(strReportPath, True)
objReport.Write strResults
objReport.Close
Set objReport = Nothing
Set objShell = CreateObject("WScript.Shell")
objShell.Run "excel """ & strReportPath & """", 1, False
MsgBox "Finished inspecting computers from text file."
End If
End Sub
' ***************************************
' Gets a list of running processes and returns HTML for the "Running Processes" section
' ***************************************
Function RunningProcesses_HTML
Dim row,strHTML,strFilter
Dim DataList,colItems,objItem,strUser,strDomain
Dim strWMIQuery
strFilter = txtProcessFilter.Value
' Recordset is used to sort data from WMI
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Name", adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "WorkingSet", adInteger, adFldIsNullable
DataList.Fields.Append "CreationDate",adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "Description",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "ProcessID",adInteger, adFldIsNullable
DataList.Fields.Append "CPUTime",adInteger, adFldIsNullable
DataList.Fields.Append "Caption",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Owner",adVarChar,MaxCharacters, adFldIsNullable
DataList.Fields.Append "Path",adVarChar,MaxCharacters, adFldIsNullable
DataList.Open
strWMIQuery = "Select * From Win32_Process"
' Add filter if required
if strFilter <> "" then
strWMIQuery = strWMIQuery & " WHERE Name LIKE '%" & strFilter & "%'"
end if
Set colItems = objWMIService.ExecQuery(strWMIQuery)
' Load WMI data into recordset
For Each objItem in colItems
Dim strOwner
DataList.AddNew
on error resume next
DataList("Name") = HTMLEncode(objItem.Name)
DataList("WorkingSet") = objItem.WorkingSetSize
DataList("CreationDate") = objItem.CreationDate
DataList("Description") = HTMLEncode(objItem.Description)
DataList("ProcessID") = objItem.ProcessID
DataList("Caption") = objItem.Caption
DataList("CPUTime") = (CSng(objItem.KernelModeTime) + CSng(objItem.UserModeTime)) / 10000000
If objItem.GetOwner (strUser, strDomain) = 0 Then
strOwner = strDomain & "\" & strUser
End If
DataList("Owner") = strOwner
on error goto 0
DataList.Update
Next
' Sort recordset
DataList.Sort = ProcessSort.InnerHTML
' Check if recordset is not empty
If DataList.BOF = FALSE then
DataList.MoveFirst
' Generate HTML table report with running processes
strHTML = strHTML & "<table class=""Table"">"
strHTML = strHTML & "<tr><th><span onclick=""SortProcesses('Name')"" class=""HeaderLink"">Name</span></th>" & _
"<th><span onclick=""SortProcesses('CreationDate')"" class=""HeaderLink"">Creation Date</span></th>" & _
"<th><span onclick=""SortProcesses('Owner')"" class=""HeaderLink"">Owner</span></th>" & _
"<th><span onclick=""SortProcesses('WorkingSet')"" class=""HeaderLink"">Working Set</span></th>" & _
"<th><span onclick=""SortProcesses('CPUTime')"" class=""HeaderLink"">Total CPU Time(s)</span></th>" & _
"<th> </th></tr>"
Do Until DataList.EOF
Dim strCaption,strCreationDate,strPath,intProcessID,strDescription
Dim strWorkingSet
strHTML = strHTML & "<tr>" & _
"<td><div title=""" & DataList("Path") & """>" & DataList("Name") & "</div></td>" & _
"<td>" & FormatDate(DataList("CreationDate")) & "</td>" & _
"<td>" & DataList("Owner") & "</td>" & _
"<td>" & ConvertToDiskUnit(DataList("WorkingSet")) & "</td>" & _
"<td>" & DataList("CPUTime") & "</td>" & _
"<td><span onclick=""KillProcess '" & DataList("ProcessID") & "','" & DataList("Name") & "'"" class=""Link"">Kill Process</span></td>" & _
"</tr>"
DataList.MoveNext
Loop
strHTML = strHTML & "</table>"
end if
DataList.Close
strHTML = strHTML & "<br>Last Refresh:" & Now()
RunningProcesses_HTML=strHTML
End Function
' ***************************************
' Gets a list of shared folders and shared printers and
' returns HTML for the "Shares" section
' ***************************************
Function Shares_HTML
Dim objItem, colItems
Dim strHTML
' Query to return shared folders
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483648 OR Type = 0")
strHTML = strHTML & "<table><tr><td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Folder Shares</th></tr>"
For Each objItem In colItems
Dim strShare
strShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strShare & "')"">" & strShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapDrive('\\" & strComputer & "\" & strShare & "')"" value=""Map Drive""></input></td></tr>"
Next
strHTML = strHTML & "</table></td>"
' Query to return shared printers
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share WHERE Type = 2147483649 OR Type = 1")
strHTML = strHTML & "<td style=""vertical-align:top"">"
strHTML = strHTML & "<table class=""Table""><tr><th colspan=""2"">Printer Shares</th></tr>"
For Each objItem In colItems
Dim strPrinterShare
strPrinterShare = HTMLEncode(objItem.Name)
strHTML = strHTML & "<tr><td><span class=""Link"" onclick=""OpenUNC('\\" & strComputer & "\" & strPrinterShare & "')"">" & strPrinterShare & "</span></td>"
strHTML = strHTML & "<td><input class=""Button"" type=""submit"" onclick=""MapPrinter('\\" & strComputer & "\" & strPrinterShare & "')"" value=""Connect Printer""></input></td></tr>"
Next
strHTML = strHTML & "</table></td></table>"
Shares_HTML = strHTML
End Function
' ***************************************
' Gets computer system info to be included in the "OS / General" section
' ***************************************
Sub GetComputerSystemInfo(BYRef strobjSMBIOS,ByRef strDomain,ByRef strDomainRole, _
ByRef strManufacturer,ByRef strModel,ByRef strUserName)
Dim objItem, colItems
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem In colItems
On Error Resume Next
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
strDomain = HTMLEncode(objItem.Domain)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strModel = HTMLEncode(objItem.Model)
strUserName = HTMLEncode(objItem.UserName)
On Error GoTo 0
If strUserName = "" Then
strUserName = "No one logged in"
End If
Select Case objItem.DomainRole
Case 0
strDomainRole="Standalone Workstation"
Case 1
strDomainRole="Member Workstation"
Case 2
strDomainRole="Standalone Server"
Case 3
strDomainRole="Member Server"
Case 4
strDomainRole="Backup Domain Controller"
Case 5
strDomainRole="Primary Domain Controller"
Case Else
strDomainRole = "Unknown (" & strDomainRole & ")"
End Select
Next
End Sub
' ***************************************
' Returns a HTML report for the "Operating System/General" section
' ***************************************
Function OS_HTML()
Dim objItem, colItems
Dim strHTML
Dim strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
GetComputerSystemInfo strobjSMBIOS,strDomain,strDomainRole,strManufacturer,strModel,strUserName
Dim strServiceTag
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
For Each objItem In colItems
strServiceTag = objItem.SerialNumber
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
strHTML = "<h3>Current User: " & strUserName & "</h3>"
For Each objItem In colItems
Dim strComputerRole
Dim strCaption,strBuildNumber,strInstallDate,strBootDate
Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
Dim intFreePhysicalMemory,intTotalVirtualMemorySize,intFreeVirtualMemory
On Error Resume Next
strCaption = HTMLEncode(objItem.Caption)
strBuildNumber = HTMLEncode(objItem.BuildNumber)
strobjSMBIOS = HTMLEncode(objSMBIOS.SerialNumber)
intServicePackMajor = objItem.ServicePackMajorVersion
intServicePackMinor = objItem.ServicePackMinorVersion
intTotalVisibleMemorySize = objItem.TotalVisibleMemorySize
intFreePhysicalMemory = objItem.FreePhysicalMemory
intFreeVirtualMemory = objItem.FreeVirtualMemory
intTotalVirtualMemorySize = objItem.TotalVirtualMemorySize
strInstallDate = FormatDate(objItem.InstallDate)
strBootDate = FormatDate(objItem.LastBootUpTime)
On Error GoTo 0
strHTML = strHTML & "<table class=""Table"">" & _
"<tr>" & _
"<th>Operating System:</th><td>" & strCaption & "</td>" & _
"<th>Build Number:</th><td>" & strBuildNumber & "</td>" & _
"</tr><tr>" & _
"<th>Service Pack:</th><td>" & intServicePackMajor & "." & intServicePackMinor & "</td>" & _
"<th>Role:</th><td>" & strDomainRole & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strobjSMBIOS & "</td>" & _
"<th>Domain:</th><td>" & strDomain & "</td>" & _
"</tr><tr>" & _
"<th>Manufacturer:</th><td>" & strManufacturer & "</td>" & _
"<th>Model:</th><td>" & strModel & "</td>" & _
"</tr><tr>" & _
"<th>Total Physical Memory:</th><td>" & intTotalVisibleMemorySize & "KB</td>" & _
"<th>Free Physical Memory:</th><td>" & intFreePhysicalMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Total Virtual Memory:</th><td>" & intTotalVirtualMemorySize & "KB</td>" & _
"<th>Free Virtual Memory:</th><td>" & intFreeVirtualMemory & "KB</td>" & _
"</tr><tr>" & _
"<th>Install Date:</th><td>" & strInstallDate & "</td>" & _
"<th>Last BootUp Time:</th><td>" & strBootDate & "</td>" & _
"</tr><tr>" & _
"<th>Service Tag:</th><td>" & strServiceTag & "</td>" & _
"<th></th><td></td>" & _
"</tr>" & _
"</table>"
strResults = strResults & VbCrLf & """" & strobjSMBIOS & """,""" & CurrentComputer.InnerHTML & """,""" & strUserName & """,""" & strServiceTag & """"
Exit For
Next
OS_HTML = strHTML
End Function
' ***************************************
' Get the number of memory slots and memory arrays
' for the memory section
' ***************************************
Function GetMemoryArrayInfo(ByRef intSlots,ByRef intArrays)
Dim objItem, colItems
intSlots = 0
intArrays = 0
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray WHERE Use=3")
For Each objItem In colItems
intSlots = intSlots + objItem.MemoryDevices
intArrays = intArrays + 1
Next
End Function
' ***************************************
' Returns a HTML report for the "Memory" section
' ***************************************
Function Memory_HTML()
Dim objItem, colItems
Dim strHTML, strTotalCapacity
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>BankLabel</th>" & _
"<th>Capacity</th>" & _
"<th>Caption</th>" & _
"<th>Description</th>" & _
"<th>DeviceLocator </th>" & _
"<th>Manufacturer</th>" & _
"<th>Memory Type</th>" & _
"<th>Form Factor</th>" & _
"<th>Model</th>" & _
"<th>Speed</th>" & _
"</tr>"
strTotalCapacity = 0
For Each objItem In colItems
Dim strBankLabel,strCaption,strDescription,strDeviceLocator
Dim strManufacturer,strMemoryType,strFormFactor,strModel
Dim strCapacity,intSpeed
On Error Resume Next
strBankLabel = HTMLEncode(objItem.BankLabel)
strCapacity = ConvertToDiskUnit(objItem.Capacity)
strCaption = HTMLEncode(objItem.Caption)
strDescription = HTMLEncode(objItem.Description)
strDeviceLocator = HTMLEncode(objItem.DeviceLocator)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strMemoryType = GetMemoryType(objItem.MemoryType)
strFormFactor = GetMemoryFormFactor(objItem.FormFactor)
strModel = HTMLEncode(objItem.Model)
intSpeed = objItem.Speed
On Error GoTo 0
strTotalCapacity = strTotalCapacity + objItem.Capacity
strHTML = strHTML & "<tr><td>" & strBankLabel & "</td>" & _
"<td>" & strCapacity & "</td>" & _
"<td>" & strCaption & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & strDeviceLocator & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strMemoryType & "</td>" & _
"<td>" & strFormFactor & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & intSpeed & "</td>" & _
"</tr>"
Next
strResults = strResults & ",""" & ConvertToDiskUnit(strTotalCapacity) & """"
strHTML = strHTML & "</table>"
Dim intSlots,intArrays
GetMemoryArrayInfo intSlots,intArrays
strHTML = strHTML & "Total Memory Slots:" & intSlots & ", Memory Arrays:" & intArrays
Memory_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Processor" section
' ***************************************
Function Processor_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
strHTML = "<table class=""Table"">" & _
"<tr>" & _
"<th>Name</th>" & _
"<th>Manufacturer</th>" & _
"<th>Description</th>" & _
"<th>Address Width</th>" & _
"<th>Current Clock Speed</th>" & _
"<th>Data Width</th>" & _
"<th>Device ID</th>" & _
"<th>Ext Clock</th>" & _
"<th>L2 Cache</th>" & _
"<th>Max Clock Speed</th>" & _
"<th>#Cores</th>" & _
"<th>#Logical Processors</th>" & _
"</tr>"
For Each objItem in colItems
Dim strName,strManufacturer,strDescription,strDeviceID
Dim intAddressWidth,intCurrentClockSpeed,intDataWidth,intExtClock
Dim intL2CacheSize,intMaxClockSpeed, intNumberOfCores,intNumberOfLogicalProcessors
On Error Resume Next
strName = HTMLEncode(objItem.Name)
strManufacturer = HTMLEncode(objItem.Manufacturer)
strDescription = HTMLEncode(objItem.Description)
intAddressWidth = objItem.AddressWidth
intCurrentClockSpeed = objItem.CurrentClockSpeed
intDataWidth = objItem.DataWidth
strDeviceID = HTMLEncode(objItem.DeviceID)
intExtClock = objItem.ExtClock
intL2CacheSize = objItem.L2CacheSize
intMaxClockSpeed = objItem.MaxClockSpeed
intNumberOfCores = objItem.NumberOfCores
intNumberOfLogicalProcessors= objItem.NumberOfLogicalProcessors
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strName & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strDescription & "</td>" & _
"<td>" & intAddressWidth & "</td>" & _
"<td>" & intCurrentClockSpeed & "</td>" & _
"<td>" & intDataWidth & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & intExtClock & "</td>" & _
"<td>" & intL2CacheSize & "</td>" & _
"<td>" & intMaxClockSpeed & "</td>" & _
"<td>" & intNumberOfCores & "</td>" & _
"<td>" & intNumberOfLogicalProcessors & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
Processor_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Physical Disk" section
' ***************************************
Function PhysicalDisk_HTML()
Dim objItem, colItems
Dim strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
strHTML = "<table class=""Table""><tr><th>Caption</th><th>Manufacturer</th>" & _
"<th>Model</th><th>Size</th><th>Serial</th><th>Media Type</th><th>#Partitions</th><th>DeviceID</th><th>Firmware</th><th>Interface</th></tr>"
For Each objItem in colItems
Dim intSize,intPartitions
Dim strSize,strCaption,strManufacturer,strModel,strMediaType
Dim strDeviceID,strFirmwareRevision,strInterfaceType, strSerialNumber
intSize = objItem.Size
If IsNumeric(intSize) = False Then
intSize = 0
End If
On Error Resume Next
strCaption= HTMLEncode(objItem.Caption)
strSize = ConvertToDiskUnit(intSize)
strSerialNumber = HTMLEncode(objItem.SerialNumber)
strMediaType = HTMLEncode(objItem.MediaType)
intPartitions = HTMLEncode(objItem.Partitions)
strDeviceID = HTMLEncode(objItem.DeviceID)
strFirmwareRevision = HTMLEncode(objItem.FirmwareRevision)
strInterfaceType = HTMLEncode(objItem.InterfaceType)
strModel = HTMLEncode(objItem.Model)
strManufacturer = HTMLEncode(objItem.Manufacturer)
On Error GoTo 0
strHTML = strHTML & "<tr><td>" & strCaption & "</td>" & _
"<td>" & strManufacturer & "</td>" & _
"<td>" & strModel & "</td>" & _
"<td>" & strSize & "</td>" & _
"<td>" & strSerialNumber & "</td>" & _
"<td>" & strMediaType & "</td>" & _
"<td>" & intPartitions & "</td>" & _
"<td>" & strDeviceID & "</td>" & _
"<td>" & strFirmwareRevision & "</td>" & _
"<td>" & strInterfaceType & "</td>" & _
"</tr>"
Next
strHTML = strHTML & "</table>"
PhysicalDisk_HTML=strHTML
End Function
' ***************************************
' Returns a HTML report for the "Logical Disk" section
' ***************************************
Function LogicalDisk_HTML()
Dim objItem, colItems
Dim strDriveType, strDiskSize, strHTML
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType = 3")
strHTML = "<table class=""Table""><tr><th>Drive</th><th>Name</th><th>File System</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>"
For Each objItem in colItems
Dim pctFreeSpace,strFreeSpace,strusedSpace,strName,strFileSystem,strVolumeName
Dim intFreeSpace, intSize
On Error Resume Next
intFreeSpace = objItem.FreeSpace
intSize = objItem.Size
If ISNUMERIC(intFreeSpace) = False Then
intFreeSpace=0
End If
If IsNumeric(intSize) = False Then
intSize = 0
End If
If objItem.FreeSpace > 0 Then
pctFreeSpace = round(((intFreeSpace / intSize) * 100),0)
Else
pctFreeSpace=0
End If
strDiskSize = ConvertToDiskUnit(intSize)
strFreeSpace = ConvertToDiskUnit(intFreeSpace)
strUsedSpace = ConvertToDiskUnit(intSize-intFreeSpace)
strName = HTMLEncode(objItem.Name)
strVolumeName = HTMLEncode(objItem.VolumeName)
strFileSystem = HTMLEncode(objItem.FileSystem)
On Error GoTo 0
dim strChart
strChart = "<div width=100%;""><span style=""padding:0px;margin:0px;width=" & 100-pctFreeSpace & _
"%;background-color:blue;""> </span><span style=""padding:0px;margin:0px;width=" & pctFreeSpace & _
"%;background-color:#FF00FF;""> </span></div>"
strHTML = strHTML & "<tr><td>" & strName & "</td><td>" & _
strVolumeName & "</td><td>" & strFileSystem & "</td><td>" & _
strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _
strFreeSpace & "</td><td>" & pctFreeSpace & "%</td></tr>" & _
"<tr><td colspan=""7"">" & strChart & "</td></tr>"
If strName = "C:" Then strResults = strResults & ",""" & strDiskSize & """,""" & strFreeSpace & """"
Next
strHTML = strHTML + "</table></br>"
LogicalDisk_HTML = strHTML
End Function
Sub OutputToExcel
Dim strHTAPath, strReportPath, objFSO, objFile, objShell, strOutputFile
If Mid(document.location, 6, 3) = "///" Then
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
Else
strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
End If
strReportPath = Left(strHTAPath, InStrRev(strHTAPath, "\") - 1) & "\Reports"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strReportPath) = False Then objFSO.CreateFolder strReportPath
strOutputFile = strReportPath & "\" & CurrentComputer.InnerHTML & "_Report.xls"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutputFile, True)
objFile.WriteLine OS.InnerHTML
objFile.WriteLine ProcessesData.InnerHTML
objFile.WriteLine Memory.InnerHTML
objFile.WriteLine LogicalDisk.InnerHTML
objFile.WriteLine PhysicalDisk.InnerHTML
objFile.WriteLine Processor.InnerHTML
objFile.WriteLine Shares.InnerHTML
objFile.Close
Set objShell = CreateObject("WScript.Shell")
objShell.Run "excel """ & strOutputFile & """", 1, False
End Sub
Sub Browse_For_File()
Dim objDialog, intResult
Const intForReading = 1
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "."
intResult = objDialog.ShowOpen
If intResult = 0 Then
Exit Sub
End If
txtComputer.Value = objDialog.FileName
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
</script>
<script type="text/javascript">
/* Toggle expand/collapse state for specified section */
function toggleDisplay(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
/* Toggle expand/collapse state for all sections */
function toggleAll() {
var el = document.getElementById("OS");
var display = ''
if ( el.style.display != 'none' ) {
display = 'none';
}
el.style.display = display;
el = document.getElementById("Memory");
el.style.display = display;
el = document.getElementById("LogicalDisk");
el.style.display = display;
el = document.getElementById("PhysicalDisk");
el.style.display = display;
el = document.getElementById("Processor");
el.style.display = display;
el = document.getElementById("Shares");
el.style.display = display;
el = document.getElementById("Processes");
el.style.display = display;
}
</script>
<h1>Computer Info Tool</h1>
<div id="Header" style="padding-bottom:0px;margin-bottom:0px;">
<span style="font-weight:bold;">Connect To Computer:<span><input id="txtComputer"></input>
<input type='button' value='Browse...' name='btnBrowse' onClick='vbs:Browse_For_File()'>
<input class="Button" style="font-weight:bold;" onClick="GenerateReport()" type="submit" value="Generate Report">
<input class="Button" style="font-weight:bold;" onClick="OutputToExcel()" type="button" value="Output To Excel">
</input>
</div>
<div id="Tools" style="display:none;margin-bottom:0px;">
<span class="Link" onClick="RebootComputer">Reboot Computer</span> |
<span class="Link" onClick="ShutDownComputer">Shutdown Computer</span>
</div>
<div id="Main" style="display:none;">
<div id="CurrentComputer" style="display:none"></div>
<div style="text-align:right;">
<span class="Link" style="font-weight:bold;" onclick="javascript:toggleAll();">Expand/Collapse All</span>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('OS');" class="InfoSectionHeader">Operating System / General</div>
<div id="OS" class="InfoSectionBody" ></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processes');" class="InfoSectionHeader">Running Processes</div>
<div id="Processes" class="InfoSectionBody">
Auto Refresh Interval:<select id="ProcessAutoRefresh" onchange="SetProcessAutoRefresh">
<option value ="0">None</option>
<option value ="1000">1 second</option>
<option value ="2000">2 seconds</option>
<option value ="3000">3 seconds</option>
<option value ="5000">5 seconds</option>
<option value ="10000">10 seconds</option>
<option value ="20000">20 seconds</option>
<option value ="30000">30 seconds</option>
<option value ="60000">1 minute</option>
</select>
Filter (Optional):<input id="txtProcessFilter"></input>
<br/><br/>
<span onclick="RefreshProcesses()" style=""font-weight:bold"" class="Link">Refresh Processes</span>
<br/><br/>
<div id="ProcessesData"></div>
</div>
<div id="ProcessSort" style="display:none">Name</div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Memory');" class="InfoSectionHeader">Memory</div>
<div id="Memory" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('LogicalDisk');" class="InfoSectionHeader">Logical Disk</div>
<div id="LogicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('PhysicalDisk');" class="InfoSectionHeader">Physical Disk</div>
<div id="PhysicalDisk" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Processor');" class="InfoSectionHeader">Processor</div>
<div id="Processor" class="InfoSectionBody"></div>
</div>
<div class="InfoSection">
<div onClick="javascript:toggleDisplay('Shares');" class="InfoSectionHeader">Shares</div>
<div id="Shares" class="InfoSectionBody"></div>
</div>
</div>
<div id="DisplayError"></div>
<div id="Footer">
<hr/>
<div style="float:left;">Version 1.0</div>
<div style="float:right;">By Dhiraj Mutha<br />
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
ASKER
No its still the same. I want it in tabular formart. The format should be like this.
A | B | C | D | E | F | G | H | I |
Sr. No. | Hostname | Logged in User | IP Address | MAC Address | Service Tag | RAM | HDD Size | Free space on C |
1 PC1 Test1 1.1.1.1 00000000 D1254D1 512 MB 40 GB 27 GB
2 PC2 Test2 1.1.1.2 00000011 D1544D2 1 Gb 80 GB 40 GB
3
4
5
A | B | C | D | E | F | G | H | I |
Sr. No. | Hostname | Logged in User | IP Address | MAC Address | Service Tag | RAM | HDD Size | Free space on C |
1 PC1 Test1 1.1.1.1 00000000 D1254D1 512 MB 40 GB 27 GB
2 PC2 Test2 1.1.1.2 00000011 D1544D2 1 Gb 80 GB 40 GB
3
4
5
That's what it's like for me when I use a text file...it opens in a CSV with all details together....
ASKER
Great.... its only not showing IP Address and MAC address.... can you get that also for me...?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks mate. That worked super fine.
ASKER
Thanks a lot, for all the help. Sorry for troubling you a lot. This as resolved the query.
ASKER
One last thing.... the model is missing in Excel sheet, can that be added in it.... please.
Does the model and serial number show in the single computer report? Can you tell me which section, and which values are the serial number and model?
Regards,
Rob.
Regards,
Rob.
ASKER
Ya it shows in the single computer report. It shows under OS/General section.