服务器之家

服务器之家 > 正文

用vbs脚本获取网卡MAC,CPUID,硬盘序列号的实现代码

时间:2020-08-19 10:46     来源/作者:VBS代码网

这里先给大家分享一个分配静态ip地址的代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
' 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'方法1
Sub Auto_Open()
OnErrorResumeNext
    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
            ExitFor
        EndIf
    Next
    If s <> ""Then
        Range("Sheet1!d8") = s
    Else
        Range("Sheet1!d8") = "系统未检测到U盘!"
   EndIf
   Set d = Nothing
   Set fs = Nothing
   Call QueryOther
EndSub
'方法2
Sub DetectUdisk()
OnErrorResumeNext
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 2")
    ForEach objDisk In colDisks
       RemovableDrive = objDisk.DeviceID
        If CreateObject("Scripting.FileSystemObject").GetDrive(RemovableDrive).IsReady Then
            s = CreateObject("Scripting.FileSystemObject").GetDrive(RemovableDrive).SerialNumber
            ExitFor
        EndIf
    Next
    If s <> ""Then
        Range("Sheet1!d8") = s
    Else
        Range("Sheet1!d8") = "系统未检测到U盘!"
   EndIf
   Call QueryOther
EndSub
Sub QueryOther()
   '2007.1.19 更新,获取主板序列号, CPUID, 网卡MAC地址
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select   SerialNumber   From   Win32_BIOS")
    ForEach objItem In colItems
        Range("Sheet1!E8") = objItem.SerialNumber
        ExitFor
    Next
    Set colItems = Nothing
    
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
    ForEach objItem In colItems
        Range("Sheet1!F8") = objItem.ProcessorId
        ExitFor
    Next
    Set colItems = Nothing
    
    Set colItems = objWMIService.ExecQuery("SELECT MACAddress FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))")
    ForEach objItem In colItems
        Range("Sheet1!G8") = objItem.MACAddress
        ExitFor
    Next
    Set colItems = Nothing
   
EndSub

好了,这里就先介绍到这,需要的朋友可以参考一下。

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
最新idea2020注册码永久激活(激活到2100年)
最新idea2020注册码永久激活(激活到2100年) 2020-07-29
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
返回顶部