开机自启c++代码_c++开机自启代码怎么写-爱代码爱编程
完整代码:
#include <stdio.h>
#include <Shlobj.h>
#pragma comment(lib, "shell32.lib")
using namespace std;
BOOL AutoRun_Startup(const char *lpszSrcFilePath,const char *lpszDestFileName)
{
char szStartupPath[MAX_PATH] = { 0 };
char szDestFilePath[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szStartupPath, CSIDL_STARTUP, TRUE);
wsprintf(szDestFilePath, "%s\\%s", szStartupPath, lpszDestFileName);
CopyFile(lpszSrcFilePath, szDestFilePath, FALSE);
return TRUE;
}
int main(int argc, char * argv[])
{
AutoRun_Startup("c://main.exe", "main.exe");
return 0;
}