Use vbs to obtain computer hardware information. Page 1/4 of the latest version

Source: Internet
Author: User

'*************************************** **************************************** ************
'Version: 3.1
'Adjust the error handling method and output the error information to the LogFile file. You can view the cause of scan failure.
'If the error "RPC server unavailable" occurs, it is because the remote host is not started.
'If there is an error other than "RPC server unavailable", it may be caused by a running program. Please tell me this information.
'After restarting, scan again to exclude non-"RPC server unavailable ." Error
'If the scanned hardware information is empty, it should be a driver problem (or the BIOS is not complete). Please resolve it yourself
'Version: 3.0
'Add the release date of the output BIOS and put it together with the motherboard information.
'Version: 2.9
'Correct the processing method for all GetInfo errors to avoid the returned array limit being inconsistent with the output requirements and causing the script to report an error.
'The cause is that the Win32 class fails to retrieve hardware or connect to the Win32 class;
'The previous judge whether Err exists, ignoring the case where the hardware cannot be retrieved (if the connection is successful, there is no Err, and the Count is 0)
'The majority of hardware cannot be retrieved because the driver is not installed.
'Version: 2.8
'Added the GetIDEProtocol process to obtain the protocol used by the IDE controller, but added the code without calling
'The process of searching other memory controllers is planned to be increased
'Version: 2.7
'Added the DeviceID attribute (device identifier) During hard disk/video card/NIC/sound card retrieval)
'This attribute is not output and used for internal script judgment.
'Version: 2.6
'The first hard disk found in the original output
'Output the information of the first hard disk whose InterfaceType attribute is IDE.
'Version: 2.5
'Add the Sort process and Sort hardware information
'Version: 2.4
'Adjust the classification of output information. If possible, only one comma is used to separate the same type of information, so that the imported xls is in the same column.
'If the queried hardware information is null or 0, the information may be incomplete or undefined, or the driver is not installed.
'The WMI query indicates that the system knows the detailed information about these hardware. If no information is found, the system does not know the hardware information.
'The system does not know the detailed information about the hardware, which indicates that the performance may be missing. We recommend that you find a driver for installation.
'The main board driver is worth noting.
'(The upgrade information of this version has been edited for ease of understanding)
'Version: 2.3
'Cancel Version 2.2 and add the output hard disk interface type
'The STAT is also attributed to the IDE interface, which leads to misunderstanding
'Ps: the script only outputs the first hard disk to be searched.
'Version: 2.2
The MemoryType, FormFactor, and TypeDetail attributes are added to the 'getmemoryinfo 'process.
'Memory type and encapsulation type are added to the output.
'Increase hard disk capacity and interface type in output
'Version: 2.1
The 'getosinfo process adds the Code to remove the comma "," contained in the Caption attribute.
'Cause: the Caption attribute read when detecting the 2003 system, with a comma ","
'This will affect the output, because the output is separated by commas (,).
'Version: 2.0 B5 release
The 'getnetworkinfo process is changed to use the MACAddress attribute,
The 'manufacturer attribute is not "Microsoft" to determine the NIC
'Version: 2.0 Beta4
The 'getnetworkinfo' process uses the NetConnectionStatus attribute to determine the network adapter.
The 'netconnectionstatus Property indicates the connection status (2000 the system does not support this property)
'The physical network adapter has this status (including the disabled status)
'Version: 2.0 Beta3
'Getnetworkinfo process adds a judgment
'When IPAddress (0) is read, The Err type data adapter is generated (combat platform)
'Version: 2.0 Beta2
The Name and ServicePackMajorVersion attributes used in the 'getosinfo' Process
'Use the Caption and CSDVersion attributes instead.
'Add error handling code for all GetInfo processes to avoid Scanning
'The script exits due to a running error.
'Version: 2.0 Beta1
'Add scan failure records, run the script again to read only failure records, and ignore configuration information.
'Version: 1.1
'Getnetworkinfo process adds a judgment
'Ignore the adapter whose NetConnectionID attribute (interface name) is null
'Version: 1.0
'Initial version

