How do I read PocketPC registry from ASP.NET application

  • Thread starter Thread starter Goran Djuranovic
  • Start date Start date
G

Goran Djuranovic

Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
This will do the trick though hopefully there is a more eloquent .NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class
 
Harry,
This is the error that I got when tried the suggested code:
System.DllNotFoundException: Unable to load DLL (Coredll.dll).

I also forgot to mention that PocketPC is accessing an ASP.NET application
wirelessly.
Once the app is accessed, PocketPC's DeviceID is stored to the database.

Is there anything else I missed.

Thanks for your response
Goran

Harry Simpson said:
This will do the trick though hopefully there is a more eloquent .NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class


Goran Djuranovic said:
Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
Goran,

I got the code from gotdotnet site at:
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src

Try to grab the segment from there.

Harry

Goran Djuranovic said:
Harry,
This is the error that I got when tried the suggested code:
System.DllNotFoundException: Unable to load DLL (Coredll.dll).

I also forgot to mention that PocketPC is accessing an ASP.NET application
wirelessly.
Once the app is accessed, PocketPC's DeviceID is stored to the database.

Is there anything else I missed.

Thanks for your response
Goran

Harry Simpson said:
This will do the trick though hopefully there is a more eloquent .NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class
 
I just figured out it can be done this way:
--------------------------------------------
Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet
Explorer\Main")
Response.Write(RegKey.GetValue("Start Page"))
-----------------------------------------------

Hope this helps someone
Goran Djuranovic

Thanks for your response

Harry Simpson said:
Goran,

I got the code from gotdotnet site at:
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src

Try to grab the segment from there.

Harry

Goran Djuranovic said:
Harry,
This is the error that I got when tried the suggested code:
System.DllNotFoundException: Unable to load DLL (Coredll.dll).

I also forgot to mention that PocketPC is accessing an ASP.NET application
wirelessly.
Once the app is accessed, PocketPC's DeviceID is stored to the database.

Is there anything else I missed.

Thanks for your response
Goran

Harry Simpson said:
This will do the trick though hopefully there is a more eloquent .NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
And this works? That's a heck of a lot better code Goran!!

Harry

Goran Djuranovic said:
I just figured out it can be done this way:
--------------------------------------------
Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet
Explorer\Main")
Response.Write(RegKey.GetValue("Start Page"))
-----------------------------------------------

Hope this helps someone
Goran Djuranovic

Thanks for your response

Harry Simpson said:
Goran,

I got the code from gotdotnet site at:
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src
Try to grab the segment from there.

Harry
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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
That will work on the WEBSERVER, but how is it going to get the device ID
from the PPC? An ASP.NET app has no way of reading the registry on the PPC
that is connecting. You would have to have some client side code on the PPC
that would run, read the device ID from the registry, then call a webservice
maybe to post it to the server, then execute a copy of the browser that
passed a token to the website so that your ASP.Net app knows which device is
connecting.

If you do need to read from the registry of a PPC device, I highly suggest
using the Smart Device Framework from http://www.opennetcf.org. Much easier
than writing all the P/Invoke code yourself :)

m

Goran Djuranovic said:
I just figured out it can be done this way:
--------------------------------------------
Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet
Explorer\Main")
Response.Write(RegKey.GetValue("Start Page"))
-----------------------------------------------

Hope this helps someone
Goran Djuranovic

Thanks for your response

Harry Simpson said:
Goran,

I got the code from gotdotnet site at:
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src
Try to grab the segment from there.

Harry
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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
Mark,

You can read the PPC registry from the desktop using Rapi. There's also a
Rapi class in the OpenNetCF Communication section
--
Ginny Caughey
..Net Compact Framework MVP

Mark Pitman said:
That will work on the WEBSERVER, but how is it going to get the device ID
from the PPC? An ASP.NET app has no way of reading the registry on the PPC
that is connecting. You would have to have some client side code on the PPC
that would run, read the device ID from the registry, then call a webservice
maybe to post it to the server, then execute a copy of the browser that
passed a token to the website so that your ASP.Net app knows which device is
connecting.

