With this hta script you can specify a list of computers and get information about them through WMI. If you are not an administrator on the remote computers you can specify a user with administrator privileges. You can also select if the script output is saved to a text file or to an excel workbook. The script can easily be modified to retrieve more information. You just have to define new functions to retrieve them.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>WMI Information Retriever</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<HTA:APPLICATION
ID="objWMIInformationRetriever"
APPLICATIONNAME="WMI Information Retriever"
SCROLL="No"
SINGLEINSTANCE="Yes"
BORDER="Thin"
MAXIMIZEBUTTON="No"
MINIMIZEBUTTON="Yes"
SYSMENU="Yes"
INNERBORDER="No"
>
<script type="text/VBScript">
'+--------------------------------------------------------
'| WMI Information Retriever
'| Created by Nikos Asimakis
'|
'| With this hta script you can specify a list of computers and get information about them
'| through WMI. If you are not an administrator on the remote computers you can specify a user
'| with administrator privileges. You can also select if the script output is saved to a text
'| file or to an excel workbook. The script can easily be modified to retrieve more information.
'| You just have to define new functions to retrieve them.
'+--------------------------------------------------------
Option Explicit
Const constProgramTitle = "WMI Information Retriever"
Const constRegistryKey = "HKCU\Software\HTAWMIInformationRetriever\"
Const constAppdataFolder = "HTAWMIInformationRetriever\"
Const constDefaultOutputFile = "WMI output.txt"
Sub Window_onLoad
Dim WshShell, strTextFilePath, RadioButton
window.ResizeTo 355,485
document.getElementById("username_textbox").Value = ReadRegistrySettings(constRegistryKey & "Username")
document.getElementById("domain_textbox").Value = ReadRegistrySettings(constRegistryKey & "Domain")
If document.getElementById("username_textbox").Value = "" Then
document.getElementById("username_textbox").focus()
Else
document.getElementById("password_textbox").focus()
End If
Set WshShell = CreateObject("WScript.Shell")
strTextFilePath = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
constAppdataFolder & "\" & _
"computers.txt"
LoadComputers strTextFilePath
For Each RadioButton in outputformat_radiobutton
If RadioButton.Value = ReadRegistrySettings(constRegistryKey & "OutputFormat") Then
RadioButton.Checked = True
End If
Next
document.getElementById("outputfile_textbox").Value = ReadRegistrySettings(constRegistryKey & "OutputFile")
If document.getElementById("outputfile_textbox").Value = "" Then
document.getElementById("outputfile_textbox").Value = constDefaultOutputFile
End If
End Sub
Sub RunStart
Dim strUsername, strDomain, strPassword, strComputer, arrComputers(), i, _
objSWbemServices, strErrorInfo, strDomainUsername, _
RadioButton, _
OutputRow, OutputColumn, OutputFilePathOrExcelObject, objWorkbook
'Get username, domain, password
strUsername = document.getElementById("username_textbox").Value
strDomain = document.getElementById("domain_textbox").Value
strPassword = document.getElementById("password_textbox").Value
If strDomain <> "" Then
If strUsername <> "" Then
strDomainUsername = strDomain & "\" & strUsername
Else
strDomainUsername = ""
End If
Else
strDomainUsername = strUsername
End If
'Get list of computers
ReDim Preserve arrComputers(0)
arrComputers(0) = ""
i = 1
For Each strComputer in computers_listbox.Options
ReDim Preserve arrComputers(i)
arrComputers(i) = strComputer.Value
i = i + 1
Next
If UBound(arrComputers,1) > 0 And Not ( strDomainUsername <> "" And strPassword = "" ) Then
OutputRow = 0
OutputColumn = 0
'Get output format
For Each RadioButton in outputformat_radiobutton
If RadioButton.Checked And RadioButton.Value = "textfile" Then
OutputFilePathOrExcelObject = document.getElementById("outputfile_textbox").Value
If OutputFilePathOrExcelObject = "" Then
Call MsgBox("No output text file specified!" & vbNewLine & _
"I will use ''" & constDefaultOutputFile & "'' on your Desktop instead.", _
vbOKOnly+vbInformation, constProgramTitle)
OutputFilePathOrExcelObject = constDefaultOutputFile
End If
OutputFilePathOrExcelObject = GenerateOutputFilePath(OutputFilePathOrExcelObject)
End If
Next
' If an output text file path is not specified then create an
' excel application object for output to an excel session
If OutputFilePathOrExcelObject = "" Then
Set OutputFilePathOrExcelObject = CreateObject("Excel.Application")
OutputFilePathOrExcelObject.Visible = True
Set objWorkbook = OutputFilePathOrExcelObject.Workbooks.Add()
End If
For each strComputer in arrComputers
If strComputer = "" Then
objSWbemServices = ""
strComputer = "Computers"
Else
On Error Resume Next
Set objSWbemServices = CreateObject("WbemScripting.SWbemLocator").ConnectServer _
(strComputer, "root\cimv2", strDomainUsername, strPassword)
If Err = -2147217308 Then 'Error -2147217308: User credentials cannot be used for local connections
Err.Clear
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
If Err <> 0 Then
strErrorInfo = Err.Number & ": " & Err.Description
Err.Clear
End If
ElseIf Err <> 0 Then 'an error occured
strErrorInfo = Err.Number & ": " & Err.Description
Err.Clear
End If
On Error Goto 0
End If
If strErrorInfo = "" Then
GenerateOutput strComputer, True, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetNetworkAdapterDescription(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetIP(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetGateway(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetDHCPStatus(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetCPUName(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetRAM(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetComputerModel(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetComputerName(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetWindowsVersionAndServicePack(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetHDDCapacity(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetHDDFreeSpace(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetMembersOfAdministratorGroup(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
Else
GenerateOutput strComputer, True, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput strErrorInfo, False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
strErrorInfo = ""
End If
Next
Call MsgBox("DONE!!", vbOKOnly+vbInformation, constProgramTitle)
End If
If strDomainUsername <> "" And strPassword = "" Then Call MsgBox("You forgot to enter your password!", vbOKOnly+vbExclamation, constProgramTitle)
WriteRegistrySettings constRegistryKey & "Username", strUsername
WriteRegistrySettings constRegistryKey & "Domain", strDomain
WriteRegistrySettings constRegistryKey & "OutputFile", document.getElementById("outputfile_textbox").Value
For Each RadioButton in outputformat_radiobutton
If RadioButton.Checked Then
WriteRegistrySettings constRegistryKey & "OutputFormat", RadioButton.Value
End If
Next
WriteAppdataSettings constAppdataFolder, "computers.txt", arrComputers
End Sub
Sub WriteRegistrySettings(RegKey, strValue)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite RegKey, strValue, "REG_SZ"
End Sub
Function ReadRegistrySettings(RegKey)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
On Error Resume Next
ReadRegistrySettings = WshShell.RegRead(RegKey)
If Err <> 0 Then 'an error occured!
Err.clear
ReadRegistrySettings = ""
End If
On Error Goto 0
End Function
Sub WriteAppdataSettings(strFolderInAppdata, strTextFile, ByRef arrList)
Dim WshShell, strTextFilePath, fso, f, i, intListSize
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = CreateObject("WScript.Shell")
strTextFilePath = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
strFolderInAppdata & "\" & _
strTextFile
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f = fso.CreateFolder(WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
strFolderInAppdata)
Set f = fso.OpenTextFile(strTextFilePath, ForWriting, True)
intListSize = UBound(arrList,1)
For i = 0 to intListSize
If arrList(i) <> "" Then
If i = intListSize Then
f.Write arrList(i)
Else
f.WriteLine arrList(i)
End If
End If
Next
Err.clear
On Error Goto 0
End Sub
Function GenerateOutputFilePath(strFile)
Dim WshShell, fso, f, strErrorDescription, strOriginallySpecifiedstrFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If InStrRev(strFile,".txt") = 0 Then 'No .txt extension specified, appending .txt extension
strFile = strFile & ".txt"
End If
If Instr(strFile,"\") = 0 Then 'Only filename specified, I will generate the full path
strFile = WshShell.SpecialFolders("Desktop") & "\" & strFile
End If
strOriginallySpecifiedstrFile = strFile
On Error Resume Next
Set f = fso.OpenTextFile(strFile, ForWriting, True)
Do While Err <> 0
Select Case Err.Number
Case 70 strErrorDescription = "The file may be open, read only or" & vbNewLine & _
"you may not have the required permissions!" & vbNewLine & vbNewLine
Case 52 strErrorDescription = "The file name is illegal!" & vbNewLine & _
"You may have used an illegal character!" & vbNewLine & vbNewLine
Case Else strErrorDescription = ""
End Select
strFile = InputBox(strErrorDescription & "Please specify a different output file.", _
constProgramTitle & " - Error: " & Err.Description & " (" & Err.Number & ")", _
strOriginallySpecifiedstrFile)
If strFile = "" Then strFile = strOriginallySpecifiedstrFile
If InStrRev(strFile,".txt") = 0 Then 'No .txt extension specified, appending .txt extension
strFile = strFile & ".txt"
End If
If Instr(strFile,"\") = 0 Then 'Only filename specified, I will generate the full path
strFile = WshShell.SpecialFolders("Desktop") & "\" & strFile
End If
Err.Clear
Set f = fso.OpenTextFile(strFile, ForWriting, True)
Loop
On Error Goto 0
GenerateOutputFilePath = strFile
End Function
Sub GenerateOutput(str, StartNewLine, ByRef Row, ByRef Column, ByRef OutputFilePathOrExcelObject)
If Instr(OutputFilePathOrExcelObject,"\") = 0 Then 'If no "\" are contained then it's not a path
If StartNewLine Then
Row = Row + 1
Column = 1
Else
Column = Column + 1
End If
OutputFilePathOrExcelObject.Cells(Row,Column) = str
OutputFilePathOrExcelObject.Cells(Row,Column).Activate
Else 'OutputFilePathOrExcelObject is the path to a text file
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If Row = 0 Then
Set f = fso.OpenTextFile(OutputFilePathOrExcelObject, ForWriting, True)
Row = 1
Column = 1
f.Write str
Else
Set f = fso.OpenTextFile(OutputFilePathOrExcelObject, ForAppending, True)
If StartNewLine Then
Row = Row + 1
Column = 1
f.Write vbNewLine
Else
Column = Column + 1
End If
If Column > 1 Then
f.Write vbTab & str
Else
f.Write str
End If
End If
End If
End Sub
Function WMIGetNetworkAdapterDescription(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetNetworkAdapterDescription = "Network Adapter Description"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetNetworkAdapterDescription = objItem.Description
Else ' i>1
WMIGetNetworkAdapterDescription = WMIGetNetworkAdapterDescription & ", " & objItem.Description
End If
End If
Next
End Function
Function WMIGetIP(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetIP = "IP Address"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetIP = Join(objItem.IPAddress, ",")
Else ' i>1
WMIGetIP = WMIGetIP & ", " & Join(objItem.IPAddress, ",")
End If
End If
Next
End Function
Function WMIGetGateway(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetGateway = "IP Gateway"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
On Error Resume Next
WMIGetGateway = Join(objItem.DefaultIPGateway, ",")
If Err <> 0 Then
Err.Clear
WMIGetGateway = "-"
End If
On Error Goto 0
Else ' i>1
On Error Resume Next
WMIGetGateway = WMIGetGateway & ", " & Join(objItem.DefaultIPGateway, ",")
If Err <> 0 Then
Err.Clear
WMIGetGateway = WMIGetGateway & ", " & "-"
End If
On Error Goto 0
End If
End If
Next
End Function
Function WMIGetDHCPStatus(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetDHCPStatus = "DHCP Enabled?"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetDHCPStatus = objItem.DHCPEnabled
Else ' i>1
WMIGetDHCPStatus = WMIGetDHCPStatus & ", " & objItem.DHCPEnabled
End If
End If
Next
End Function
Function WMIGetCPUName(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetCPUName = "CPU Name"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetCPUName = objItem.Name
Next
WMIGetCPUName = RegExReplace(WMIGetCPUName, "\s{2,}", "") ' Remove excess white space from CPU name
End Function
Function WMIGetRAM(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetRAM = "RAM (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetRAM = objItem.TotalPhysicalMemory
Next
End Function
Function WMIGetComputerModel(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetComputerModel = "Computer Model"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetComputerModel = objItem.Model
Next
End Function
Function WMIGetComputerName(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetComputerName = "Computer Name"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetComputerName = objItem.Name
Next
End Function
Function WMIGetWindowsVersionAndServicePack(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetWindowsVersionAndServicePack = "Windows Version & Service Pack"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetWindowsVersionAndServicePack = objItem.Caption & ", " & objItem.CSDVersion
Next
End Function
Function WMIGetHDDCapacity(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetHDDCapacity = "HDD C:\ Capacity (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If objItem.Caption = "C:" Then WMIGetHDDCapacity = objItem.Size
Next
End Function
Function WMIGetHDDFreeSpace(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetHDDFreeSpace = "HDD C:\ Free Space (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If objItem.Caption = "C:" Then WMIGetHDDFreeSpace = objItem.FreeSpace
Next
End Function
Function WMIGetMembersOfAdministratorGroup(ByRef objWMIService)
Dim colItems, objItem, i, str
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetMembersOfAdministratorGroup = "Local Administrators Group"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 1
For Each objItem In colItems
If InStr(objItem.GroupComponent, "Administrators") <> 0 Then ' Administrators found!
If i > 1 Then WMIGetMembersOfAdministratorGroup = WMIGetMembersOfAdministratorGroup & ", "
str = Split(objItem.PartComponent, Chr(34), -1, 1)
WMIGetMembersOfAdministratorGroup = WMIGetMembersOfAdministratorGroup & str(1) & "\" & str(3)
i = i + 1
End If
Next
End Function
Function RegExReplace(str, patrn, replStr)
Dim regEx ' Create variables.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Make case insensitive.
RegExReplace = regEx.Replace(str, replStr) ' Make replacement.
End Function
Sub LoadComputers(strTextFilePath)
Dim intResult, objDialog, objOption, fso, objFile, strLine
If strTextFilePath = "" Then
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files|*.txt|All Files|*.*"
objDialog.FilterIndex = 1
intResult = objDialog.ShowOpen
If intResult = 0 Then
Exit Sub
End If
strTextFilePath = objDialog.FileName
End If
For Each objOption in computers_listbox.Options
objOption.RemoveNode
Next
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFile = fso.OpenTextFile(strTextFilePath, ForReading)
If Err = 0 Then
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
computers_listbox.Add(objOption)
Loop
objFile.Close
End If
Err.Clear
On Error Goto 0
End Sub
Sub RunClear
Dim objOption
For Each objOption in computers_listbox.Options
objOption.RemoveNode
Next
End Sub
Sub RunAdd
Dim objOption, input
input = InputBox("Enter the computer name",constProgramTitle)
If input <> "" Then
Set objOption = Document.createElement("OPTION")
objOption.Text = input
objOption.Value = objOption.Text
computers_listbox.Add(objOption)
End If
End Sub
Sub RunSelectComputer
Dim objOption, input
On Error Resume Next
input = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Select a remote computer", 0, "::{208D2C60-3AEA-1069-A2D7-08002B30309D}\EntireNetwork"). _
Self.Name
If Err <> 0 Then
input = ""
Err.Clear
End If
On Error Goto 0
If input <> "" Then
Set objOption = Document.createElement("OPTION")
objOption.Text = input
objOption.Value = objOption.Text
computers_listbox.Add(objOption)
End If
End Sub
Sub RunRemove
Dim objOption
For Each objOption in computers_listbox.Options
If objOption.Selected Then
objOption.RemoveNode
End If
Next
End Sub
Sub TrapEnter
If window.event.Keycode = 13 Then
RunStart()
End If
End Sub
Sub SetTextOutputFormat
Dim RadioButton
For Each RadioButton in outputformat_radiobutton
If RadioButton.Value = "textfile" Then RadioButton.Checked = True
Next
End Sub
Sub RunExit
self.close()
End Sub
</script>
</head>
<body bgcolor="buttonface">
<fieldset id="userdomainpassw">
<legend>User with administrator privileges:</legend>
<ol>
<li><label for="username_textbox">Username:</label>
<input type="text"
id="username_textbox"
onkeypress="TrapEnter" /></li>
<li><label for="domain_textbox">Domain:</label>
<input type="text"
id="domain_textbox"
onkeypress="TrapEnter" /></li>
<li><label for="password_textbox">Password:</label>
<input type="password"
id="password_textbox"
onkeypress="TrapEnter" /></li>
</ol>
</fieldset>
<fieldset id="computerlist">
<legend>Computer list:</legend>
<select id="computers_listbox" size="10"></select>
<ol>
<li><input type="button"
value="Load list..."
title="Load a text file containing a list of computers"
id="LoadComputers_button"
onclick="LoadComputers('')"/></li>
<li><input type="button"
value="Select..."
title="Select a remote computer from a list"
id="SelectComputer_button"
onclick="RunSelectComputer" /></li>
<li><input type="button"
value="Add..."
id="Add_button"
onclick="RunAdd" /></li>
<li><input type="button"
value="Remove"
id="Remove_button"
onclick="RunRemove" /></li>
<li><input type="button"
value="Clear"
id="Clear_button"
onclick="RunClear" /></li>
</ol>
</fieldset>
<fieldset id="outputformat">
<legend>Output format:</legend>
<ol>
<li>
<label><input type="radio"
name="outputformat_radiobutton"
value="textfile" />Text File</label>
<label for="outputfile_textbox"> - Specify filename:</label>
<input type="text"
id="outputfile_textbox"
onkeypress="TrapEnter"
onclick="SetTextOutputFormat"
onfocus="SetTextOutputFormat" />
<p>(The file will be saved on your desktop)</p>
</li>
<li>
<label><input type="radio"
name="outputformat_radiobutton"
value="excelsession"
checked="checked" />Excel Session</label>
</li>
</ol>
</fieldset>
<fieldset id="actionbuttons">
<input type="button"
value="Exit"
id="Exit_button"
onclick="RunExit" />
<input type="button"
value="Start"
id="Start_button"
onclick="RunStart" />
</fieldset>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>WMI Information Retriever</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<HTA:APPLICATION
ID="objWMIInformationRetriever"
APPLICATIONNAME="WMI Information Retriever"
SCROLL="No"
SINGLEINSTANCE="Yes"
BORDER="Thin"
MAXIMIZEBUTTON="No"
MINIMIZEBUTTON="Yes"
SYSMENU="Yes"
INNERBORDER="No"
>
<script type="text/VBScript">
'+--------------------------------------------------------
'| WMI Information Retriever
'| Created by Nikos Asimakis
'|
'| With this hta script you can specify a list of computers and get information about them
'| through WMI. If you are not an administrator on the remote computers you can specify a user
'| with administrator privileges. You can also select if the script output is saved to a text
'| file or to an excel workbook. The script can easily be modified to retrieve more information.
'| You just have to define new functions to retrieve them.
'+--------------------------------------------------------
Option Explicit
Const constProgramTitle = "WMI Information Retriever"
Const constRegistryKey = "HKCU\Software\HTAWMIInformationRetriever\"
Const constAppdataFolder = "HTAWMIInformationRetriever\"
Const constDefaultOutputFile = "WMI output.txt"
Sub Window_onLoad
Dim WshShell, strTextFilePath, RadioButton
window.ResizeTo 355,485
document.getElementById("username_textbox").Value = ReadRegistrySettings(constRegistryKey & "Username")
document.getElementById("domain_textbox").Value = ReadRegistrySettings(constRegistryKey & "Domain")
If document.getElementById("username_textbox").Value = "" Then
document.getElementById("username_textbox").focus()
Else
document.getElementById("password_textbox").focus()
End If
Set WshShell = CreateObject("WScript.Shell")
strTextFilePath = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
constAppdataFolder & "\" & _
"computers.txt"
LoadComputers strTextFilePath
For Each RadioButton in outputformat_radiobutton
If RadioButton.Value = ReadRegistrySettings(constRegistryKey & "OutputFormat") Then
RadioButton.Checked = True
End If
Next
document.getElementById("outputfile_textbox").Value = ReadRegistrySettings(constRegistryKey & "OutputFile")
If document.getElementById("outputfile_textbox").Value = "" Then
document.getElementById("outputfile_textbox").Value = constDefaultOutputFile
End If
End Sub
Sub RunStart
Dim strUsername, strDomain, strPassword, strComputer, arrComputers(), i, _
objSWbemServices, strErrorInfo, strDomainUsername, _
RadioButton, _
OutputRow, OutputColumn, OutputFilePathOrExcelObject, objWorkbook
'Get username, domain, password
strUsername = document.getElementById("username_textbox").Value
strDomain = document.getElementById("domain_textbox").Value
strPassword = document.getElementById("password_textbox").Value
If strDomain <> "" Then
If strUsername <> "" Then
strDomainUsername = strDomain & "\" & strUsername
Else
strDomainUsername = ""
End If
Else
strDomainUsername = strUsername
End If
'Get list of computers
ReDim Preserve arrComputers(0)
arrComputers(0) = ""
i = 1
For Each strComputer in computers_listbox.Options
ReDim Preserve arrComputers(i)
arrComputers(i) = strComputer.Value
i = i + 1
Next
If UBound(arrComputers,1) > 0 And Not ( strDomainUsername <> "" And strPassword = "" ) Then
OutputRow = 0
OutputColumn = 0
'Get output format
For Each RadioButton in outputformat_radiobutton
If RadioButton.Checked And RadioButton.Value = "textfile" Then
OutputFilePathOrExcelObject = document.getElementById("outputfile_textbox").Value
If OutputFilePathOrExcelObject = "" Then
Call MsgBox("No output text file specified!" & vbNewLine & _
"I will use ''" & constDefaultOutputFile & "'' on your Desktop instead.", _
vbOKOnly+vbInformation, constProgramTitle)
OutputFilePathOrExcelObject = constDefaultOutputFile
End If
OutputFilePathOrExcelObject = GenerateOutputFilePath(OutputFilePathOrExcelObject)
End If
Next
' If an output text file path is not specified then create an
' excel application object for output to an excel session
If OutputFilePathOrExcelObject = "" Then
Set OutputFilePathOrExcelObject = CreateObject("Excel.Application")
OutputFilePathOrExcelObject.Visible = True
Set objWorkbook = OutputFilePathOrExcelObject.Workbooks.Add()
End If
For each strComputer in arrComputers
If strComputer = "" Then
objSWbemServices = ""
strComputer = "Computers"
Else
On Error Resume Next
Set objSWbemServices = CreateObject("WbemScripting.SWbemLocator").ConnectServer _
(strComputer, "root\cimv2", strDomainUsername, strPassword)
If Err = -2147217308 Then 'Error -2147217308: User credentials cannot be used for local connections
Err.Clear
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
If Err <> 0 Then
strErrorInfo = Err.Number & ": " & Err.Description
Err.Clear
End If
ElseIf Err <> 0 Then 'an error occured
strErrorInfo = Err.Number & ": " & Err.Description
Err.Clear
End If
On Error Goto 0
End If
If strErrorInfo = "" Then
GenerateOutput strComputer, True, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetNetworkAdapterDescription(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetIP(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetGateway(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetDHCPStatus(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetCPUName(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetRAM(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetComputerModel(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetComputerName(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetWindowsVersionAndServicePack(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetHDDCapacity(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetHDDFreeSpace(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput WMIGetMembersOfAdministratorGroup(objSWbemServices), False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
Else
GenerateOutput strComputer, True, OutputRow, OutputColumn, OutputFilePathOrExcelObject
GenerateOutput strErrorInfo, False, OutputRow, OutputColumn, OutputFilePathOrExcelObject
strErrorInfo = ""
End If
Next
Call MsgBox("DONE!!", vbOKOnly+vbInformation, constProgramTitle)
End If
If strDomainUsername <> "" And strPassword = "" Then Call MsgBox("You forgot to enter your password!", vbOKOnly+vbExclamation, constProgramTitle)
WriteRegistrySettings constRegistryKey & "Username", strUsername
WriteRegistrySettings constRegistryKey & "Domain", strDomain
WriteRegistrySettings constRegistryKey & "OutputFile", document.getElementById("outputfile_textbox").Value
For Each RadioButton in outputformat_radiobutton
If RadioButton.Checked Then
WriteRegistrySettings constRegistryKey & "OutputFormat", RadioButton.Value
End If
Next
WriteAppdataSettings constAppdataFolder, "computers.txt", arrComputers
End Sub
Sub WriteRegistrySettings(RegKey, strValue)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite RegKey, strValue, "REG_SZ"
End Sub
Function ReadRegistrySettings(RegKey)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
On Error Resume Next
ReadRegistrySettings = WshShell.RegRead(RegKey)
If Err <> 0 Then 'an error occured!
Err.clear
ReadRegistrySettings = ""
End If
On Error Goto 0
End Function
Sub WriteAppdataSettings(strFolderInAppdata, strTextFile, ByRef arrList)
Dim WshShell, strTextFilePath, fso, f, i, intListSize
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = CreateObject("WScript.Shell")
strTextFilePath = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
strFolderInAppdata & "\" & _
strTextFile
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f = fso.CreateFolder(WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\" & _
strFolderInAppdata)
Set f = fso.OpenTextFile(strTextFilePath, ForWriting, True)
intListSize = UBound(arrList,1)
For i = 0 to intListSize
If arrList(i) <> "" Then
If i = intListSize Then
f.Write arrList(i)
Else
f.WriteLine arrList(i)
End If
End If
Next
Err.clear
On Error Goto 0
End Sub
Function GenerateOutputFilePath(strFile)
Dim WshShell, fso, f, strErrorDescription, strOriginallySpecifiedstrFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If InStrRev(strFile,".txt") = 0 Then 'No .txt extension specified, appending .txt extension
strFile = strFile & ".txt"
End If
If Instr(strFile,"\") = 0 Then 'Only filename specified, I will generate the full path
strFile = WshShell.SpecialFolders("Desktop") & "\" & strFile
End If
strOriginallySpecifiedstrFile = strFile
On Error Resume Next
Set f = fso.OpenTextFile(strFile, ForWriting, True)
Do While Err <> 0
Select Case Err.Number
Case 70 strErrorDescription = "The file may be open, read only or" & vbNewLine & _
"you may not have the required permissions!" & vbNewLine & vbNewLine
Case 52 strErrorDescription = "The file name is illegal!" & vbNewLine & _
"You may have used an illegal character!" & vbNewLine & vbNewLine
Case Else strErrorDescription = ""
End Select
strFile = InputBox(strErrorDescription & "Please specify a different output file.", _
constProgramTitle & " - Error: " & Err.Description & " (" & Err.Number & ")", _
strOriginallySpecifiedstrFile)
If strFile = "" Then strFile = strOriginallySpecifiedstrFile
If InStrRev(strFile,".txt") = 0 Then 'No .txt extension specified, appending .txt extension
strFile = strFile & ".txt"
End If
If Instr(strFile,"\") = 0 Then 'Only filename specified, I will generate the full path
strFile = WshShell.SpecialFolders("Desktop") & "\" & strFile
End If
Err.Clear
Set f = fso.OpenTextFile(strFile, ForWriting, True)
Loop
On Error Goto 0
GenerateOutputFilePath = strFile
End Function
Sub GenerateOutput(str, StartNewLine, ByRef Row, ByRef Column, ByRef OutputFilePathOrExcelObject)
If Instr(OutputFilePathOrExcelObject,"\") = 0 Then 'If no "\" are contained then it's not a path
If StartNewLine Then
Row = Row + 1
Column = 1
Else
Column = Column + 1
End If
OutputFilePathOrExcelObject.Cells(Row,Column) = str
OutputFilePathOrExcelObject.Cells(Row,Column).Activate
Else 'OutputFilePathOrExcelObject is the path to a text file
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If Row = 0 Then
Set f = fso.OpenTextFile(OutputFilePathOrExcelObject, ForWriting, True)
Row = 1
Column = 1
f.Write str
Else
Set f = fso.OpenTextFile(OutputFilePathOrExcelObject, ForAppending, True)
If StartNewLine Then
Row = Row + 1
Column = 1
f.Write vbNewLine
Else
Column = Column + 1
End If
If Column > 1 Then
f.Write vbTab & str
Else
f.Write str
End If
End If
End If
End Sub
Function WMIGetNetworkAdapterDescription(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetNetworkAdapterDescription = "Network Adapter Description"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetNetworkAdapterDescription = objItem.Description
Else ' i>1
WMIGetNetworkAdapterDescription = WMIGetNetworkAdapterDescription & ", " & objItem.Description
End If
End If
Next
End Function
Function WMIGetIP(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetIP = "IP Address"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetIP = Join(objItem.IPAddress, ",")
Else ' i>1
WMIGetIP = WMIGetIP & ", " & Join(objItem.IPAddress, ",")
End If
End If
Next
End Function
Function WMIGetGateway(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetGateway = "IP Gateway"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
On Error Resume Next
WMIGetGateway = Join(objItem.DefaultIPGateway, ",")
If Err <> 0 Then
Err.Clear
WMIGetGateway = "-"
End If
On Error Goto 0
Else ' i>1
On Error Resume Next
WMIGetGateway = WMIGetGateway & ", " & Join(objItem.DefaultIPGateway, ",")
If Err <> 0 Then
Err.Clear
WMIGetGateway = WMIGetGateway & ", " & "-"
End If
On Error Goto 0
End If
End If
Next
End Function
Function WMIGetDHCPStatus(ByRef objWMIService)
Dim colItems, objItem, i
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetDHCPStatus = "DHCP Enabled?"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 0
For Each objItem In colItems
If objItem.IPEnabled Then
i = i + 1
If i = 1 Then
WMIGetDHCPStatus = objItem.DHCPEnabled
Else ' i>1
WMIGetDHCPStatus = WMIGetDHCPStatus & ", " & objItem.DHCPEnabled
End If
End If
Next
End Function
Function WMIGetCPUName(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetCPUName = "CPU Name"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetCPUName = objItem.Name
Next
WMIGetCPUName = RegExReplace(WMIGetCPUName, "\s{2,}", "") ' Remove excess white space from CPU name
End Function
Function WMIGetRAM(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetRAM = "RAM (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetRAM = objItem.TotalPhysicalMemory
Next
End Function
Function WMIGetComputerModel(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetComputerModel = "Computer Model"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetComputerModel = objItem.Model
Next
End Function
Function WMIGetComputerName(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetComputerName = "Computer Name"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetComputerName = objItem.Name
Next
End Function
Function WMIGetWindowsVersionAndServicePack(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetWindowsVersionAndServicePack = "Windows Version & Service Pack"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WMIGetWindowsVersionAndServicePack = objItem.Caption & ", " & objItem.CSDVersion
Next
End Function
Function WMIGetHDDCapacity(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetHDDCapacity = "HDD C:\ Capacity (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If objItem.Caption = "C:" Then WMIGetHDDCapacity = objItem.Size
Next
End Function
Function WMIGetHDDFreeSpace(ByRef objWMIService)
Dim colItems, objItem
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetHDDFreeSpace = "HDD C:\ Free Space (bytes)"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If objItem.Caption = "C:" Then WMIGetHDDFreeSpace = objItem.FreeSpace
Next
End Function
Function WMIGetMembersOfAdministratorGroup(ByRef objWMIService)
Dim colItems, objItem, i, str
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
If VarType(objWMIService) <> vbObject Then
WMIGetMembersOfAdministratorGroup = "Local Administrators Group"
Exit Function
End If
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
i = 1
For Each objItem In colItems
If InStr(objItem.GroupComponent, "Administrators") <> 0 Then ' Administrators found!
If i > 1 Then WMIGetMembersOfAdministratorGroup = WMIGetMembersOfAdministratorGroup & ", "
str = Split(objItem.PartComponent, Chr(34), -1, 1)
WMIGetMembersOfAdministratorGroup = WMIGetMembersOfAdministratorGroup & str(1) & "\" & str(3)
i = i + 1
End If
Next
End Function
Function RegExReplace(str, patrn, replStr)
Dim regEx ' Create variables.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Make case insensitive.
RegExReplace = regEx.Replace(str, replStr) ' Make replacement.
End Function
Sub LoadComputers(strTextFilePath)
Dim intResult, objDialog, objOption, fso, objFile, strLine
If strTextFilePath = "" Then
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files|*.txt|All Files|*.*"
objDialog.FilterIndex = 1
intResult = objDialog.ShowOpen
If intResult = 0 Then
Exit Sub
End If
strTextFilePath = objDialog.FileName
End If
For Each objOption in computers_listbox.Options
objOption.RemoveNode
Next
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFile = fso.OpenTextFile(strTextFilePath, ForReading)
If Err = 0 Then
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
computers_listbox.Add(objOption)
Loop
objFile.Close
End If
Err.Clear
On Error Goto 0
End Sub
Sub RunClear
Dim objOption
For Each objOption in computers_listbox.Options
objOption.RemoveNode
Next
End Sub
Sub RunAdd
Dim objOption, input
input = InputBox("Enter the computer name",constProgramTitle)
If input <> "" Then
Set objOption = Document.createElement("OPTION")
objOption.Text = input
objOption.Value = objOption.Text
computers_listbox.Add(objOption)
End If
End Sub
Sub RunSelectComputer
Dim objOption, input
On Error Resume Next
input = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Select a remote computer", 0, "::{208D2C60-3AEA-1069-A2D7-08002B30309D}\EntireNetwork"). _
Self.Name
If Err <> 0 Then
input = ""
Err.Clear
End If
On Error Goto 0
If input <> "" Then
Set objOption = Document.createElement("OPTION")
objOption.Text = input
objOption.Value = objOption.Text
computers_listbox.Add(objOption)
End If
End Sub
Sub RunRemove
Dim objOption
For Each objOption in computers_listbox.Options
If objOption.Selected Then
objOption.RemoveNode
End If
Next
End Sub
Sub TrapEnter
If window.event.Keycode = 13 Then
RunStart()
End If
End Sub
Sub SetTextOutputFormat
Dim RadioButton
For Each RadioButton in outputformat_radiobutton
If RadioButton.Value = "textfile" Then RadioButton.Checked = True
Next
End Sub
Sub RunExit
self.close()
End Sub
</script>
</head>
<body bgcolor="buttonface">
<fieldset id="userdomainpassw">
<legend>User with administrator privileges:</legend>
<ol>
<li><label for="username_textbox">Username:</label>
<input type="text"
id="username_textbox"
onkeypress="TrapEnter" /></li>
<li><label for="domain_textbox">Domain:</label>
<input type="text"
id="domain_textbox"
onkeypress="TrapEnter" /></li>
<li><label for="password_textbox">Password:</label>
<input type="password"
id="password_textbox"
onkeypress="TrapEnter" /></li>
</ol>
</fieldset>
<fieldset id="computerlist">
<legend>Computer list:</legend>
<select id="computers_listbox" size="10"></select>
<ol>
<li><input type="button"
value="Load list..."
title="Load a text file containing a list of computers"
id="LoadComputers_button"
onclick="LoadComputers('')"/></li>
<li><input type="button"
value="Select..."
title="Select a remote computer from a list"
id="SelectComputer_button"
onclick="RunSelectComputer" /></li>
<li><input type="button"
value="Add..."
id="Add_button"
onclick="RunAdd" /></li>
<li><input type="button"
value="Remove"
id="Remove_button"
onclick="RunRemove" /></li>
<li><input type="button"
value="Clear"
id="Clear_button"
onclick="RunClear" /></li>
</ol>
</fieldset>
<fieldset id="outputformat">
<legend>Output format:</legend>
<ol>
<li>
<label><input type="radio"
name="outputformat_radiobutton"
value="textfile" />Text File</label>
<label for="outputfile_textbox"> - Specify filename:</label>
<input type="text"
id="outputfile_textbox"
onkeypress="TrapEnter"
onclick="SetTextOutputFormat"
onfocus="SetTextOutputFormat" />
<p>(The file will be saved on your desktop)</p>
</li>
<li>
<label><input type="radio"
name="outputformat_radiobutton"
value="excelsession"
checked="checked" />Excel Session</label>
</li>
</ol>
</fieldset>
<fieldset id="actionbuttons">
<input type="button"
value="Exit"
id="Exit_button"
onclick="RunExit" />
<input type="button"
value="Start"
id="Start_button"
onclick="RunStart" />
</fieldset>
</body>
</html>