Option Explicit
'**************************************
'Author: LZ-MyST QQ: 8450919
'Http: // hi.baidu.com/lzmyst
'Http: // www.clxp.net.cn
'E-mail: lzmyst@163.com
'You can edit or reference all or part of the script code at will.
'Copyright is reserved for all or part of the code for pasting or referencing scripts.
'**************************************

***** ********************************
'Input format: Start IP address-quantity = user name = password; Start computer name-quantity = user name = Password
'Separate multiple configuration items ';'
'Example: 192.168.0.1-10 indicates that the IP address range is 192.168.0.1 ~ 192.168.0.10, supporting cross-network segments
'Example: The PC001-10 specified range is PC001 ~ PC010 (the computer name can contain a-number)
'The format is different from the specified one. The default format is single IP [computer name]. You can also configure it in "unscanned computer .txt ".
'"Hardware information .txt" is separated by commas (,). You need to import XLS to sort and streamline the hardware information.
'The unscanned computer will save the host number, user name, and password to "unscanned computer .txt"
'Running the script again will only read the information in "unscanned computer .txt" (if the script exists and the size is not 0)
***** ********************************

Dim Input, InfoOutFile, and LogFile assign values to Input according to the format
'Input = "pc021 = administrator = cylslynetbar"
Input = "PC001-109 = administrator = cylslynet bar; pc110-85 = administrator = LYjfnetbaradmin"
InfoOutFile = "hardware information .txt"
LogFile = "unscanned computer .txt"

Redim arrConfig (0)
Dim WshShell, FSO, intCount1, intCount2
IntCount1 = 0
IntCount2 = 0
Set WshShell = WScript. CreateObject ("WScript. Shell ")
Set FSO = WScript. Createobject ("Scripting. Filesystemobject ")
ReadConfig
WshShell. Popup "the scan process will be slow. Please wait patiently. After the scan is completed, a prompt will be displayed,", "scan started"
LinkRemoteServer arrConfig
Dim LenNum1, LenNum2
If intCount1> intCount2 Then
LenNum1 = 0
LenNum2 = Len (intCount1)-Len (intCount2)
Else
LenNum1 = Len (intCount2)-Len (intCount1)
LenNum2 = 0
End If
Sort InfoOutFile
WshShell. Popup "scan result :"&_
VbCrLf & vbTab & "Scan successful:" & Space (LenNum1) & intCount1 & ""&_
VbCrLf & vbTab & "Scan failed:" & Space (LenNum2) & intCount2 & ""&_
VbCrLf & "the computer that failed to scan has been recorded, run the script again to scan only the computer in the record", "Scan completed"

Function ReadConfig
Dim objMatches, objMatche, objLogFile, arrLog, intUBarrConfig
If FSO. FileExists (LogFile) Then
If FSO. GetFile (LogFile). Size = 0 Then
Set objMatches = GetMatche ("([^; =] +) = ([^; =] +) = ([^; =] +)", Input)
For Each objMatche In objMatches
GetConfig objMatche. SubMatches (0), objMatche. SubMatches (1), objMatche. SubMatches (2)
Next
If objMatches. Count = 0 Then
Msgbox "Incorrect configuration information format, Please modify"
WScript. Quit
End If
Else
Set objLogFile = FSO. OpenTextFile (LogFile)
Do Until objLogFile. AtEndOfStream
ArrLog = Split (objLogFile. ReadLine, "= ")
IntUBarrConfig = (Ubound (arrConfig) + 1) \ 3 + 1) * 3-1
Redim Preserve arrConfig (intUBarrConfig)
ArrConfig (intUBarrConfig-2) = arrLog (0)
ArrConfig (intUBarrConfig-1) = arrLog (1)
ArrConfig (intUBarrConfig-0) = arrLog (2)
Loop
End If
Else
Set objMatches = GetMatche ("([^; =] +) = ([^; =] +) = ([^; =] +)", Input)
For Each objMatche In objMatches
GetConfig objMatche. SubMatches (0), objMatche. SubMatches (1), objMatche. SubMatches (2)
Next
If objMatches. Count = 0 Then
Msgbox "Incorrect configuration information format, Please modify"
WScript. Quit
End If
End If
End Function

