Solved

Get device unique ID through code in VB.Net

Posted on 2008-10-09
14
1,762 Views
Last Modified: 2013-12-21
I have an application developed in VB.Net that runs on a device with WM 2003.  I want to know how to determine the device's unique ID number through code.

Please be thorough (assume I don't know anything).  

I have tried to couple of snippets I found on the web, but they were either in a differnt programming language (c++ or something else) or when I copied and pasted, there were too many errors to correct.

I need a VB solution.  

Thanks in advance for any help
0
Comment
Question by:PSCTECH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 22683361
0
 

Author Comment

by:PSCTECH
ID: 22686788
I tried that and got several syntax errors.
1.  Line 1 <DllImport>              error = type DllImport not defined
2.  Line 4 [In]                           error = type In not defined
3.  Line 4 [Out]                        error type Out not defined
4.. Line 5 UInteger                  error type UInteger not defined
5.  Line 19 AppString(count)  error = Expression is not an array or method and cannot have an argument list
6.  Line 26  UInteger               error type UInteger not defined
1    <DllImport("coredll.dll")> _
2    Private Shared Function GetDeviceUniqueID(<[In](), Out()> ByVal   3   appdata As Byte(), ByVal cbApplictionData As Integer, ByVal         4    dwDeviceIDVersion As Integer, <[In](), Out()> ByVal deviceIDOuput 5    As Byte(), ByRef pcbDeviceIDOutput As UInteger) As Integer
6    End Function
7
8
9
10    Private Function GetDeviceID(ByVal AppString As String) As Byte()
11
12
13        ' Call the GetDeviceUniqueID 
14
15        Dim AppData As Byte() = New Byte(AppString.Length - 1) {}
16
17       For count As Integer = 0 To AppString.Length - 1
18
19            AppData(count) = CByte(AppString(count))
20        Next
21
22        Dim appDataSize As Integer = AppData.Length
23
24        Dim DeviceOutput As Byte() = New Byte(19) {}
25
26        Dim SizeOut As UInteger = 20
27
28        GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput,    29        SizeOut)
30
31        Return DeviceOutput
32
33    End Function

Open in new window

0
 

Author Comment

by:PSCTECH
ID: 22686822
sorry the line numbers got changed when I submitted.  They should be
1
2
2
2
16
23
0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 24

Expert Comment

by:alexey_gusev
ID: 22686912
well,

1) you have to Import System.Runtime.InteropServices
2) - 3) remove all In (this is ByVal) and replace possibly Out as ByRef
4) look for UInteger in Object Browser to find appropriate namespace to Import
5) replace "CByte(AppString(count))"  by something that converts AppString(count) - this is of Char type - to Hex string, presumably some AppString(count).ToString() flavour
               
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 22686922
sorry, for the last problem - you need to convert String to an array Byte, I guess Encoding is a right choice for it
0
 

Author Comment

by:PSCTECH
ID: 22687047
Ok, thanks.
So far I have imported the System.Runtime.InteropServices

That cleared up everything except the UInteger (I searched the  Object browser and didn't find anything)
Any thoughts

Also, I have no idea what to do with the "CByte(appString(count))" statement
0
 

Author Comment

by:PSCTECH
ID: 22687089
Sorry, I thought I had listed it, but if it helps....I'm using vs 2003
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 22687176
well, use UInt32 for UInteger and something like


appData = Encoding.ASCII.GetBytes(appString)
0
 

Author Comment

by:PSCTECH
ID: 22687344
well, that caused different errors

Dim SizeOut As UInt32 = 20 cause an error on 20: "Value of type Integer cannot be converted to System.UInt32"

and

appData = Encoding.ASCII.GetBytes(appString)  causes an error on Encoding: "Name Encoding is not declared"
0
 

Author Comment

by:PSCTECH
ID: 22687362
AppData = System.Text.Encoding.ASCII.GetBytes(AppString)
seems to be ok
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 22687409
ok, use whatever type you like that is 4 bytes
0
 

Author Comment

by:PSCTECH
ID: 22687452
??????
0
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 500 total points
ID: 22687485
such as  Integer or Long :) - UInt32 is unsigned integer of 32 bits = 4 bytes
0
 

Author Closing Comment

by:PSCTECH
ID: 31504767
I really appreciate it.  Hope I can get it working now.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question