[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1872
  • Last Modified:

Get device unique ID through code in VB.Net

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
PSCTECH
Asked:
PSCTECH
  • 8
  • 6
1 Solution
 
alexey_gusevCommented:
0
 
PSCTECHAuthor Commented:
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
 
PSCTECHAuthor Commented:
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.  

 
alexey_gusevCommented:
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
 
alexey_gusevCommented:
sorry, for the last problem - you need to convert String to an array Byte, I guess Encoding is a right choice for it
0
 
PSCTECHAuthor Commented:
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
 
PSCTECHAuthor Commented:
Sorry, I thought I had listed it, but if it helps....I'm using vs 2003
0
 
alexey_gusevCommented:
well, use UInt32 for UInteger and something like


appData = Encoding.ASCII.GetBytes(appString)
0
 
PSCTECHAuthor Commented:
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
 
PSCTECHAuthor Commented:
AppData = System.Text.Encoding.ASCII.GetBytes(AppString)
seems to be ok
0
 
alexey_gusevCommented:
ok, use whatever type you like that is 4 bytes
0
 
PSCTECHAuthor Commented:
??????
0
 
alexey_gusevCommented:
such as  Integer or Long :) - UInt32 is unsigned integer of 32 bits = 4 bytes
0
 
PSCTECHAuthor Commented:
I really appreciate it.  Hope I can get it working now.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now