'*************************************** **************************************** **
'Purpose: to connect to the WMI namespace of the remote host
'Input: arrArray, including the computer name [IP], user name, and password
'Call: LinkServer Process
'If the instance of the SWbemLocator object ConnectServer method is returned, the OutInfo process is called.
'If the returned Err information (string type), output the computer name [IP], user name, password, and error information to the LogFile File
'Outinfo Process
'If the returned Err information (string type) is used to output the computer name [IP], user name, password, and error message to the LogFile
'Transfer: the instance of the SWbemLocator object ConnectServer method is passed to OutInfo.
'Computer name [IP], namespace, user name, and password passed to LinkServer
'*************************************** **************************************** **
Function LinkRemoteServer (arrArray)
Dim objErrLog, E, objLinkServer, objConnection, objWbemLocator, objErr
Set objWbemLocator = CreateObject ("WbemScripting. SWbemLocator ")
Set objErrLog = FSO. CreateTextFile (LogFile, True)
For E = 0 To Ubound (arrArray) Step 3
Set objLinkServer = LinkServer (arrConfig (E), "root \ cimv2", arrConfig (E + 1), arrConfig (E + 2 ))
If Err Then
ObjErrLog. Writeline arrArray (E) & "=" & arrArray (E + 1) & "=" & arrArray (E + 2) & "= "&_
"Error No.:" & CStr (Err. Number )&_
", Error cause:" & CStr (Err. Description )&_
", Error Source:" & CStr (Err. Source) & "By LinkServer Function"
IntCount2 = intCount2 + 1
Err. Clear
Else
ObjErr = OutInfo (objLinkServer)
If Vartype (objErr) = 8 Then
ObjErrLog. Writeline arrArray (E) & "=" & arrArray (E + 1) & "=" & arrArray (E + 2) & "=" & objErr
IntCount2 = intCount2 + 1
End If
End If
Next
End Function

