长兴县救护车出租网

vbs查询局域网内电脑的软件和硬件列表清单

2026-04-01 16:14:03 浏览次数:0
详细信息

1. 查询局域网计算机软件硬件信息的VBS脚本

' ================================================
' 局域网计算机信息收集脚本
' 文件名: LAN_Computer_Info.vbs
' 用法: 双击运行或使用 cscript LAN_Computer_Info.vbs
' ================================================

Option Explicit

' 主函数
Main()

Sub Main()
    Dim objShell, objFSO, objFile, strComputer, strOutputFile
    Dim colComputers, strComputerList, arrComputers, i

    ' 创建对象
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' 输出文件
    strOutputFile = "Computer_Inventory_" & Year(Date) & Month(Date) & Day(Date) & ".txt"
    Set objFile = objFSO.CreateTextFile(strOutputFile, True)

    ' 记录开始时间
    objFile.WriteLine "===================== 计算机信息收集报告 ====================="
    objFile.WriteLine "收集时间: " & Now()
    objFile.WriteLine "收集者: " & objShell.ExpandEnvironmentStrings("%USERNAME%")
    objFile.WriteLine "=================================================================" & vbCrLf

    ' 获取计算机名(可以是当前计算机或指定列表)
    strComputer = InputBox("请输入计算机名(用逗号分隔多个,或留空查询本机):", "计算机信息收集")

    If strComputer = "" Then
        ' 查询本机
        strComputer = "."
        ReDim arrComputers(0)
        arrComputers(0) = strComputer
    Else
        ' 解析计算机列表
        arrComputers = Split(strComputer, ",")
    End If

    ' 遍历每台计算机
    For i = 0 To UBound(arrComputers)
        strComputer = Trim(arrComputers(i))
        If strComputer = "." Then
            objFile.WriteLine "【查询本地计算机】"
        Else
            objFile.WriteLine "【查询计算机: " & strComputer & "】"
        End If

        ' 查询硬件信息
        GetHardwareInfo strComputer, objFile, objShell

        ' 查询软件信息
        GetSoftwareInfo strComputer, objFile

        objFile.WriteLine vbCrLf & String(60, "=") & vbCrLf
    Next

    objFile.Close

    MsgBox "信息收集完成!结果已保存到: " & strOutputFile, vbInformation, "完成"

    ' 清理对象
    Set objShell = Nothing
    Set objFSO = Nothing
    Set objFile = Nothing
End Sub

