2012-07-18 58 views
0

我需要一个函数返回一个字符串,使用硬件序列号并将它们混合在一起以获得单个序列号。Function for GetUniquePCID .NET

我搜索尝试这样的功能,但我找不到任何类似的东西,这个功能需要识别具有授权系统的PC。

我只需要每台计算机具有相同的值。

回答

1

这可能不完全是你想要的,但如果我正确理解你的问题,玩下面的代码(不要使用下面的代码与严格)不是最好的想法,但它的作品...

Private Function SystemSerialNumber() As String 
    ' Get the Windows Management Instrumentation object. 
    Dim wmi As Object = GetObject("WinMgmts:") 

    ' Get the "base boards" (mother boards). 
    Dim serial_numbers As String = "" 
    Dim mother_boards As Object = _ 
     wmi.InstancesOf("Win32_BaseBoard") 
    For Each board As Object In mother_boards 
     serial_numbers &= ", " & board.SerialNumber 
    Next board 
    If serial_numbers.Length > 0 Then serial_numbers = _ 
     serial_numbers.Substring(2) 

    Return serial_numbers 
End Function 

Private Function CpuId() As String 
    Dim computer As String = "." 
    Dim wmi As Object = GetObject("winmgmts:" & _ 
     "{impersonationLevel=impersonate}!\\" & _ 
     computer & "\root\cimv2") 
    Dim processors As Object = wmi.ExecQuery("Select * from " & _ 
     "Win32_Processor") 

    Dim cpu_ids As String = "" 
    For Each cpu As Object In processors 
     cpu_ids = cpu_ids & ", " & cpu.ProcessorId 
    Next cpu 
    If cpu_ids.Length > 0 Then cpu_ids = _ 
     cpu_ids.Substring(2) 

    Return cpu_ids 
End Function 

来源: http://www.vb-helper.com/howto_net_get_cpu_serial_number_id.html

+0

这正是我需要的,非常感谢你 – 2012-07-18 23:21:59

+0

您的欢迎约翰,很高兴我能帮助! – Dayan 2012-07-18 23:35:46