用vbs实现判断计算机是笔记本还是台式机的代码
程序员文章站
2022-07-04 20:40:46
chassistypes 属性可以告诉您,您使用的是笔记本电脑、台式计算机还是其他类型的计算机。哦,输入。以下脚本可以让您知道您使用的是哪种类型的计算机: 复制代...
chassistypes 属性可以告诉您,您使用的是笔记本电脑、台式计算机还是其他类型的计算机。哦,输入。以下脚本可以让您知道您使用的是哪种类型的计算机:
strcomputer = "."
set objwmiservice = getobject("winmgmts:" _
& "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
set colchassis = objwmiservice.execquery _
("select * from win32_systemenclosure")
for each objchassis in colchassis
for each strchassistype in objchassis.chassistypes
wscript.echo strchassistype
next
next
好吧,以上脚本只是在一定程度上让您知道您使用的是哪种类型的计算机。实际上,chassistype 属性返回的是一个数字,这就是说当我们在面前的计算机上运行这个脚本时,我们将得到 10。那么,什么是 10 呢?根据wmi sdk,它指的是笔记本计算机。猜一猜会发生什么呢?没错!
但您并不必每次检查计算机类型时都参考 sdk。以下经过扩展的脚本使用一个 select case 语句,它可将这些整数转换为更有意义的内容:
strcomputer = "."
set objwmiservice = getobject("winmgmts:" _
& "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
set colchassis = objwmiservice.execquery _
("select * from win32_systemenclosure")
for each objchassis in colchassis
for each strchassistype in objchassis.chassistypes
select case strchassistype
case 1
wscript.echo "other"
case 2
wscript.echo "unknown"
case 3
wscript.echo "desktop"
case 4
wscript.echo "low profile desktop"
case 5
wscript.echo "pizza box"
case 6
wscript.echo "mini tower"
case 7
wscript.echo "tower"
case 8
wscript.echo "portable"
case 9
wscript.echo "laptop"
case 10
wscript.echo "notebook"
case 11
wscript.echo "handheld"
case 12
wscript.echo "docking station"
case 13
wscript.echo "all-in-one"
case 14
wscript.echo "sub-notebook"
case 15
wscript.echo "space saving"
case 16
wscript.echo "lunch box"
case 17
wscript.echo "main system chassis"
case 18
wscript.echo "expansion chassis"
case 19
wscript.echo "sub-chassis"
case 20
wscript.echo "bus expansion chassis"
case 21
wscript.echo "peripheral chassis"
case 22
wscript.echo "storage chassis"
case 23
wscript.echo "rack mount chassis"
case 24
wscript.echo "sealed-case pc"
case else
wscript.echo "unknown"
end select
next
next
在您提问以前,不,我们并不知道这些大多数计算机类型是什么,也不知道便携式计算机、膝上型计算机以及笔记本计算机之间有什么区别。我们也不知道 chassistypes 属性为什么存储为数组。那是否意味着一台计算机可以有多种计算机类型?不要问我们,我们也不知道。让我们喘口气吧:毕竟我们只是 microsoft scripting guy,可不是 microsoft hardware guy
复制代码 代码如下:
strcomputer = "."
set objwmiservice = getobject("winmgmts:" _
& "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
set colchassis = objwmiservice.execquery _
("select * from win32_systemenclosure")
for each objchassis in colchassis
for each strchassistype in objchassis.chassistypes
wscript.echo strchassistype
next
next
好吧,以上脚本只是在一定程度上让您知道您使用的是哪种类型的计算机。实际上,chassistype 属性返回的是一个数字,这就是说当我们在面前的计算机上运行这个脚本时,我们将得到 10。那么,什么是 10 呢?根据wmi sdk,它指的是笔记本计算机。猜一猜会发生什么呢?没错!
但您并不必每次检查计算机类型时都参考 sdk。以下经过扩展的脚本使用一个 select case 语句,它可将这些整数转换为更有意义的内容:
复制代码 代码如下:
strcomputer = "."
set objwmiservice = getobject("winmgmts:" _
& "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
set colchassis = objwmiservice.execquery _
("select * from win32_systemenclosure")
for each objchassis in colchassis
for each strchassistype in objchassis.chassistypes
select case strchassistype
case 1
wscript.echo "other"
case 2
wscript.echo "unknown"
case 3
wscript.echo "desktop"
case 4
wscript.echo "low profile desktop"
case 5
wscript.echo "pizza box"
case 6
wscript.echo "mini tower"
case 7
wscript.echo "tower"
case 8
wscript.echo "portable"
case 9
wscript.echo "laptop"
case 10
wscript.echo "notebook"
case 11
wscript.echo "handheld"
case 12
wscript.echo "docking station"
case 13
wscript.echo "all-in-one"
case 14
wscript.echo "sub-notebook"
case 15
wscript.echo "space saving"
case 16
wscript.echo "lunch box"
case 17
wscript.echo "main system chassis"
case 18
wscript.echo "expansion chassis"
case 19
wscript.echo "sub-chassis"
case 20
wscript.echo "bus expansion chassis"
case 21
wscript.echo "peripheral chassis"
case 22
wscript.echo "storage chassis"
case 23
wscript.echo "rack mount chassis"
case 24
wscript.echo "sealed-case pc"
case else
wscript.echo "unknown"
end select
next
next
在您提问以前,不,我们并不知道这些大多数计算机类型是什么,也不知道便携式计算机、膝上型计算机以及笔记本计算机之间有什么区别。我们也不知道 chassistypes 属性为什么存储为数组。那是否意味着一台计算机可以有多种计算机类型?不要问我们,我们也不知道。让我们喘口气吧:毕竟我们只是 microsoft scripting guy,可不是 microsoft hardware guy