User Passwort
 Passwort speichern Passwort vergessen?
 
 
 
 Alle Foren
 PDA-Dev :: Windows Mobile
 VB.NET
 Geräte-ID auslesen mit VB.NET
Autor Vorheriges Thema Thema Nächstes Thema  

pda-dev

pda-dev

Forum Admin


554 Beiträge

Erstellt am: 31.07.2008 :  13:44:42 Uhr  Profil anzeigen  Autor eine Email senden  Besuche pda-dev's Homepage  Sende pda-dev eine ICQ Message  Antwort mit Zitat
Beinahe jeder Pocket PC besitzt eine vom Hersteller fest eincodierte Seriennummer, anhand derer er sich eindeutig identifizieren lässt.
Diese Geräte-ID lässt sich z.B. gut verwenden, um Registrierungsfunktionen zu erstellen.
Und so lässt sich die Device Id des Pocket PC's unter .NET CF mit VB.NET auslesen:
 
'DLLImports andConstants
Private Shared FILE_DEVICE_HAL As Int32 = &H101
Private Shared FILE_ANY_ACCESS As Int32 = &H0
Private Shared METHOD_BUFFERED As Int32 = &H0
Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = ((FILE_DEVICE_HAL) << 16) Or ((FILE_ANY_ACCESS) << 14) Or ((21) << 2) Or (METHOD_BUFFERED)
<DllImport("coredll.dll")> _
Private Shared Function KernelIoControl(ByVal IoControlCode As Int32, _
ByVal InputBuffer As IntPtr, ByVal InputBufferSize As Int32, ByVal OutputBuffer As Byte(), _
ByVal OutputBufferSize As Int32, ByRef BytesReturned As Int32) As Boolean
End Function
'read device and return it as string.
'return "" if no id present
Private Function GetDeviceID() As String
Dim OutputBuffer(256) As Byte
Dim OutputBufferSize, BytesReturned As Int32
OutputBufferSize = OutputBuffer.Length
BytesReturned = 0
'// Call KernelIoControl passing the previously defined
'// IOCTL_HAL_GET_DEVICEID parameter
'// We do not need to pass any input buffers to this call
'// so InputBuffer and InputBufferSize are set to their null
'// values
Dim retVal As Boolean = KernelIoControl(IOCTL_HAL_GET_DEVICEID, _
IntPtr.Zero, _
0, _
OutputBuffer, _
OutputBufferSize, _
BytesReturned)
'// If the request failed, exit the method now
'//No id present!
If (retVal = False) Then
Return ""
Else
End If
'// Examine the OutputBuffer byte array to find the start of the
'// Preset ID and Platform ID, as well as the size of the
'// PlatformID.
'// PresetIDOffset ? The number of bytes the preset ID is offset
'// from the beginning of the structure
'// PlatformIDOffset - The number of bytes the platform ID is
'// offset from the beginning of the structure
'// PlatformIDSize - The number of bytes used to store the
'// platform ID
'// Use BitConverter.ToInt32() to convert from byte[] to int
Dim PresetIDOffset As Int32 = BitConverter.ToInt32(OutputBuffer, 4)
Dim PlatformIDOffset As Int32 = BitConverter.ToInt32(OutputBuffer, &HC)
Dim PlatformIDSize As Int32 = BitConverter.ToInt32(OutputBuffer, &H10)
'// Convert the Preset ID segments into a string so they can be
'// displayed easily.
Dim sb As StringBuilder = New StringBuilder
sb.Append(String.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-", _
BitConverter.ToInt32(OutputBuffer, PresetIDOffset), _
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 4), _
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 6), _
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 8)))
'// Break the Platform ID down into 2-digit hexadecimal numbers
'// and append them to the Preset ID. This will result in a
'// string-formatted Device ID
Dim i As Int32
For i = PlatformIDOffset To PlatformIDOffset + PlatformIDSize - 1
sb.Append(String.Format("{0:X2}", OutputBuffer(i)))
Next i
'// return the Device ID string
Return sb.ToString()
End Function
 

Ein Computer wird nie das tun, was du willst - sondern das, was du programmierst!
   

Okeanos

Neumitglied


1 Beitrag

Erstellt  am: 05.10.2009 :  15:42:59 Uhr  Profil anzeigen  Autor eine Email senden  Antwort mit Zitat
Ich bin gerade über Deine Funktion gestoßen und möchte Dir Danken. Du hast mir damit ein wenig Arbeit abgenommen.
Danke
Zum Anfang der Seite
  Vorheriges Thema Thema Nächstes Thema  
Springe nach:
 
  Bookmark & Share  
 
 
 
  Tags  
 
Keine Tags gefunden
 
 
 



pda-dev.de

Quicklinks: Foren-Übersicht | Developer-News | Suche | Impressum

© just-works! Software

Zum Anfang der Seite

Snitz Forums 2000