Programmatically retrieving the IMEI or ESN number for mobile devices and the peculiar problem in doing this with windows mobile.
While writing commercial applications which require some sort of licensing/copy protection/user duplication prevention ,developers need to have a method for retrieving any unique id associated with a device.For most practical purposes this unique id is the IMEI(International Mobile Equipment Identity) or the ESN(Electronic Serial Number)of the mobile device.On all phones this can be retrieved by dialing “*#06#”.A few mobile platforms have this exposed by way of native API’s which return the IMEI/ESN of the device.On some mobile platforms such as Windows mobile, these API are restricted and need the application to be signed for the API to function properly.But there exists a way in which the IMEI/ESN can be retrieved by all applications regardless of the platform,this approach uses the GSM/CDMA modem to get the IMEI /ESN .All that is required is to programmatic ally open a serial port connection to the modem(mostly on COM9) ,initialize the modem and then send the “AT+CGSN” command.In response the modem will give you the IMEI/ESN of the device.In case you are not able to establish a connection on COM9, try polling all the available COM ports and see which one responds to specific commands.