i am using dev-c++ compiler (with MinGW) lately.and i am liking it very much .
loading a program at start-up automatically ( program is loaded automatically when system starts) can be done in many ways ,however i find following two ways easier.
in the system Startup’s folder
by making some changes in registry
using system startup folder is easy.you just have to place the shortcut of the program you want to run at the startup in this folder. the second method is what i am interested in ,by making changes in registry it is less accessible for the user,and he/she must be familiar with the registry editors (regedit,reshack etc) to change it back.
you can find a lot of information on net on which you particular key you should access. here i am using
this key is sufficient to launch any program when a user logs in.you can already see the entries of program which are automatically loaded at the start-up.
if you don’t wish to load any of those at the start-up you can delete them by using delete key.
if you want to add any click on edit in the menu bar and then new >>and then click on string value. give it any name you want.double click on the newly created entry fill the data ,as shown in image below.and press ok.
all these things was about doing things manually.but the main emphasis here is doing it thru code (c++).
i assume you are already using windows.hheader file.you should also use winreg.h to use registry fuctions.
we will be using three functions
RegCreateKeyEx : to create a new key if it doesn’t exist or to open an existing one.
RegSetValueEx : to set value for particular key opened.
RegCloseKey: to close the handle. (not always necessary but its a good programming practise to use it)
i won’t be going into details of the syntax.you can find it in msdn and number of other places.you will have to have a variable of type HKEY
0, “”, 0, KEY_WRITE, 0,&Key, &n);
RegSetValueEx(Key,”name of program”, 0, REG_SZ,(LPBYTE)&(“address of prog”), sizeof(address of program you want to run at startup));
RegCloseKey (Key);
important :
use double backslash to give address of the program you want to run at the startup.
example: if you want to run notepad at startup ,the address you have to give is
“c:\\windows\\notepad.exe” instead of “c:\windows\notepad.exe”
How To Load A Program Automatically at Startup (thru code)
i am using dev-c++ compiler (with MinGW) lately.and i am liking it very much .
loading a program at start-up automatically ( program is loaded automatically when system starts) can be done in many ways ,however i find following two ways easier.
using system startup folder is easy.you just have to place the shortcut of the program you want to run at the startup in this folder. the second method is what i am interested in ,by making changes in registry it is less accessible for the user,and he/she must be familiar with the registry editors (regedit,reshack etc) to change it back.
you can find a lot of information on net on which you particular key you should access. here i am using
HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\Run
this key is sufficient to launch any program when a user logs in.you can already see the entries of program which are automatically loaded at the start-up.
if you don’t wish to load any of those at the start-up you can delete them by using delete key.
if you want to add any click on edit in the menu bar and then new >>and then click on string value. give it any name you want.double click on the newly created entry fill the data ,as shown in image below.and press ok.
all these things was about doing things manually.but the main emphasis here is doing it thru code (c++).
i assume you are already using windows.h header file.you should also use winreg.h to use registry fuctions.
we will be using three functions
i won’t be going into details of the syntax.you can find it in msdn and number of other places.you will have to have a variable of type HKEY
HKEY Key;
long int n;
RegCreateKeyEx(HKEY_LOCAL_MACHINE,”SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”,
0, “”, 0, KEY_WRITE, 0,&Key, &n);
RegSetValueEx(Key,”name of program”, 0, REG_SZ,(LPBYTE)&(“address of prog”), sizeof(address of program you want to run at startup));
RegCloseKey (Key);
important :
use double backslash to give address of the program you want to run at the startup.
example: if you want to run notepad at startup ,the address you have to give is
“c:\\windows\\notepad.exe” instead of “c:\windows\notepad.exe”