' 获取硬件信息
Sub GetHardwareInfo(strComputer, objFile, objShell)
    On Error Resume Next

    Dim objWMIService, colItems, objItem
    Dim strQuery

    objFile.WriteLine vbCrLf & "====== 硬件信息 ======"

    ' 连接到WMI服务
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    If Err.Number <> 0 Then
        objFile.WriteLine "无法连接到计算机 " & strComputer & "。错误: " & Err.Description
        Exit Sub
    End If

    ' 1. 计算机系统信息
    objFile.WriteLine vbCrLf & "--- 系统信息 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    For Each objItem In colItems
        objFile.WriteLine "计算机名: " & objItem.Name
        objFile.WriteLine "制造商: " & objItem.Manufacturer
        objFile.WriteLine "型号: " & objItem.Model
        objFile.WriteLine "系统类型: " & objItem.SystemType
        objFile.WriteLine "总物理内存: " & FormatNumber(objItem.TotalPhysicalMemory/1073741824, 2) & " GB"
        objFile.WriteLine "用户名: " & objItem.UserName
        objFile.WriteLine "工作组: " & objItem.Domain
    Next

    ' 2. 操作系统信息
    objFile.WriteLine vbCrLf & "--- 操作系统 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
    For Each objItem In colItems
        objFile.WriteLine "操作系统: " & objItem.Caption
        objFile.WriteLine "版本: " & objItem.Version
        objFile.WriteLine "架构: " & objItem.OSArchitecture
        objFile.WriteLine "序列号: " & objItem.SerialNumber
        objFile.WriteLine "安装日期: " & objItem.InstallDate
        objFile.WriteLine "启动时间: " & WMIDateStringToDate(objItem.LastBootUpTime)
    Next

    ' 3. 处理器信息
    objFile.WriteLine vbCrLf & "--- 处理器 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")
    For Each objItem In colItems
        objFile.WriteLine "处理器: " & objItem.Name
        objFile.WriteLine "制造商: " & objItem.Manufacturer
        objFile.WriteLine "核心数: " & objItem.NumberOfCores
        objFile.WriteLine "线程数: " & objItem.NumberOfLogicalProcessors
        objFile.WriteLine "当前时钟: " & objItem.CurrentClockSpeed & " MHz"
        objFile.WriteLine "最大时钟: " & objItem.MaxClockSpeed & " MHz"
    Next

    ' 4. 内存信息
    objFile.WriteLine vbCrLf & "--- 物理内存 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory")
    Dim i, totalRAM
    totalRAM = 0
    i = 1
    For Each objItem In colItems
        objFile.WriteLine "内存条 " & i & ":"
        objFile.WriteLine "  容量: " & FormatNumber(objItem.Capacity/1073741824, 2) & " GB"
        objFile.WriteLine "  速度: " & objItem.Speed & " MHz"
        objFile.WriteLine "  类型: " & objItem.MemoryType
        objFile.WriteLine "  制造商: " & objItem.Manufacturer
        totalRAM = totalRAM + objItem.Capacity
        i = i + 1
    Next
    objFile.WriteLine "总内存: " & FormatNumber(totalRAM/1073741824, 2) & " GB"

    ' 5. 磁盘信息
    objFile.WriteLine vbCrLf & "--- 磁盘驱动器 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
    For Each objItem In colItems
        objFile.WriteLine "磁盘: " & objItem.Model
        objFile.WriteLine "  接口类型: " & objItem.InterfaceType
        objFile.WriteLine "  容量: " & FormatNumber(objItem.Size/1073741824, 2) & " GB"
        objFile.WriteLine "  分区: " & objItem.Partitions
    Next

    ' 6. 网络适配器
    objFile.WriteLine vbCrLf & "--- 网络适配器 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each objItem In colItems
        objFile.WriteLine "适配器: " & objItem.Description
        If IsArray(objItem.IPAddress) Then
            objFile.WriteLine "  IP地址: " & objItem.IPAddress(0)
            If UBound(objItem.IPAddress) > 0 Then
                objFile.WriteLine "  IPv6地址: " & objItem.IPAddress(1)
            End If
        End If
        objFile.WriteLine "  MAC地址: " & objItem.MACAddress
        objFile.WriteLine "  子网掩码: " & objItem.IPSubnet(0)
        objFile.WriteLine "  默认网关: " & objItem.DefaultIPGateway(0)
    Next

    ' 7. 显卡信息
    objFile.WriteLine vbCrLf & "--- 显示适配器 ---"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoController")
    For Each objItem In colItems
        objFile.WriteLine "显卡: " & objItem.Name
        objFile.WriteLine "  显存: " & FormatNumber(objItem.AdapterRAM/1048576, 0) & " MB"
        objFile.WriteLine "  驱动程序: " & objItem.DriverVersion
    Next

    ' 清理WMI对象
    Set colItems = Nothing
    Set objWMIService = Nothing
End Sub

' 获取软件信息
Sub GetSoftwareInfo(strComputer, objFile)
    On Error Resume Next

    Dim objWMIService, colItems, objItem

    objFile.WriteLine vbCrLf & "====== 已安装软件 ======"

    ' 连接到WMI服务
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    If Err.Number <> 0 Then
        objFile.WriteLine "无法连接到计算机 " & strComputer & " 获取软件信息。"
        Exit Sub
    End If

    ' 查询已安装软件
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product ORDER BY Name")

    Dim count
    count = 0
    For Each objItem In colItems
        count = count + 1
        objFile.WriteLine count & ". " & objItem.Name
        objFile.WriteLine "   版本: " & objItem.Version
        objFile.WriteLine "   厂商: " & objItem.Vendor
        objFile.WriteLine "   安装日期: " & Left(objItem.InstallDate, 4) & "-" & Mid(objItem.InstallDate, 5, 2) & "-" & Mid(objItem.InstallDate, 7, 2)
    Next

    objFile.WriteLine vbCrLf & "总计: " & count & " 个已安装程序"

    ' 清理对象
    Set colItems = Nothing
    Set objWMIService = Nothing
End Sub

' WMI日期格式转换
Function WMIDateStringToDate(dtmDate)
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
        Mid(dtmDate, 7, 2) & "/" & _
        Left(dtmDate, 4) & " " & _
        Mid(dtmDate, 9, 2) & ":" & _
        Mid(dtmDate, 11, 2) & ":" & _
        Mid(dtmDate, 13, 2))
End Function

2. 简化版脚本(仅查询局域网内指定计算机)

' 简化的局域网计算机查询脚本
Option Explicit

Dim strComputer
strComputer = InputBox("请输入要查询的计算机名(如: COMPUTER01):", "查询计算机信息")

If strComputer <> "" Then
    ' 使用WMI查询计算机信息
    QueryComputerInfo strComputer
End If

