-
Using registry...
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-
-
Re: Using registry...
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.
-
Re: Using registry...
thanks a lot...I'll try this code.. :)
-Cedric-
-
Re: Using registry...
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.
-
Re: Using registry...
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.