Loop through and read adapters

StewartBW 1,255 Reputation points
2025-03-07T20:19:13.4066667+00:00

Hello

Because WMI Win32_VideoController AdapterRAM property cannot read more than 4GB of memory, I'm going to read Keys here:

HKLM\SYSTEM\ControlSet001\Control\Class{4d36e968-e325-11ce-bfc1-08002be10318}

There's 2 samples in PowerShell posted on stackoverflow but can't understand or translate them to VB.net, anyone knows a vb equivalent to loop through and read graphics names and sizes?

Thanks.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,804 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 87,971 Reputation points
    2025-03-08T06:11:31.4666667+00:00

    You can do something like this :

               Dim sRegistryPath As String = "SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}"
               Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey(sRegistryPath)
               If regKey IsNot Nothing Then
                   ' Loop through all subkeys (e.g., 0000, 0001, 0002, ...)
                   For Each sSubKeyName As String In regKey.GetSubKeyNames()
                       If sSubKeyName.StartsWith("0") Then
                           Dim subKey As RegistryKey = regKey.OpenSubKey(sSubKeyName)
                           If subKey IsNot Nothing Then
                               Dim chipsetInfo As String() = {
                               "HardwareInformation.MemorySize",
                               "HardwareInformation.ChipType",
                               "HardwareInformation.DacType",
                               "HardwareInformation.AdapterString",
                               "HardwareInformation.BiosString",
                               "DriverDesc",
                               "DriverVersion",
                               "DriverDate"
                               }
                               For Each sInfo As String In chipsetInfo
                                   Dim value As Object = subKey.GetValue(sInfo, "N/A")
                                   If TypeOf value Is Byte() Then
                                       Dim byteArray As Byte() = CType(value, Byte())
                                       If sInfo = "HardwareInformation.MemorySize" Then
                                           ' For memory size, convert byte array to integer
                                           Dim nMemorySize As Integer = BitConverter.ToInt32(byteArray, 0)
                                           Dim nMemorySizeInMB As Double = nMemorySize / (1024 * 1024)
                                           Debug.WriteLine($"{sInfo}: {nMemorySize} bytes ({Math.Round(nMemorySizeInMB, 2)} MB)")
                                       Else
                                           ' For string values, convert byte array to a UTF-16 string
                                           Dim sValueStr As String = Encoding.Unicode.GetString(byteArray)
                                           sValueStr = sValueStr.TrimEnd(ChrW(0))
                                           Debug.WriteLine($"{sInfo}: {sValueStr}")
                                       End If
                                   Else
                                       Debug.WriteLine($"{sInfo}: {value}")
                                   End If
                               Next
                               Debug.WriteLine("")
                           End If
                       End If
                   Next
               Else
                   Debug.WriteLine("Registry path not found.")
               End If
    
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.