Results 1 to 2 of 2

Thread: How to write to Registry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    How to write to Registry

    Hello there,
    I am trying to write file to registry, as I knew this method is working for Windows XP :
    Code:
    Private Sub Form_Load()
    'On Error Resume Next
    
    Dim regrun ' Create a file and write for Registry
    
    '**********************************************
    'App.TaskVisible = False 'Make is unvisible during running
    '**********************************************
    Set regrun = CreateObject("Wscript.shell")
    regrun.regwrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\Kalimantan Internet", "c:\Kalimantan_Internet.exe"
    
    End Sub
    Today I trying do this on Windows 7 is not working.

    Could anyone help me, probably there is needed an API to working in above Windows 7.

    Thank you.
    Rukmana Badjuri.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2017
    Posts
    380

    Re: How to write to Registry

    The most likely reason for the apparent failure is because your program is not running elevated (Run as administrator). Beginning with Vista, programs can no longer write to protected file system locations and Registry hives (such as HKLM) without explicit permission from an administrator account.

    There are at least 3 approaches to accomplish your goal: 1) mark your application as always requiring elevation (via an app manifest), 2) request elevation as needed (via the "runas" verb) and 3) modify your program so that it doesn't need elevation anymore. According to Microsoft's guidelines, you should avoid resorting to approaches 1 and 2 whenever possible. Fortunately in your case, there is a way to avoid the need for elevation - rather than writing to the HKEY_LOCAL_MACHINE hive, store your settings under the HKEY_CURRENT_USER hive instead.

    Code:
    Private Sub Form_Load()
        Const HKCU_RUN = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\"
    
        CreateObject("WScript.Shell").RegWrite HKCU_RUN & "Kalimantan Internet", "C:\Kalimantan_Internet.exe"
    End Sub

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