Search Tools Links Login

Start your application when windows starts

Many people want to know how to start there application when windows starts and not simply by putting a shortcut in the windows startup folder.This article will show you how to do this using vb and a few api's

Original Author: venky_dude


Start Application as 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 


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


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:myprogmyprog.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.Send your comments to
.Visit my homepage
for some cool vb codes.

About this post

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


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.