'cpu序號
Public Function GetCpuID() As String
Try
Dim cpuInfo As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_Processor").GetInstances
Dim mo As ManagementObject
For Each mo In moc
cpuInfo = mo.Properties.Item("ProcessorId").Value.ToString
Next
moc = Nothing
Return cpuInfo
CpuID = cpuInfo
Catch
Return "unknow"
End Try
End Function
'硬碟系列號
Public Function GetDiskID() As String
Try
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
Dim strHardDiskID As String = ""
For Each mo As ManagementObject In searcher.Get()
strHardDiskID = mo.Properties("SerialNumber").Value.ToString
strHardDiskID = strHardDiskID.Replace(" ", "")
Exit For
Next
Return strHardDiskID
Catch
Return "unknow"
End Try
End Function
'硬碟型號
Public Function GetDiskModel() As String
Try
Dim HDModel As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_DiskDrive").GetInstances
Dim mo As ManagementObject
For Each mo In moc
HDModel = mo.Properties("Model").Value.ToString
Next
moc = Nothing
Return HDModel
DiskID = HDModel
Catch
Return "unknow"
End Try
End Function
'CPU
Function GetDiskModel_1() As String
Try
Dim HDModel As String = ""
Dim mc As ManagementClass = New ManagementClass("Win32_DiskDrive")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
HDModel = mo.Properties("Model").Value.ToString
'HDModel = HDModel.Replace(" ", "")
Exit For
Next
moc = Nothing
mc = Nothing
Return HDModel
Catch
Return "unknow"
End Try
End Function
'主機板
Function GetmainboardID() As String
Try
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("Select * FROM Win32_BaseBoard")
Dim strmainboardID As String = ""
For Each mo As ManagementObject In searcher.Get()
strmainboardID = mo.Properties("SerialNumber").Value.ToString
strmainboardID = strmainboardID.Replace(" ", "")
Exit For
Next
Return strmainboardID
Catch
Return "unknow"
End Try
End Function
'ip地址
Public Function GetIPAddress() As String
Try
Dim st As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances
Dim mo As ManagementObject
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
Dim ar As Array = DirectCast(mo.Properties.Item("IpAddress").Value, Array)
st = ar.GetValue(0).ToString
Exit For
End If
Next
moc = Nothing
Return st
IpAddress = st
Catch
Return "unknow"
End Try
End Function
'mac地址
Public Function GetMacAddress() As String
Try
Dim mac As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances
Dim mo As ManagementObject
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
mac = mo.Item("MacAddress").ToString
Exit For
End If
Next
moc = Nothing
Return mac
MacAddress = mac
Catch
Return "unknow"
End Try
End Function
'系統類型
Public Function GetSystemType() As String
Try
Dim st As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_ComputerSystem").GetInstances
Dim mo As ManagementObject
For Each mo In moc
st = mo.Item("SystemType").ToString
Next
moc = Nothing
Return st
SystemType = st
Catch
Return "unknow"
End Try
End Function
'内存空間
Public Function GetTotalPhysicalMemory() As String
Try
Dim st As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_ComputerSystem").GetInstances
Dim mo As ManagementObject
For Each mo In moc
st = mo.Item("TotalPhysicalMemory").ToString
Next
moc = Nothing
Return st
TotalPhysicalMemory = st
Catch
Return "unknow"
End Try
End Function
'系統用戶名
Public Function GetUserName() As String
Try
Dim st As String = ""
Dim moc As ManagementObjectCollection = New ManagementClass("Win32_ComputerSystem").GetInstances
Dim mo As ManagementObject
For Each mo In moc
st = mo.Item("UserName").ToString
Next
moc = Nothing
Return st
LoginUserName = st
Catch
Return "unknow"
End Try
End Function
歡迎光臨 冰楓論壇 (https://bingfong.com/) | Powered by 冰楓 |