123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- GenerateHostsFile()
- '------------------------------------------------------------
- ' Generate the myhostids.txt file.
- '------------------------------------------------------------
- Function GenerateHostsFile()
- ScriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
- RlmUtilExe = """" & ScriptPath & "rlmutil.exe"""
-
- 'Get info needed to create host file.
- DiskID = MakeSafeXmlText(Trim(RunExe(RlmUtilExe & " rlmhostid -q -32")))
- Ether = MakeSafeXmlText(Trim(RunExe(RlmUtilExe & " rlmhostid -q ether")))
- User = MakeSafeXmlText(RemoveJunk(RunExe(RlmUtilExe & " rlmhostid -q user")))
- Host = MakeSafeXmlText(RemoveJunk(RunExe(RlmUtilExe & " rlmhostid -q host")))
-
- 'Make queries for system information.
- Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set colProcessorInfo = objWMIService.ExecQuery("Select * from Win32_Processor")
- Set colComputerInfo = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
- Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
- Set colVideoController = objWMIService.ExecQuery("Select * from Win32_VideoController",,48)
- Set colDisplayConfig = objWMIService.ExecQuery("Select * from Win32_DisplayConfiguration")
- Set colDesktopMonitor = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
- Set colControllerConfig = objWMIService.ExecQuery("Select * from Win32_DisplayControllerConfiguration")
- 'Echo the myhostids.txt file.
- Wscript.echo "<hostid>"
- Wscript.echo " <disk>" & DiskID & "</disk>"
- Wscript.echo " <ether>" & Ether & "</ether>"
- Wscript.echo " <user>" & User & "</user>"
- Wscript.echo " <host>" & Host & "</host>"
- Wscript.echo " <platform>" & GetOSName(colOSes) & " " & GetSpNumber(colOSes) & "</platform>"
- Wscript.echo " <langCode>" & GetLanguage() & "</langCode>"
- Wscript.echo " <VideoMemory>" & MakeSafeXmlText(GetVideoCardMemory(colVideoController)) & "</VideoMemory>"
- Wscript.echo " <DeviceName>" & MakeSafeXmlText(GetVideoCardDeviceName(colDisplayConfig)) & "</DeviceName>"
- Wscript.echo " <DriverVersion>" & MakeSafeXmlText(GetVideoCardDriverVersion(colDisplayConfig)) & "</DriverVersion>"
- Wscript.echo " <Resolution>" & MakeSafeXmlText(GetDisplayResolution(colDesktopMonitor)) & "</Resolution>"
- Wscript.echo " <BitsPerPixel>" & MakeSafeXmlText(GetDisplayBitsPerPixel(colControllerConfig)) & "</BitsPerPixel>"
- Wscript.echo " <ProcessorName>" & MakeSafeXmlText(GetProcessorName(colProcessorInfo)) & "</ProcessorName>"
- Wscript.echo " <PhysicalProcessors>" & MakeSafeXmlText(GetPhysicalProcessors(colComputerInfo)) & "</PhysicalProcessors>"
- Wscript.echo " <Cores>" & MakeSafeXmlText(GetProcessorCores(colProcessorInfo)) & "</Cores>"
- Wscript.echo " <LogicalProcessors>" & MakeSafeXmlText(GetLogicalProcessors(colProcessorInfo)) & "</LogicalProcessors>"
- Wscript.echo " <ClockSpeed>" & MakeSafeXmlText(GetProcessorClockSpeed(colProcessorInfo)) & "</ClockSpeed>"
- Wscript.echo " <Architecture>" & MakeSafeXmlText(GetProcessorArchitecture(colProcessorInfo)) & "</Architecture>"
- Wscript.echo " <BusSpeed>" & MakeSafeXmlText(GetProcessorBusSpeed(colProcessorInfo)) & "</BusSpeed>"
- Wscript.echo " <Manufacturer>" & MakeSafeXmlText(GetProcessorManufacturer(colProcessorInfo)) & "</Manufacturer>"
- Wscript.echo "</hostid>"
- End Function
- '------------------------------------------------------------
- ' Get the operating system's name.
- '------------------------------------------------------------
- Function GetOSName(colOSes)
- For Each objOS in colOSes
- 'Windows 2000
- If (InStr(ObjOS.Caption, "2000") <> 0) Then
- StrOsVer = "Win2K"
- 'Windows XP
- ElseIf ( InStr(objOS.Caption, "XP") <> 0) Then
- If ( InStr(objOS.Caption, "x64") <> 0) Then
- StrOsVer = "WinXP_x64"
- Else
- StrOsVer = "WinXP_x86"
- End If
- Else
- 'Vista
- If (InStr(ObjOS.Caption, "Vista") <> 0) Then
- StrOsVer = "Vista"
-
- 'Windows 7
- ElseIf (InStr(ObjOS.Caption, "Windows 7") <> 0) Then
- StrOsVer = "Win7"
- 'Windows 8.1 (This must be before 8)
- ElseIf (InStr(ObjOS.Caption, "Windows 8.1") <> 0) Then
- StrOsVer = "Win8.1"
- 'Windows 8
- ElseIf (InStr(ObjOS.Caption, "Windows 8") <> 0) Then
- StrOsVer = "Win8"
- End If
- If (IsEmpty(StrOsVer)) Then
- 'Unknown OS.
- StrOsVer = ObjOS.Caption & ", " & objOS.OSArchitecture
- Else
- 'Append the architecture.
- If ( InStr(objOS.OSArchitecture, "64") <> 0) Then
- StrOsVer = StrOsVer & "_x64"
- Else
- StrOsVer = StrOsVer & "_x86"
- End If
- End If
- End If
- Next
-
- GetOSName = StrOsVer
- End Function
- '------------------------------------------------------------
- ' Get the OS Service Pack Number.
- '------------------------------------------------------------
- Function GetSpNumber(colOSes)
- For Each objOperatingSystem in colOSes
- major = objOperatingSystem.ServicePackMajorVersion
- minor = objOperatingSystem.ServicePackMinorVersion
- Next
-
- If (Major=0) Then
- strSPnum = "RTM"
- Else
- strSPnum = "SP" & major
- End If
- GetSpNumber = strSPnum
- End Function
- '------------------------------------------------------------
- ' Get the OS language.
- '------------------------------------------------------------
- Function GetLanguage()
- set osvc = GetObject("winmgmts:")
- For each objOS in osvc.instancesof("win32_operatingsystem")
- LangCode = objOS.OSLanguage
- Next
- Select Case LangCode
- Case 1025
- strCountry= "AR" 'Arabic
- Case 1028
- strCountry= "ZHTW" 'Chinese
- Case 2052
- strCountry= "ZHCN" 'Chinese (Simplified)
- Case 3076
- strCountry= "ZHHK" 'Chinese (Hong Kong)
- Case 1029
- strCountry= "CS" 'CZech
- Case 1030
- strCountry= "DA" 'Danish
- Case 1031
- strCountry= "DE" 'German
- Case 1032
- strCountry= "EL" 'Greek
- Case 1033
- strCountry= "EN" 'English (US)
- Case 1034
- strCountry= "ES" 'Spanish
- Case 1035
- strCountry= "FI" 'Finnish
- Case 1036
- strCountry= "FR" 'French
- Case 1037
- strCountry= "HE" 'Hebrew
- Case 1039
- strCountry= "HU" 'Hungarian
- Case 1040
- strCountry= "IT" 'Italian
- Case 1041
- strCountry= "JA" 'Japanese
- Case 1042
- strCountry= "KO" 'Korean
- Case 1043
- strCountry= "NL" 'Dutch
- Case 1044
- strCountry= "NO" 'Norwegian
- Case 1045
- strCountry= "PL" 'Polish
- Case 1046
- Case 1070
- strCountry= "PT" 'Portuguese
- Case 1049
- strCountry= "RU" 'Russian
- Case 1053
- strCountry= "SV" 'Swedish
- Case 1054
- strCountry= "TH" 'Thai
- Case 1055
- strCountry= "TR" 'Turkish
- Case Else
- strCountry = "UnknownLanguage"
- End Select
- GetLanguage = strCountry
- End Function
- '------------------------------------------------------------
- ' Get video card information.
- '------------------------------------------------------------
- Function GetVideoCardMemory(colVideoController)
- If CollectionHasItems(colVideoController) Then
- For Each objItem in colVideoController
- VideoCardInfo = FormatNumber(RetrieveProperty("objItem.AdapterRAM")/1024\1024, 0) & " MB"
- Next
- End If
- GetVideoCardMemory = SetToUnknownIfEmpty(VideoCardInfo)
- End Function
- Function GetVideoCardDeviceName(colDisplayConfig)
- If CollectionHasItems(colDisplayConfig) Then
- For Each objItem in colDisplayConfig
- VideoCardInfo = RetrieveProperty("objItem.DeviceName")
- Next
- End If
- GetVideoCardDeviceName = SetToUnknownIfEmpty(VideoCardInfo)
- End Function
- Function GetVideoCardDriverVersion(colDisplayConfig)
- If CollectionHasItems(colDisplayConfig) Then
- For Each objItem in colDisplayConfig
- VideoCardInfo = RetrieveProperty("objItem.DriverVersion")
- Next
- End If
- GetVideoCardDriverVersion = SetToUnknownIfEmpty(VideoCardInfo)
- End Function
- Function GetDisplayResolution(colDesktopMonitor)
- If CollectionHasItems(colDesktopMonitor) Then
- For Each objItem in colDesktopMonitor
- If (Not IsEmpty(objItem.ScreenWidth) And Not IsEmpty(objItem.ScreenHeight)) Then
- VideoCardInfo = RetrieveProperty("objItem.ScreenWidth") & "x" & RetrieveProperty("objItem.ScreenHeight")
- End If
- Next
- End If
- GetDisplayResolution = SetToUnknownIfEmpty(VideoCardInfo)
- End Function
- Function GetDisplayBitsPerPixel(colControllerConfig)
- If CollectionHasItems(colControllerConfig) Then
- For Each objItem in colControllerConfig
- VideoCardInfo = RetrieveProperty("objItem.BitsPerPixel")
- Next
- End If
- GetDisplayBitsPerPixel = SetToUnknownIfEmpty(VideoCardInfo)
- End Function
- '------------------------------------------------------------
- ' Get processor information.
- '------------------------------------------------------------
- Function GetProcessorName(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcName = replace(objItem.Name, " ", " ")
- ProcName = replace(ProcName, "(TM)","")
- ProcName = replace(ProcName, "(R)","")
- ProcessorInfo = ProcName
- Next
- End If
- GetProcessorName = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetPhysicalProcessors(colComputerInfo)
- For Each objItem in colComputerInfo
- ProcessorInfo = RetrieveProperty("objItem.NumberOfProcessors")
- Next
- GetPhysicalProcessors = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetProcessorCores(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.NumberOfCores")
- Next
- End If
- GetProcessorCores = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetLogicalProcessors(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.NumberOfLogicalProcessors")
- Next
- End If
- GetLogicalProcessors = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetProcessorClockSpeed(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.MaxClockSpeed")
- Next
- End If
- GetProcessorClockSpeed = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetProcessorArchitecture(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.AddressWidth")
- Next
- End If
- GetProcessorArchitecture = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetProcessorBusSpeed(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.ExtClock")
- Next
- End If
- GetProcessorBusSpeed = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- Function GetProcessorManufacturer(colProcessorInfo)
- If (CollectionHasItems(colProcessorInfo)) Then
- For Each objItem in colProcessorInfo
- ProcessorInfo = RetrieveProperty("objItem.Manufacturer")
- Next
- End If
- GetProcessorManufacturer = SetToUnknownIfEmpty(ProcessorInfo)
- End Function
- '------------------------------------------------------------
- ' Make sure a collection has accessible items in it.
- '------------------------------------------------------------
- Function CollectionHasItems(SomeCollection)
- On Error Resume Next
- CollectionHasItems = SomeCollection.Count
- If (Err.Number <> 0) Then
- CollectionHasItems = False
- Else
- CollectionHasItems = True
- End If
- On Error Goto 0
- End Function
- '------------------------------------------------------------
- ' Retrieve a property of an object or return an Empty value.
- '------------------------------------------------------------
- Function RetrieveProperty(ObjectProperty)
- On Error Resume Next
- RetrieveProperty = Eval(ObjectProperty)
- On Error Goto 0
- End Function
- '------------------------------------------------------------
- ' Strip off any garbage that rlmutil may output.
- ' EG:
- ' rlmutil.exe -rlmhostid -q internet
- ' outputs 'ip=xxx.xxx.xxx.xxx'. This function will
- ' strip the garbage so it returns the ip address part.
- '------------------------------------------------------------
- Function RemoveJunk(SomeString)
- TokenArray = Split(Trim(SomeString), " ")
- For ElemNum = 0 to UBound(TokenArray)
- StrLen = Len(TokenArray(ElemNum))
- EqualLoc = InStr(TokenArray(ElemNum), "=")
- TokenArray(ElemNum) = Trim(Right(TokenArray(ElemNum), StrLen - EqualLoc))
- Next
- RemoveJunk = Join(TokenArray)
- End Function
- '------------------------------------------------------------
- ' If the variable is empty, set it to "Unknown"
- '------------------------------------------------------------
- Function SetToUnknownIfEmpty(Data)
- If (IsEmpty(Data)) Then
- Data = "Unknown"
- End If
- SetToUnknownIfEmpty = Data
- End Function
- '------------------------------------------------------------
- ' The following characters aren't allowed
- ' in XML data:
- ' < > " ' &
- '
- ' This method determines if one of these invalid characters
- ' is contained in the value passed in and if so it wraps
- ' the string in a CDATA node to make the string valid XML data.
- '------------------------------------------------------------
- Function MakeSafeXmlText(SomeString)
- ContainsInvalidChars = false
- If (InStr(SomeString, "<") > 0) Then
- ContainsInvalidChars = true
- End If
- If (InStr(SomeString, """") > 0) Then
- ContainsInvalidChars = true
- End If
- If (InStr(SomeString, "'") > 0) Then
- ContainsInvalidChars = true
- End If
- If (InStr(SomeString, "&") > 0) Then
- ContainsInvalidChars = true
- End If
-
- If (ContainsInvalidChars = true) Then
- 'It is pretty unlikely that the string will already
- 'contain a CDATA node but remove it if it does.
- If (InStr(SomeString, "<![CDATA[")) Then
- SomeString = Replace(SomeString, "<![CDATA[", "")
- End If
- If (InStr(SomeString, "]]>")) Then
- SomeString = Replace(SomeString, "]]>", "")
- End If
-
- result = "<![CDATA[" & SomeString & "]]>"
- Else
- result = SomeString
- End If
-
- MakeSafeXmlText = result
- End Function
- '------------------------------------------------------------
- ' Execute a file and return the output from standard out.
- '------------------------------------------------------------
- Function RunExe(ExeFilePlusArgs)
- Set WshShell = CreateObject("WScript.Shell")
- Set oExec = WshShell.Exec(ExeFilePlusArgs)
-
- Do While (oExec.Status = 0)
- 'Do Nothing here
- Loop
-
- RunExe = oExec.StdOut.ReadLine()
- End Function
|