Search Tools Links Login

Auto Run Registry Entry


If you have ever needed to have your program start at the same time as windows starts without putting the program into the start up menu but have been unable to figure out how to do it then just follow the following text.

Original Author: Dean lancaster

Code

What you have to do to use this code is:
In your project (for example, form_load())
insert the following text somewhere that would be useful to your project:




Call SetStringValue(HKEY_LOCAL_MACHINE, "Softwaremicrosoftwindowscurrentversion un", "Currency", App.Path + "" + App.EXEName + ".exe")



This code will put the current project path and the current project name in the windows auto run section in the windows registry.

The benfit of this is so that you can have your program start as windows starts.

Add to your project a module


project -> add module


and insert the following code




Public Exist As Boolean


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 Const REG_SZ = 1


Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long


Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long


Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long


Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long


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


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



After this has been added also add the following code to your module file



Public Sub SetStringValue(Hkey As Long, strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
Dim i As Long
'Create the key
i = RegCreateKey(Hkey, strPath, keyhand)
'Set the value
i = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
'Close the key
i = RegCloseKey(keyhand)
End Sub




This then should allow the setstringvalue to be accessed and the information you need be put into the windows auto run registry.

I must thank T. L. Phillips for the code for the module form, that is where i optained it.

Hope you like the code! :)

if you need help with it (although you shouldn't) mail me :)
(As for the Link to mr phillips's website, that is beyond my control and the link that is on his source submissions)

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 88 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.