IMEI number again

  • Thread starter Thread starter Victor
  • Start date Start date
V

Victor

Can i get the IMEI number information without getting the line information
first?
cheers
victor
 
The only documented way to get the IMEI is through the lineGetGeneralInfo
TAPI method. On Smartphone your app needs signing with a priviledged
certificate to access this method.

Peter
 
Another mthode is get_DeviceID


U also must have a signed application or set Securitya level to one
tier with security unlocker

her the code for VB.Net: (

#Region " Region : Device"
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101

Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A


Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 *
FILE_DEVICE_HAL) Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or
METHOD_BUFFERED


Private Shared Function GetDeviceID() As String


' Initialize the output buffer to the size of a Win32
DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False

Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look
at
' this field rather than the nOutBufSize param of
KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0


' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0,
outbuff, nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New
NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this
device", New Win32Exception([error]))

Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data.
The required size
' is in the first 4 bytes of the output buffer
(DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'

BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)

Case Else
Throw New Win32Exception([error], "Unexpected
error")
End Select
End If
End While

Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff,
&H4) ' DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H8) ' DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 =
BitConverter.ToInt32(outbuff, &HC) ' DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H10) ' DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer

For i = dwPresetIDOffset To (dwPresetIDOffset +
dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset +
dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function

Private Sub DeviceID_Load() ' (ByVal sender As Object, ByVal e As
System.EventArgs) 'Handles MyBase.Load
Try
Dim strDeviceID As String = GetDeviceID()
deviceStr = strDeviceID
'MessageBox.Show(("The ID for this device is " +
deviceStr))

'Application.Exit()

Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
Application.Exit()

End Try
End Sub
#End Region

End Class
 
You also need to be signed with a priveleged cert to call this API. In a
future version of Windows Mobile, we'll provide a simple API for getting a
unique ID that doesn't require this elevated level of trust.

--
Robert Levy
Program Manager
Mobile Devices Product Group
http://blogs.msdn.com/windowsmobile

This posting is provided "AS IS" with no warranties, and confers no
rights.
Another mthode is get_DeviceID


U also must have a signed application or set Securitya level to one
tier with security unlocker

her the code for VB.Net: (

#Region " Region : Device"
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101

Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A


Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 *
FILE_DEVICE_HAL) Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or
METHOD_BUFFERED


Private Shared Function GetDeviceID() As String


' Initialize the output buffer to the size of a Win32
DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False

Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look
at
' this field rather than the nOutBufSize param of
KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0


' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0,
outbuff, nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New
NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this
device", New Win32Exception([error]))

Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data.
The required size
' is in the first 4 bytes of the output buffer
(DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'

BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)

Case Else
Throw New Win32Exception([error], "Unexpected
error")
End Select
End If
End While

Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff,
&H4) ' DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H8) ' DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 =
BitConverter.ToInt32(outbuff, &HC) ' DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H10) ' DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer

For i = dwPresetIDOffset To (dwPresetIDOffset +
dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset +
dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function

Private Sub DeviceID_Load() ' (ByVal sender As Object, ByVal e As
System.EventArgs) 'Handles MyBase.Load
Try
Dim strDeviceID As String = GetDeviceID()
deviceStr = strDeviceID
'MessageBox.Show(("The ID for this device is " +
deviceStr))

'Application.Exit()

Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
Application.Exit()

End Try
End Sub
#End Region

End Class




Can i get the IMEI number information without getting the line
information first?
cheers
victor
 
hi guys
first thank you for all these great ideas.. really helpful..

second i still have some problem. how to signed with a priveleged cert to
call this API??
can you provide some little examples?

cheers

victor


Robert Levy said:
You also need to be signed with a priveleged cert to call this API. In a
future version of Windows Mobile, we'll provide a simple API for getting a
unique ID that doesn't require this elevated level of trust.

--
Robert Levy
Program Manager
Mobile Devices Product Group
http://blogs.msdn.com/windowsmobile

This posting is provided "AS IS" with no warranties, and confers no
rights.
Another mthode is get_DeviceID


U also must have a signed application or set Securitya level to one
tier with security unlocker

her the code for VB.Net: (

#Region " Region : Device"
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101

Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A


Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 *
FILE_DEVICE_HAL) Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or
METHOD_BUFFERED


Private Shared Function GetDeviceID() As String


' Initialize the output buffer to the size of a Win32
DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False

Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look
at
' this field rather than the nOutBufSize param of
KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0


' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0,
outbuff, nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New
NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this
device", New Win32Exception([error]))

Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data.
The required size
' is in the first 4 bytes of the output buffer
(DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'

BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)

Case Else
Throw New Win32Exception([error], "Unexpected
error")
End Select
End If
End While

Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff,
&H4) ' DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H8) ' DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 =
BitConverter.ToInt32(outbuff, &HC) ' DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff,
&H10) ' DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer

For i = dwPresetIDOffset To (dwPresetIDOffset +
dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset +
dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function

Private Sub DeviceID_Load() ' (ByVal sender As Object, ByVal e As
System.EventArgs) 'Handles MyBase.Load
Try
Dim strDeviceID As String = GetDeviceID()
deviceStr = strDeviceID
'MessageBox.Show(("The ID for this device is " +
deviceStr))

'Application.Exit()

Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
Application.Exit()

End Try
End Sub
#End Region

End Class




Can i get the IMEI number information without getting the line
information first?
cheers
victor
 
Actually I can only get DeviceID from that KernelIoControl API call. but i
really want is the IMEI number.....
 
hi robert
the reason why i want to avoid the lineInfo step is I want to get the IMEI
number from my XDA II at all time. but now I can only get the info I want
when the phone is enable(like the flight mode in off). It's very strange
because even the phone is disabled, i can still view the IMEI number info
from the "device Information" in the settings. that means there must be a
way to get the info at all time.......
I thought the different between the phone enable and disable is the line. so
i want to get rid of the lineInfo.

The current method call I am using is lineGetGeneralInfo()

Can you help out?

cheers
victor
 
Ahh... interesting. Sorry though, I don't know of any other way to get the
IMEI using public APIs.

--
Robert Levy
Program Manager
Mobile Devices Product Group
http://blogs.msdn.com/windowsmobile

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
hi robert

so you mean windows ce using a different way(private method call) to get the
IMEI number?

cheers
victor
 
Dont remember, some month ago I googled for smartphone , Imei etc. .
But it works on several HTC devices ( Imate, SDA ,QTek).
But App with code must be signed or use Security Unlocker before.
 
Back
Top