'*************************************** ***************
'Purpose: to output hardware information
'Input: instance of the SWbemLocator object ConnectServer Method
'Call: GetXXXInfo process for obtaining hardware information
'Transfer: instance of the SWbemLocator object ConnectServer Method
'Return: If the Err Object is not returned for all GetInfo calls, True is returned.
'If an Err Object is returned during a GetInfo process, False is returned.
'*************************************** ***************
Function OutInfo (objRemote)
Dim OutFile, arrInfo, strOutInfo, Tmp,
If FSO. FileExists (InfoOutFile) Then
Set OutFile = FSO. OpenTextFile (InfoOutFile, 8)
Else
Set OutFile = FSO. CreateTextFile (InfoOutFile)
OutFile. writeline "computer name, system (initial installation date), motherboard model (vendor) (release date), CPU model (interface type), external frequency, L2 capacity (speed ),"&_
"Total memory, memory speed (location), memory type (encapsulation type), hard disk model (capacity), graphics card model (video memory), Nic, IP/MAC"
End If
'System
ArrInfo = GetOSInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = arrInfo (0) & "," & arrInfo (1) & "(" & arrInfo (2 )&"),"
'Motherboard
ArrInfo = GetBoardInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = strOutInfo & arrInfo (0) & "(" & arrInfo (1 )&")"
'Bios
ArrInfo = GetBIOSInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = strOutInfo & "(" & arrInfo (2 )&"),"
'Cpu
ArrInfo = GetCPUInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = strOutInfo & arrInfo (1) & "(" & arrInfo (8) & ")," & arrInfo (4 )&","&_
ArrInfo (6) & "(" & arrInfo (7 )&"),"
'Memory
ArrInfo = GetMemoryInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
Tmp = 0
For A = 1 To Ubound (arrInfo) Step 6
Tmp = Tmp + Cint (arrInfo ())
Next
StrOutInfo = strOutInfo & arrInfo (0) & "entries, total" & Tmp & "M ,"
Tmp = ""
For A = 2 To Ubound (arrInfo) Step 6
If A = Ubound (arrInfo)-4 Then
Tmp = Tmp & arrInfo (A) & "(" & arrInfo (A + 1 )&"),"
Else
Tmp = Tmp & arrInfo (A) & "(" & arrInfo (A + 1 )&")"
End If
Next
StrOutInfo = strOutInfo & Tmp
Tmp = ""
For A = 4 To Ubound (arrInfo) Step 6
If A = Ubound (arrInfo)-2 Then
Tmp = Tmp & arrInfo (A) & "(" & arrInfo (A + 1 )&"),"
Else
Tmp = Tmp & arrInfo (A) & "(" & arrInfo (A + 1 )&")"
End If
Next
StrOutInfo = strOutInfo & Tmp
'Hard Disk
Tmp = ""
ArrInfo = GetDiskInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
For A = 1 To Ubound (arrInfo) Step 5
If arrInfo (A + 1) = "IDE" Then
Tmp = arrInfo (A) & "(" & arrInfo (A + 2) & "G ),"
Exit
End If
Next
If Tmp = "" Then
StrOutInfo = strOutInfo & "Hard Disk Model not retrieved ,"
Else
StrOutInfo = strOutInfo & Tmp
End If
'Graphics card
ArrInfo = GetVideoInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = strOutInfo & arrInfo (0) & "(" & arrInfo (1) & "M ),"
'Network card
ArrInfo = GetNetworkInfo (objRemote)
If Vartype (arrInfo) = 8 Then
OutInfo = arrInfo
Exit Function
End If
StrOutInfo = strOutInfo & arrInfo (1) & "," & arrInfo (2) & Space (17-Len (arrInfo (2) & arrInfo (3)
'Output
OutFile. Writeline strOutInfo
IntCount1 = intCount1 + 1
OutInfo = True
End Function

'*************************************** ******************
'Purpose: to connect to the WMI namespace of the remote host
'Input: strComputer: The computer name or IP address of the remote host
'Strnamespace: Command Space
'Strusername: User Name
'Strpassword: Password
'Return: Connection successful. Return the instance of the object after the SWbemLocator class is connected to the remote host.
'Connection failed, error object returned
'*************************************** ******************
Function LinkServer (strComputer, strNamespace, strUserName, strPassword)
Dim objWbemLocator
Set objWbemLocator = CreateObject ("WbemScripting. SWbemLocator ")
Dim objConnection
On Error Resume Next
Set objConnection = objwbemLocator. ConnectServer _
(StrComputer, strNamespace, strUserName, strPassword)
If Err Then
Set LinkServer = Err
Exit Function
End If
On Error Goto 0
ObjConnection. Security _. ImpersonationLevel = 3
Set LinkServer = objConnection
End Function

'*************************************** ***
'Purpose: Regular Expression
'Input: strPatrn: Regular Expression Pattern
'Strstring: string of the regular expression to be executed
'Return: Match object
'*************************************** ***
Function GetMatche (strPatrn, strString)
Dim RegEx
Set RegEx = New Regexp
RegEx. Global = True
RegEx. IgnoreCase = True
RegEx. Pattern = strPatrn
Set GetMatche = RegEx. Execute (strString)
End Function

'***************************************
'Objective: to convert hexadecimal 2, 8, and 16 to hexadecimal 10
'Input: strString: 2, 8, hexadecimal number
'Intnum: hexadecimal (2 | 8 | 16)
'Return value: decimal number
'***************************************
Function ChangeToDecimal (strString, intNum)
ChangeToDecimal = 0
If Isnull (strString) Then ChangeToDecimal = 0: Exit Function
Dim A, M
For A = 1 To Len (strString)
M = LCase (Mid (strString, A, 1 ))
Select Case M
Case "a": M = 10
Case "B": M = 11
Case "c": M = 12
Case "d": M = 13
Case "e": M = 14
Case "f": M = 15
End Select
ChangeToDecimal = ChangeToDecimal + M * intNum ^ (Len (strString)-)
Next
End Function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.