EXCEL中能否用VBA读取电脑的机器码?
答案:2 悬赏:0 手机版
解决时间 2021-02-04 22:48
- 提问者网友:活着好累
- 2021-02-04 12:06
每台电脑都有一个独一无二的机器码,EXCEL中能否用VBA读取电脑的机器码?
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-02-04 12:52
电脑没有机器码的,我们所说的机器码指对电脑的配件(如硬盘)型号按一定算法演算出的代码.通常不同软件演算出的机器码都是不一样的,下面三个函数分别得到本机IP,电脑名称,硬盤Id.(硬盤id可做机器码)Public Function GetIPAddress() As String'得到IPSTRComputer = "."
Set OBJWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & STRComputer & "\root\cimv2")Set IPConfigSet = OBJWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each IPConfig In IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress) GetIPAddress = IPConfig.IPAddress(i) Next End IfNext
End Function
Public Function GetUserName() As String'得到电脑名称STRComputer = "."
Set OBJWMIService = GetObject("winmgmts:\\" & STRComputer & "\root\CIMV2")Set ColCSItems = OBJWMIService.ExecQuery("SELECt * From Win32_ComputerSystem")For Each OBJCSItem In ColCSItems GetUserName = OBJCSItem.UserNameNext
End Function
Public Function GetDiskID(Disk As String) As String'得到磁盤IDDim Flag As BooleanDim DiskID As String
Flag = FalseOn Error GoTo label
DiskID = Str(CreateObject("Scripting.FileSystemObject").GetDrive(Disk).SerialNumber)
Flag = Truelabel:If Flag Then GetDiskID = DiskIDElse GetDiskID = "" x = MsgBox("Function Parameter Like C " + Chr(10) + Chr(13) + "Please Check The Existence Of The " + Disk + " Disk", vbInformation + vbOKOnly, "Microsoft Excel 5.0")End If
End Function
Set OBJWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & STRComputer & "\root\cimv2")Set IPConfigSet = OBJWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each IPConfig In IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress) GetIPAddress = IPConfig.IPAddress(i) Next End IfNext
End Function
Public Function GetUserName() As String'得到电脑名称STRComputer = "."
Set OBJWMIService = GetObject("winmgmts:\\" & STRComputer & "\root\CIMV2")Set ColCSItems = OBJWMIService.ExecQuery("SELECt * From Win32_ComputerSystem")For Each OBJCSItem In ColCSItems GetUserName = OBJCSItem.UserNameNext
End Function
Public Function GetDiskID(Disk As String) As String'得到磁盤IDDim Flag As BooleanDim DiskID As String
Flag = FalseOn Error GoTo label
DiskID = Str(CreateObject("Scripting.FileSystemObject").GetDrive(Disk).SerialNumber)
Flag = Truelabel:If Flag Then GetDiskID = DiskIDElse GetDiskID = "" x = MsgBox("Function Parameter Like C " + Chr(10) + Chr(13) + "Please Check The Existence Of The " + Disk + " Disk", vbInformation + vbOKOnly, "Microsoft Excel 5.0")End If
End Function
全部回答
- 1楼网友:笑迎怀羞
- 2021-02-04 14:22
直接在excel的vba的帮助中就能找到源码
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