Sub QueryComputerInfo(strComputer)
    Dim objWMIService, colItems, objItem

    On Error Resume Next

    ' 连接远程计算机WMI
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    If Err.Number <> 0 Then
        MsgBox "无法连接到计算机 " & strComputer & vbCrLf & _
               "错误: " & Err.Description, vbCritical, "连接失败"
        Exit Sub
    End If

    ' 查询计算机信息
    Dim strInfo
    strInfo = "计算机名: " & strComputer & vbCrLf & vbCrLf

    ' 系统信息
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    For Each objItem In colItems
        strInfo = strInfo & "系统信息:" & vbCrLf
        strInfo = strInfo & "  型号: " & objItem.Model & vbCrLf
        strInfo = strInfo & "  制造商: " & objItem.Manufacturer & vbCrLf
        strInfo = strInfo & "  内存: " & FormatNumber(objItem.TotalPhysicalMemory/1073741824, 1) & " GB" & vbCrLf & vbCrLf
    Next

    ' 操作系统
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
    For Each objItem In colItems
        strInfo = strInfo & "操作系统:" & vbCrLf
        strInfo = strInfo & "  " & objItem.Caption & vbCrLf
        strInfo = strInfo & "  版本: " & objItem.Version & vbCrLf & vbCrLf
    Next

    ' 处理器
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")
    For Each objItem In colItems
        strInfo = strInfo & "处理器:" & vbCrLf
        strInfo = strInfo & "  " & objItem.Name & vbCrLf & vbCrLf
    Next

    ' IP地址
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each objItem In colItems
        If IsArray(objItem.IPAddress) Then
            strInfo = strInfo & "网络配置:" & vbCrLf
            strInfo = strInfo & "  IP地址: " & objItem.IPAddress(0) & vbCrLf
            strInfo = strInfo & "  MAC地址: " & objItem.MACAddress & vbCrLf
        End If
    Next

    MsgBox strInfo, vbInformation, "计算机信息"

    Set colItems = Nothing
    Set objWMIService = Nothing
End Sub

3. 批量扫描脚本(扫描整个网络段)

' 网络批量扫描脚本
Option Explicit

Dim objFSO, objFile, strOutputFile
Dim i, strComputer, objShell

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

' 创建输出文件
strOutputFile = "Network_Scan_" & Year(Date) & Month(Date) & Day(Date) & ".csv"
Set objFile = objFSO.CreateTextFile(strOutputFile, True)

' CSV标题行
objFile.WriteLine "IP地址,计算机名,操作系统,用户名,内存(GB),在线状态"

' 扫描网络段(修改为您的网络段)
Dim networkPrefix
networkPrefix = "192.168.1."  ' 修改为您网络的IP段

For i = 1 To 254
    strComputer = networkPrefix & i

    ' 使用ping测试连通性
    Dim objPing, strPingResult
    Set objPing = objShell.Exec("ping -n 1 -w 500 " & strComputer)
    strPingResult = objPing.StdOut.ReadAll

    If InStr(strPingResult, "TTL=") > 0 Then
        ' 尝试获取计算机信息
        Dim strInfo
        strInfo = GetBasicInfo(strComputer)
        objFile.WriteLine strInfo
        WScript.Echo "发现: " & strComputer & " - " & Split(strInfo, ",")(1)
    End If

    ' 避免过快扫描
    WScript.Sleep 50
Next

objFile.Close
MsgBox "网络扫描完成!结果保存到: " & strOutputFile, vbInformation, "完成"

Function GetBasicInfo(strIP)
    On Error Resume Next

    Dim objWMIService, colItems, objItem
    Dim strResult, strComputerName, strOS, strUser, strMemory

    strResult = strIP & ",未知,未知,未知,0,在线"

    ' 尝试通过WMI获取信息
    Set objWMIService = GetObject("winmgmts:\\" & strIP & "\root\cimv2")

    If Err.Number = 0 Then
        ' 获取计算机名
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For Each objItem In colItems
            strComputerName = objItem.Name
            strUser = objItem.UserName
            strMemory = FormatNumber(objItem.TotalPhysicalMemory/1073741824, 1)
        Next

        ' 获取操作系统
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
        For Each objItem In colItems
            strOS = objItem.Caption
        Next

        strResult = strIP & "," & strComputerName & "," & strOS & "," & strUser & "," & strMemory & ",在线"
    End If

    GetBasicInfo = strResult
End Function

使用说明:

权限要求:

管理员权限:需要以管理员身份运行脚本 网络权限:需要开启远程WMI访问 防火墙设置:确保目标计算机允许WMI连接

配置目标计算机(如需要):

# 以管理员身份运行CMD,执行以下命令:
wmic /node:"计算机名" /user:"管理员账号" /password:"密码" process call create "cmd.exe"

# 或在组策略中启用:
# 计算机配置 → 管理模板 → Windows组件 → Windows远程管理

运行方式:

将脚本保存为 .vbs 文件 双击运行(图形界面) 或使用命令行:cscript scriptname.vbs

注意事项:

查询远程计算机需要相应的网络权限 某些信息可能需要UAC提升 建议在域环境下使用,权限管理更方便

这个脚本可以查询以下信息:

您可以根据需要修改脚本,添加更多查询项目或调整输出格式。

相关推荐