EXCEL中能否用VBA读取电脑的机器码?
2个回答
2013-07-05
展开全部
电脑没有机器码的,我们所说的机器码指对电脑的配件(如硬盘)型号按一定算法演算出的代码.通常不同软件演算出的机器码都是不一样的,下面三个函数分别得到本机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
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
2013-07-05
展开全部
可以的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询