Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

load with windows (urgent)

Posted on 1998-12-18
3
Medium Priority
?
182 Views
Last Modified: 2010-05-03
i need to set an option in my app to load with windows (like ICQ for instance)
please be quick
thanks
0
Comment
Question by:acorp
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
ID: 1451361
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
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
Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long

Public Const REG_SZ As Long = 1     'Add association
Public Const REG_DWORD As Long = 4
Public Const HKEY_LOCAL_MACHINE = &H80000002

'Internal procedures
Public Sub CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)
   Dim hKey As Long
   RegCreateKeyEx lPredefinedKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hKey, r
   RegCloseKey hKey
End Sub
Public Sub SetKeyValue(sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
    Dim hKey As Long
    RegOpenKeyEx HKEY_LOCAL_MACHINE, sKeyName, 0, KEY_ALL_ACCESS, hKey
    SetValueEx hKey, sValueName, lValueType, vValueSetting
    RegCloseKey hKey
End Sub
Public Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
    Dim nValue As Long
    Dim sValue As String
    Select Case lType
        Case REG_SZ
             sValue = vValue & Chr$(0)
             SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
        Case REG_DWORD
            nValue = vValue
            SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, nValue, 4)
    End Select
End Function

'Actual code:
SetKeyValue "Software\Microsoft\Windows\CurrentVersion\Run", "MyApp", "C:\files\App.Exe", REG_SZ
0
 

Author Comment

by:acorp
ID: 1451362
thanks, it's working
but i need also to delete the key i created with this code
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1451363
Use RegOpenKey to open it (as shown in CreateKey), and RegDeleteValue to delete the value
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question