Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Function sequence() As Byte()
        Dim r As RegistryKey
        Dim return_value As Byte()
        r = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,_       
        RegistryView.Registry64)
        r.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion",_
        False,_
        Security.AccessControl.RegistryRights.QueryValues)
        return_value = r.GetValue("DigitalProductID", {})
        Return return_value
    End Function


Why does the above code return NULL/Value does not exist? I have tried Impersonate etc.. in WMI programming.

All I would like to do is get the Digital Product ID return to me as a Byte() array in Visual Basic Express 2010 (AnyCPU compile. As I intend to add this to a DLL). This is of course simple in a x86 Windows enviroment.

Any help would be great. If you can do it in C# then I can always convert it over to VB.NET

Here is what I have Done.
Google for over 2 days.
WMI Impersonate (With the Set oReg, VBE 2010 freaks and removes the SET)
Setting Secuitry Permissions
Changing registry view to Default/32 and 64.

I am at a complete loss. So any help would be great.

Cheers
Posted
Updated 6-Sep-11 21:08pm
v4

1 solution

Try the following code:
C#
const string queryString = "SELECT SerialNumber FROM Win32_OperatingSystem";

string productId = (from ManagementObject managementObject in new ManagementObjectSearcher(queryString).Get()
                    from PropertyData propertyData in managementObject.Properties
                    where propertyData.Name == "SerialNumber"
                    select (string)propertyData.Value).FirstOrDefault();

Console.WriteLine(productId);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900