易语言利用WMI取磁盘信息源码

文章目录[隐藏]

511遇见

用WMI对象列出系统所有进程:
----Instance.vbs----

Dim WMI,objs
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_Process")
For Each obj In objs
Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10)
Next
msgbox Enum1
获得物理内存的容量:
-----physicalMemory.vbs-----

strComputer = "."

Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

For Each wbemObject In wbemObjectSet
WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)
Next
取得系统所有服务及运行状态
----service.vbs----

Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")
Dim s,infor
infor=""
for each s in ServiceSet
infor=infor+s.Description+" ==> "+s.State+chr(13)+chr(10)
next
msgbox infor

用WMI对象列出系统所有进程:
----Instance.vbs----

Dim WMI,objs
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_Process")
For Each obj In objs
Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10)
Next
msgbox Enum1
获得物理内存的容量:
-----physicalMemory.vbs-----

strComputer = "."

Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

For Each wbemObject In wbemObjectSet
WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)
Next
取得系统所有服务及运行状态
----service.vbs----

Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")
Dim s,infor
infor=""
for each s in ServiceSet
infor=infor+s.Description+" ==> "+s.State+chr(13)+chr(10)
next
msgbox infor

CPU的序列号:
---CPUID.vbs---

Dim cpuInfo
cpuInfo = ""
set moc = GetObject("Winmgmts:").InstancesOf("Win32_Processor")
for each mo in moc
cpuInfo = CStr(mo.ProcessorId)
msgbox "CPU SerialNumber is : " & cpuInfo
next
硬盘型号:
---HDID.vbs---

Dim HDid,moc
set moc =GetObject("Winmgmts:").InstancesOf("Win32_DiskDrive")
for each mo in moc
HDid = mo.Model
msgbox "硬盘型号为:" & HDid
next

网卡MAC物理地址:
---MACAddress.vbs---

Dim mc
set mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
for each mo in mc
if mo.IPEnabled=true then
msgbox "网卡MAC地址是: " & mo.MacAddress
exit for
end if
next

测试你的显卡:
On Error Resume Next
Dim ye
Dim yexj00
set yexj00=GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_VideoController")
for each ye in yexj00
msgbox " 型 号: " & ye.VideoProcessor & vbCrLf & " 厂 商: " & ye.AdapterCompatibility & vbCrLf & " 名 称: " & ye.Name & vbCrLf & " 状 态: " & ye.Status & vbCrLf & " 显 存: " & (ye.AdapterRAM\1024000) & "MB" & vbCrLf & "驱 动 (dll): " & ye.InstalledDisplayDrivers & vbCrLf & "驱 动 (inf): " & ye.infFilename & vbCrLf & " 版 本: " & ye.DriverVersion
next

易语言实现

1、声明一个常量GetDiskList

Function GetDiskList()
Dim i, RetStr, wmiObjSet, obj
    'On Local Error Resume Next
    Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_DiskDrive ")
    For Each obj In wmiObjSet
            i = i + 1
            RetStr = RetStr & "序号:" & Cstr(i) & vbCrLf
            RetStr = RetStr & "标题:" & obj.Caption & vbCrLf
            RetStr = RetStr & "描述:" & obj.Description & vbCrLf
            RetStr = RetStr & "分区:" & obj.Partitions & vbCrLf
            RetStr = RetStr & "容量:" & obj.Size & vbCrLf & vbCrLf
    Next
GetDiskList = RetStr
End Function

2、封装

.版本 2
 
.子程序 取硬盘列表, 文本型, 公开
.局部变量 Script, 对象
.局部变量 ret, 文本型
 
Script.创建 (“MSScriptControl.ScriptControl, )
Script.写属性 (“Language”, “VBScript”)
Script.数值方法 (“AddCode”, #GetDiskList)
ret = Script.通用方法 (“Eval”, “GetDiskList()).取文本 ()
返回 (ret)

根据上面的代码,我们可以灵活的取读写底层硬件信息。


发布日期:

所属分类: 编程 标签:  


没有相关文章!