windows下设置开机自启动(c语言)
#include <windows.h>
#include <stdio.h>
int main()
{
HKEY hRoot = HKEY_LOCAL_MACHINE;
char *szSubKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
char *szModule = "D:\\software\\eclipse\\eclipse.exe";
HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if(lRet != ERROR_SUCCESS)
{
printf("failed to find !\n");
return -1;
}
lRet = RegSetValueEx(hKey, "eclipse", 0, REG_SZ, (BYTE *)szModule, strlen(szModule));
RegCloseKey(hKey);
if(lRet != ERROR_SUCCESS)
{
printf("failed to reg !\n");
return -1;
}
return 0;
}