Solved

Get device unique ID through code in VB.Net

Posted on 2008-10-09
14
1,646 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now