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

pda-dev

pda-dev

Forum Admin


554 Beiträge

Erstellt am: 31.07.2008 :  13:55:37 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 lässt sich die Device Id des Pocket PC's unter .NET CF mit C# auslesen:
 
//DLLImports and constants
private static Int32 FILE_DEVICE_HAL = 257;
private static Int32 FILE_ANY_ACCESS = 0;
private static Int32 METHOD_BUFFERED = 0;
private static Int32 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14) | ((21) << 2) | (METHOD_BUFFERED);
[DllImport("coredll.dll")]
private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr InputBuffer, Int32 InputBufferSize,
byte[] OutputBuffer, Int32 OutputBufferSize, ref Int32 BytesReturned);
//Reads the device id and returns it as String
//returns "" if no id present
public string GetDeviceID()
{
byte[] OutputBuffer = new byte[257];
Int32 OutputBufferSize;
Int32 BytesReturned;
OutputBufferSize = OutputBuffer.Length;
BytesReturned = 0;
//// Call KernelIoControl passing the previously defined
//// IOCTL_HAL_GET_DEVICEID parameter
//// We don?t need to pass any input buffers to this call
//// so InputBuffer and InputBufferSize are set to their null
//// values
bool retVal = KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, OutputBuffer, OutputBufferSize, ref BytesReturned);
//// If the request failed, exit the method now
//no id present!
if ((retVal == false))
{
return "";
}
//// 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
Int32 PresetIDOffset = BitConverter.ToInt32(OutputBuffer, 4);
Int32 PlatformIDOffset = BitConverter.ToInt32(OutputBuffer, 12);
Int32 PlatformIDSize = BitConverter.ToInt32(OutputBuffer, 16);
//// Convert the Preset ID segments into a string so they can be
//// displayed easily.
StringBuilder sb = 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
Int32 i;
for (i = PlatformIDOffset; i <= PlatformIDOffset + PlatformIDSize - 1; i++)
{
sb.Append(string.Format("{0:X2}", OutputBuffer[i]));
}
//// return the Device ID string
return sb.ToString();
}
 

Ein Computer wird nie das tun, was du willst - sondern das, was du programmierst!
   
  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