• Write to the registry (VB6 / NT4)

    Author
    Topic
    #360796

    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!

    Thanks!

    – Linda

    Viewing 1 reply thread
    Author
    Replies
    • #544078

      There may be an easier way in VB, but I haven’t found it. hairout 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.

      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 = "SoftwareMicrosoftWindowsCurrentVersionExplorer"
          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)
          Else
              MsgBox "SetValue failed."
          End If
          Unload Me
      End Sub
    • #544109

      Try VBScript, and the command line interpreter, cscript.exe. I’m not sure which Windows had it, but IE5.x would have installed it. Example.

    Viewing 1 reply thread
    Reply To: Write to the registry (VB6 / NT4)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: