看帖子,发现一个MFC开机自启动的方法,留着也许以后用的到:
- #include <Windows.h>
- #include <tchar.h>
- int main(void)
- {
- HKEY hKey;
- HKEY hNewKey;
- DWORD dwDisposition=0;
- __try
- {
- char binPath[MAX_PATH]="D:\\Program Files\\QQ\\Bin\\QQ.exe";//在这里设置你要启动的程序的路径
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
- 0,KEY_ALL_ACCESS,&hKey)!=ERROR_SUCCESS)
- __leave;
- if(RegSetValueEx(hKey,
- _T("AutoStart"),
- 0,REG_SZ,(const BYTE*)binPath,
- strlen(binPath)+1)!=ERROR_SUCCESS)
- __leave;
- }
- __finally
- {
- RegCloseKey(hKey);
- }
- system("pause");
- return(0);
- }
本文介绍了一种使用MFC实现程序开机自启动的方法。通过注册表设置,具体步骤包括打开注册表项、写入程序路径等。适用于需要开机即运行的应用场景。
810

被折叠的 条评论
为什么被折叠?



