All Forums
 Microsoft Windows CE
 CE Sample Applications and Utilities
 eVC - ReadFlashID (Flash Serial Number)
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

ctacke

877 Posts

Posted - 11 Nov 2003 :  10:48:44  Show Profile  Email Poster
Read Flash Serial Number - eVC


Notice of Deprecation
We have deprecated this code. While this example will work for the 8-byte ID returned by current flash chips, it would not work with other sizes that could be used in the future.



Below is a code snippet showing how to read the 64-bit serial number of the on-board flash of some ADS systems (see Topic 1242 for support info).

#include "windows.h"

#define IOCTL_READ_FLASH_ID 0x10

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow )
{
BOOL bRet;
ULONG BytesRet;

HANDLE hPort = INVALID_HANDLE_VALUE;

// Open a handle to the Flash driver
hPort = CreateFile (TEXT("FSH1:"),
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

// sanity check
if (hPort == INVALID_HANDLE_VALUE)
{
RETAILMSG(1,(L" ReadFlashID: Could not open File %s.\\r\\n",TEXT("FSH1:")));
return FALSE;
}

BYTE a[1];
USHORT b[4];

// read the flash ID through an IOCTL
bRet = DeviceIoControl( hPort,
IOCTL_READ_FLASH_ID,
a, // not used, but can't be NULL
0,
b,
sizeof(b),
&BytesRet, // not actually set to any valid number
NULL);

RETAILMSG(1,(L" \\r\\n ReadFlashID: "));

if(! bRet)
{
RETAILMSG(1,(L" \\r\\n Failed\\r\\n"));
return 0;
}

TCHAR id[20];

// output the ID
_stprintf(id, _T("%04X %04X %04X %04X"), b[0], b[1], b[2], b[3]);
RETAILMSG(1,(_T("%s\\r\\n"), id));
MessageBox(NULL, id, _T("Flash ID"), 0);

// close the driver
if(hPort != INVALID_HANDLE_VALUE)
{
CloseHandle(hPort);
hPort = INVALID_HANDLE_VALUE;
}

// exit
return 0;
}


Edited by akidder 12-May-2008: Add notice of deprecation.

jmoger

11 Posts

Posted - 22 Sep 2006 :  10:56:45  Show Profile  Email Poster
Is there a variation of this code that would allow retrieval of the volume ID / serial number from a USB flash disk? (\Hard Disk)

It appears that CE 4.2 does not support the GetVolumeInformation function.
Go to Top of Page

jmoger

11 Posts

Posted - 22 Sep 2006 :  11:50:18  Show Profile  Email Poster
Hmm.... this looks promising...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceddk5/html/wce50lrfioctldiskgetstorageid.asp

Unfortunately I don't seem to have diskio.h and/or definitions for STORAGE_IDENTIFICATION or IOCTL_DISK_GET_STORAGEID.

I want to be able to read a unique identifier from a USB mass storage device and compare that to an encrypted file saved on the USB mass storage device which contains the same value. If the values match, then additional features will be activated in my software. If they don't match (the encrypted file has been copied to a different USB mass storage device) then the features won't be activated. Simple anti-piracy.

Correspondingly, I would need to be able to obtain the same identifier from Windows XP in order to create the encrypted file.

The actual meaning of the ID doesn't matter... device serial number, volume serial number, etc... as long as its unique to that formatted USB device.

Any pointers?
Go to Top of Page

jnosek

3 Posts

Posted - 25 Sep 2006 :  17:48:35  Show Profile  Email Poster
This topic has been moved to the following forum topic
Go to Top of Page

cbadr

154 Posts

Posted - 29 May 2008 :  12:10:23  Show Profile  Email Poster
#Notice_of_deprecation

You can download here a sample C++ application that reads flash serial number and device code.
Go to Top of Page
  Topic  
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000