设置注册表使程序开机自启动

设置注册表使程序开机自启动
比较简单的做个注册表的设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
BOOL CCBKFourPicKM3Dlg::Register()
{
long ret = 0;
HKEY hKEY;
char chCurPath[MAX_PATH];
DWORD dwType = REG_SZ;
DWORD dwSize = MAX_PATH;
LPCTSTR lpRegPath = _T("Software\Microsoft\Windows\CurrentVersion\Run");

::GetModuleFileName(NULL, chCurPath, dwSize);
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRegPath, 0, KEY_WRITE, &hKEY);
if(ret != ERROR_SUCCESS)
{
RegCloseKey(hKEY);
return FALSE;
}
//Set Key
ret = RegSetValueEx(hKEY, "CBKZYFourPic", NULL, dwType,
(const unsigned char*)chCurPath, dwSize);
RegCloseKey(hKEY);
return TRUE;
}