程序初始化中加:
char system[MAX_PATH];
char pathtofile[MAX_PATH];HMODULE GetModH = GetModuleHandle(NULL);
GetModuleFileName(GetModH,pathtofile,sizeof(pathtofile));
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_SET_VALUE,&hKey );
RegSetValueEx(hKey, "Writing to the Registry Example",
0,REG_SZ,(const unsigned char*)pathtofile,strlen(pathtofile));
RegCloseKey(hKey);