Solved

Get device unique ID through code in VB.Net

Posted on 2008-10-09
14
1,699 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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