简单设置程序自启动
/*
example: SetAutoRun("abc","c:\\abc.exe");
*/
void SetAutoRun(const char* szValueName,const char* szData)
{
HKEY hKey;
DWORD dwRet = RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey);
if (dwRet != ERROR_SUCCESS)
return;
char szVal[MAX_PATH] = {0};
DWORD dwLen = MAX_PATH;
memset(szVal,0,MAX_PATH);
DWORD dwType = REG_SZ;
dwRet = RegQueryValueEx(hKey,szValueName,NULL,&dwType,(LPBYTE)szVal,&dwLen);
if (dwRet == ERROR_SUCCESS)
{
if (stricmp(szVal,szData) != 0)
{
RegSetValueEx(hKey,szValueName,0,REG_SZ,(const BYTE*)szData,strlen(szData));
}
}
else
{
RegSetValueEx(hKey,szValueName,0,REG_SZ,(const BYTE*)szData,strlen(szData));
}
RegCloseKey(hKey);
}