Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get device unique ID through code in VB.Net

Posted on 2008-10-09
14
Medium Priority
?
1,843 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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