If you do need to read from the registry of a PPC device, I highly suggest
using the Smart Device Framework from http://www.opennetcf.org. Much easier
than writing all the P/Invoke code yourself :)

m

Goran Djuranovic said:
I just figured out it can be done this way:
--------------------------------------------
Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet
Explorer\Main")
Response.Write(RegKey.GetValue("Start Page"))
-----------------------------------------------

Hope this helps someone
Goran Djuranovic

Thanks for your response
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src nInBufSize
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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
Yup, you were right. It reads only the server's registry.
I will try the OPENNETCF suggestion.

Thanks for your response.

Goran Djuranovic

Mark Pitman said:
That will work on the WEBSERVER, but how is it going to get the device ID
from the PPC? An ASP.NET app has no way of reading the registry on the PPC
that is connecting. You would have to have some client side code on the PPC
that would run, read the device ID from the registry, then call a webservice
maybe to post it to the server, then execute a copy of the browser that
passed a token to the website so that your ASP.Net app knows which device is
connecting.

If you do need to read from the registry of a PPC device, I highly suggest
using the Smart Device Framework from http://www.opennetcf.org. Much easier
than writing all the P/Invoke code yourself :)

m

Goran Djuranovic said:
I just figured out it can be done this way:
--------------------------------------------
Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet
Explorer\Main")
Response.Write(RegKey.GetValue("Start Page"))
-----------------------------------------------

Hope this helps someone
Goran Djuranovic

Thanks for your response
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src nInBufSize
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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
I realize that, but he was asking how to do it from ASP.Net.

m

Ginny Caughey said:
Mark,

You can read the PPC registry from the desktop using Rapi. There's also a
Rapi class in the OpenNetCF Communication section
--
Ginny Caughey
.Net Compact Framework MVP

Mark Pitman said:
That will work on the WEBSERVER, but how is it going to get the device ID
from the PPC? An ASP.NET app has no way of reading the registry on the PPC
that is connecting. You would have to have some client side code on the PPC
that would run, read the device ID from the registry, then call a webservice
maybe to post it to the server, then execute a copy of the browser that
passed a token to the website so that your ASP.Net app knows which
device
is
connecting.

If you do need to read from the registry of a PPC device, I highly suggest
using the Smart Device Framework from http://www.opennetcf.org. Much easier
than writing all the P/Invoke code yourself :)

m
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src
Try to grab the segment from there.

Harry

Harry,
This is the error that I got when tried the suggested code:
System.DllNotFoundException: Unable to load DLL (Coredll.dll).

I also forgot to mention that PocketPC is accessing an ASP.NET
application
wirelessly.
Once the app is accessed, PocketPC's DeviceID is stored to the database.

Is there anything else I missed.

Thanks for your response
Goran

This will do the trick though hopefully there is a more eloquent .NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal
nInBufSize
As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
Allowing a web page to access the registry would be a huge security hole.

-Chris


Mark Pitman said:
I realize that, but he was asking how to do it from ASP.Net.

m

Mark,

You can read the PPC registry from the desktop using Rapi. There's also a
Rapi class in the OpenNetCF Communication section
--
Ginny Caughey
.Net Compact Framework MVP

the
PPC device
http://samples.gotdotnet.com/quicks...ompactFramework/samples/deviceid/deviceid.src
Try to grab the segment from there.

Harry

Harry,
This is the error that I got when tried the suggested code:
System.DllNotFoundException: Unable to load DLL (Coredll.dll).

I also forgot to mention that PocketPC is accessing an ASP.NET
application
wirelessly.
Once the app is accessed, PocketPC's DeviceID is stored to the
database.

Is there anything else I missed.

Thanks for your response
Goran

This will do the trick though hopefully there is a more eloquent
.NET
way.....

HTH
Harry

Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal
dwIoControlCode As Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize
As
Int32, ByVal lpOutBuf() As Byte, ByVal nOutBufSize As Int32, ByRef
lpBytesReturned As Int32) As Boolean
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


Public 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
End Class


Hi All,
I would like to be able to read Device ID from PocketPC.
I guess I have to read PocketPC's registry somehow.
How do I do this?
 
Back
Top