Venky's World

     

     

    Start Your application when windows starts

    We shall use a few api function which are  


    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 RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long





    These api's are used for the following purpose


    1.RegOpenKey - To open a key for reading/writing values 
    2.RegSetValue - To write values into a key


    We shall also use a few constants 

    Private Const HKEY_CURRENT_USER = &H80000001

    Private Const REG_SZ = 1


    In order to make our applications start when windows starts we have to add an entry in the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run



    To make an entry into a key we need to get the 'handle' or a unique identifier for that key.We get this 'unique id by opening the key.We do this in the following way

    Dim result As Long
    Dim keyres As Long
    result=RegOpenKey(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Run",keyres)


    If the function executed correctly we will get 0 as result and keyres will contain the unique id for that key.

    After opening the key we will put in a value into it .We can do it this way


    Dim file As String
    Dim entry as string
    entry = "Myprog"
    file = "c:\myprog\myprog.exe"
    result = RegSetValueEx(keyres, entry, 0, REG_SZ, ByVal file, Len(file))



    you can input your program's path into file and run the function.And entry is the name you give to the value you are trying to put in.If the function executed successfully result will contain 0 .Restart your computer and your program should start as soon as windows starts.