开机自动运行

// 开机自动运行 BOOL SetAutoRun(TCHAR* pszExeName, TCHAR* pszPath, BOOL bAddOrRemove) { HKEY hRegKey = NULL; BOOL bResult = FALSE; TCHAR* str = L"Software//Microsoft//Windows//CurrentVersion//Run"; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, 0, KEY_WRITE, &hRegKey) == ERROR_SUCCESS) { if(bAddOrRemove) { if(RegSetValueEx(hRegKey, pszExeName, 0, REG_SZ, (BYTE*)pszPath, (lstrlen(pszPath) + 1) * 2) == ERROR_SUCCESS) bResult = TRUE; else bResult = FALSE; } else { if(RegDeleteValue(hRegKey, pszExeName) == ERROR_SUCCESS) bResult = TRUE; else bResult = FALSE; } RegCloseKey(hRegKey); } else bResult = FALSE; return bResult; }

 

成功返回TRUE,失败返回FALSE。

你可能感兴趣的:(null,byte)