Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 17,951 times

Related Categories

Register Program to Start Up Automatically

-=D=-

This sample code shows you how to register your visual basic program on the windows startup registry. First of all, copy and past all below code to a module.

Option Explicit
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public 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
Public Const REG_SZ = 1 ' Unicode nul terminated String
Public Const REG_DWORD = 4 ' 32-bit number
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&


Public Sub SaveString(Hkey As Long, strPath As String, strValue As String, strdata As String)
   Dim keyhand As Long
   Dim r As Long
   r = RegCreateKey(Hkey, strPath, keyhand)
   r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
   r = RegCloseKey(keyhand)
End Sub

Next, to make the entry in the registry, use code like this (this only really needs to be done once, but could be called in Form_Load each time your app starts):

SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    App.ExeName, App.Path & "\" & App.ExeName & ".exe")

Hope this code will make you programming life easy...:D

Comments

  • Converting Picture to Binary

    Posted by Sindu on 29 May 2005

    Hey Guys

    How to convert picture files to binary?

    Please help me!

  • Posted by -=D=- on 14 Mar 2004

    yap u can do that oso,
    before that u may need to know how to del the registry key,(the question as amoibabe asked)...:DD

  • Run once

    Posted by Sir Limey on 14 Mar 2004

    Would it be easier to run a check of the change on start up and if present not run again:confused:

  • Posted by -=D=- on 25 Jan 2004

    sorry man, i jz finish my chinese new year...:D
    so may be late reply ur question, hope u can forgive me...:p

    to delete the register key u can using the following code
    [code]
    r = RegDeleteValue...

  • Posted by amoibade on 25 Jan 2004

    Well... It seems i failed on using RegDeleteKey properly. Can you provide me with some code please?

    Thank you very much for your help, i really appreciate it...