用vbs脚本获取网卡MAC,CPUID,硬盘序列号的实现代码
程序员文章站
2022-06-17 22:13:56
这里先给大家分享一个分配静态ip地址的代码
' assign a static ip address
strcomputer = "."
set ob...
这里先给大家分享一个分配静态ip地址的代码
' assign a static ip address strcomputer = "." set objwmiservice = getobject("winmgmts:" _ & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2") set colnetadapters = objwmiservice.execquery _ ("select * from win32_networkadapterconfiguration where ipenabled=true") stripaddress = array("192.168.6.98") strsubnetmask = array("255.255.255.0") strgateway = array("192.168.6.1") strgatewaymetric = array(1) for each objnetadapter in colnetadapters errenable = objnetadapter.enablestatic(stripaddress, strsubnetmask) errgateways = objnetadapter.setgateways(strgateway, strgatewaymetric) if errenable = 0 then wscript.echo "the ip address has been changed." else wscript.echo "the ip address could not be changed." end if next
检测u盘 方法一
'方法1 sub auto_open() on error resume next set fs = createobject("scripting.filesystemobject") strdrive = "b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" strdrivearray = split(strdrive, ",") for startpos = 1 to ubound(strdrivearray) set d = fs.getdrive(fs.getdrivename(fs.getabsolutepathname(strdrivearray(startpos) & ":\\"))) if d.drivetype = 1 then s = d.serialnumber exit for end if next if s <> "" then range("sheet1!d8") = s else range("sheet1!d8") = "系统未检测到u盘!" end if set d = nothing set fs = nothing call queryother end sub '方法2 sub detectudisk() on error resume next set objwmiservice = getobject("winmgmts:\\.\root\cimv2") set coldisks = objwmiservice.execquery("select * from win32_logicaldisk where drivetype = 2") for each objdisk in coldisks removabledrive = objdisk.deviceid if createobject("scripting.filesystemobject").getdrive(removabledrive).isready then s = createobject("scripting.filesystemobject").getdrive(removabledrive).serialnumber exit for end if next if s <> "" then range("sheet1!d8") = s else range("sheet1!d8") = "系统未检测到u盘!" end if call queryother end sub sub queryother() '2007.1.19 更新,获取主板序列号, cpuid, 网卡mac地址 set objwmiservice = getobject("winmgmts:\\.\root\cimv2") set colitems = objwmiservice.execquery("select serialnumber from win32_bios") for each objitem in colitems range("sheet1!e8") = objitem.serialnumber exit for next set colitems = nothing set colitems = objwmiservice.execquery("select * from win32_processor") for each objitem in colitems range("sheet1!f8") = objitem.processorid exit for next set colitems = nothing set colitems = objwmiservice.execquery("select macaddress from win32_networkadapter where ((macaddress is not null) and (manufacturer <> 'microsoft'))") for each objitem in colitems range("sheet1!g8") = objitem.macaddress exit for next set colitems = nothing end sub
好了,这里就先介绍到这,需要的朋友可以参考一下。
上一篇: VBS基础篇 - vbscript堆栈