16,504
社区成员
发帖
与我相关
我的任务
分享
// 程序开机启动写入注册表
bool CSlitMachineApp::WriteKEY()
{
long lRet;
DWORD dwDisposition;
HKEY hAppKey = NULL;
LPCTSTR lpRun = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hAppKey, &dwDisposition);
if (lRet == ERROR_SUCCESS)
{
TCHAR pFileName[MAX_PATH] = { 0 };
//得到程序自身的全路径
DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH);
//添加一个子key,并设置值
lRet = RegSetValueEx(hAppKey, _T("DS"), 0, REG_SZ, (BYTE*)pFileName, dwRet );
//关闭注册表
RegCloseKey(hAppKey);
}
return true;
}
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_WOW64_64KEY, NULL, &hAppKey, &dwDisposition);
//or:
//lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpRun,0,KEY_READ|KEY_WRITE|KEY_WOW64_64KEY,&hAppKey);