You can add your appliaction to the system startup using the calss CRegKey
Here is the code snippet
#include "atlbase.h" //Required for CRegKey class
void RemAutoStart() // To remove old entry
{
CString strKeyName;
strKeyName = _T("myAppAutoStart");
CRegKey mKey;
mKey.Create(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
REG_NONE,REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL,NULL);
mKey.DeleteValue(strKeyName);
mKey.Close();
}
void AddAutoStart() // To add new entry
{
RemAutoStart();
CString strKeyName;
strKeyName = _T("myAppAutoStart");
TCHAR sExeFilePath[490];
DWORD length;
length = ::GetModuleFileName(NULL, sExeFilePath, 490);
if(!length)
return;
CString sFullExeCommand;
sFullExeCommand.Format(_T("%s -AutoStart"), sExeFilePath);
CRegKey mKey;
mKey.Create(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
REG_NONE,REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL,NULL);
mKey.SetStringValue(strKeyName, sFullExeCommand);
mKey.Close();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment