Click to See Complete Forum and Search --> : Using registry...


Cedric Le Jalle
June 9th, 1999, 02:26 AM
Hi..
Here's a new question for you programmers..
I'm writing an application which should start up with Windows, but without having a 'myapp.lnk' in the start up menu..So, to do this, I thought I should use the registry, but the problem is that I never used registry before...So, imagine I have the full path of my app in

CString myPath = "c:\mypath\myapp.exe";



..then, how can I add it into registry so that the app start up automatically with Windows..I think that I should write it into
HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run
in the registry, is this right ?..
If so, how can I write myPath into it if it doesn't already exists ?..hey, also I would like to know how I can remove it ?
Could you send me some sample code..?
Thanks a lot.. :)
-Cedric-

Jose Wilson. M
June 10th, 1999, 12:28 AM
Hi,
You have to use the follwing piece of code. The RegOpenKeyEx creates the key for you. Use RegSetValueEx to set the path of the exe you want to write.


char filepath[] = "c:\mypath\myapp.exe";
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\",0,KEY_ALL_ACCESS,&hKey);
LONG i = RegSetValueEx( hKey,"YourApp",0,REG_SZ,(BYTE*) filepath,sizeof(filepath)+1);
RegCloseKey(hKey);




Regards,
M. Jose Wilson,
Software Engineer,
Aditi Technologies Pvt Ltd,
Bangalore,
India.

Cedric Le Jalle
June 10th, 1999, 05:28 AM
thanks a lot...I'll try this code.. :)

-Cedric-

Jason Teagle
June 10th, 1999, 06:28 AM
Sorry, RegOpenKeyEx() does NOT create the key if it does not already exist. The required function is RegCreateKeyEx(), which will create it if it does not exist or just open it if it does exist.

Jason Teagle
June 10th, 1999, 06:29 AM
RegOpenKeyEx() does NOT create the key if it does not already exist. The required function is RegCreateKeyEx(), which will create it if it does not exist or just open it if it does exist.