Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Thanked 0 Times in 0 Posts

    Write to the registry (VB6 / NT4)

    I would like to modify a registry entry that relates to the Windows Explorer and batch it to our users. I was thinking that I could write a little VB6 app and have it run during the login process. I can't find the correct object/method in VB to accomplish this. Can anyone help?

    Alternatively, if you have a better way to change the registry, let me know!


    - Linda

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Willow Grove, Pennsylvania, USA
    Thanked 49 Times in 40 Posts

    Re: Write to the registry (VB6 / NT4)

    There may be an easier way in VB, but I haven't found it. <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23> The Win32API way works, but it's complicated. Put this behind a command button, run it, and then look at the Explorer key in RegEdit.

    <pre>Const ERROR_SUCCESS = 0&
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const REG_SZ = 1 ' Unicode nul terminated string
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
    (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
    (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
    ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    ' Note that if you declare the lpData parameter as String,
    ' you must pass it By Value.

    Private Sub Command1_Click()
    Dim nRet As Long, hKey As Long
    Dim SubKey As String, ValName As String, ValValue As String

    SubKey = "SoftwareMicrosoftWindowsCurrentVersionExplore r"
    ValName = "Demonstration"
    ValValue = "My string value"

    nRet = RegOpenKey(HKEY_LOCAL_MACHINE, SubKey, hKey)
    If (ERROR_SUCCESS = nRet) Then
    nRet = RegSetValueEx(hKey, ValName, 0&, REG_SZ, ByVal ValValue, _
    Len(ValValue) + 1)
    If (ERROR_SUCCESS <> nRet) Then
    MsgBox "SetValue failed."
    End If
    RegCloseKey (hKey)
    MsgBox "SetValue failed."
    End If
    Unload Me
    End Sub</pre>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Write to the registry (VB6 / NT4)

    Try VBScript, and the command line interpreter, cscript.exe. I'm not sure which Windows had it, but IE5.x would have installed it. <A target="_blank" HREF=>Exampl e</A>.

Posting Permissions

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