Results 1 to 5 of 5

Thread: Reading Registry Keys and Values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244

    Reading Registry Keys and Values

    Ok, here is what I am trying to do. I want to either do it in VB6 or preferably VB.NET so either way is going to be helpful.

    I need to do two things:

    1) I need to read this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3 but not return a value. What I actually need to return is all of the keys underneath it. IE

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3 will contain all of the printer drivers on your system so they keys would look like:
    Code:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3\HP LaserJet 5si
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3\Canon BJC-300
    I want to read those keys so the values I would be looking for in this case would be HP LaserJet 5si & Canon BJC-300.

    Now my plan is to append these values to a list box. Once in the list box here is the function I want to perform against them (and yes this is getting exponentionally more difficult).

    In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers is a list of all of the printers on the system. In that key there is a key based on the name of the printer & a value "Printer Driver" that will correspond with one of the keys from above.

    More or less what I am trying to do is generate a list box of all of the printer drivers installed on the system and from that list generate a list of printers on the system that use that particular driver.

    Is this do able with VB and can anyone point me in the right direction.

    I can be reached on here. AOL IM jimmjr19 or ICQ 6262404 if you have any questions or advice.

    Thanks,

    Jim

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I am not too fluent with the APIs for the registry, but I know you can
    enumerate the keys of a particular hive. This way you can build your list.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Do you have any links, etc... to point me in the right direction?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    I want to write this for VB6 ( I am learning VB right now and am starting with VB .NET.

    This is the code I have now:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim Cnt As Integer
    3.         Dim RegKey As RegistryKey = Registry.CurrentUser.CreateSubKey( _
    4.            "Software")
    5.         Dim SubKeys() As String = RegKey.GetSubKeyNames()
    6.         Dim DriverAdd As String
    7.         If SubKeys.Length > 0 Then
    8.             For Cnt = 0 To SubKeys.Length - 1
    9.                 DriverAdd = (SubKeys(Cnt))
    10.                 lbDrivers.Items.Add(DriverAdd)
    11.             Next Cnt
    12.         End If
    13.     End Sub

    Which is modified and pieced together from the ALLApi website. lbDrivers is a listbox. When you click the button it populates the contents of the listbox with all of the subkeys from HKCU\Software. Since I want to write this in VB6 I went back to the website to get the syntax for it and was first A) shocked and the length of code but also ran into a brick wall because when I paste it into a few form most of the syntax is in red and none of it will compile, without editing any of it yet.

    If anyone could point me in the right direction I would greatly appreciate it.

    Thanks,

    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width