Link to home
Start Free TrialLog in
Avatar of Tai-San
Tai-San

asked on

problem with savesetting

how do i make savesetting save a registry value:

Path: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
ValueName: "Test"
ValueData: "some path"

then id like to delete that value again
Avatar of Mikal613
Mikal613
Flag of United States of America image

You have to make your own SAveSetting
Avatar of Tai-San
Tai-San

ASKER

example?
Option Explicit

'startup.frm
'Lee Weiner - 03/02/99

'This project shows you how to make the required registry
'to cause your app to start every time Windows is started.  It
'does NOT place a shortcut in the STARTUP folder.  YOU have to
'decide whether this is a good thing or not.  Personally, I
'believe that the user should have total control over his/her
'PC, and using this code makes it very difficult for the
'average user to stop the program from running on startup.

'The same subkey exists under both HKEY_LOCAL_MACHINE and
'HKEY_CURRENT_USER.  Use the code as is to ensure your program
'starts EVERY TIME THE MACHINE IS BOOTED.  Change to
'HKEY_CURRENT_USER as the first argument to the RegOpenKeyEx
'function call if you want the program to start up only when a
'particular user logs on.

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal ulOptions As Long, ByVal samDesired As Long, _
    phkResult 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

Private Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long

Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_SET_VALUE = &H2

Private Const REG_SZ = 1

Private Sub Command1_Click()
    Dim lRet As Long, lHnd As Long, lLen As Long
    Dim sKey As String, sData As String
   
    sKey = "software\microsoft\windows\currentversion\run"
   
    lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKey, 0&, _
            KEY_SET_VALUE, lHnd)
                'If the key opened successfully.
    If lRet = 0 Then
            'The string sData is the command line used to start
            'the app, and includes any command line parameters.
        sData = "c:\mydir\myapp.exe"
        lLen = Len(sData)
            'The second argument (in my example, "MyApp") is
            'the name of the app, what would ordinarily appear
            'in the Caption Bar.  As far as I can tell, it does
            'nothing important in this process, except to assign
            'a name for the new entry under the RUN key.  It can
            'be used to easily delete this entry.
        lRet = RegSetValueEx(lHnd, "MyApp", 0&, REG_SZ, _
                ByVal sData, lLen)
    Else
        MsgBox "OpenKey failed."
    End If
    lRet = RegCloseKey(lHnd)
End Sub

ASKER CERTIFIED SOLUTION
Avatar of fantasy1001
fantasy1001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial