自动启动代码: void CServerApp::SetAutoRun() { HKEY hKey; char* szRegpath = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; long lRet; // 打开注册表 lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegpath, 0, KEY_ALL_ACCESS, &hKey); if (lRet != ERROR_SUCCESS) { AfxMessageBox("打开自动启动注册表失败!"); RegCloseKey(hKey); return; } // 得到当前文件的路径 char szFilePath[MAX_PATH]; DWORD dwRet; dwRet = GetModuleFileName(NULL, szFilePath, MAX_PATH); if (dwRet == 0) { AfxMessageBox("得到当前文件路径失败!"); return; } // 将当前路径增加到该注册表中 lRet = RegSetValueEx(hKey, "AttendServer", 0, REG_SZ, (CONST BYTE*)&szFilePath, strlen(szFilePath) + 1); if (lRet != ERROR_SUCCESS) { AfxMessageBox("写入自动启动注册表失败!"); RegCloseKey(hKey); return; } RegCloseKey(hKey); } 取消自动运行代码: void CServerApp::CancelAutoRun() { HKEY hKey; char* szRegpath = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; long lRet; // 打开注册表 lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegpath, 0, KEY_ALL_ACCESS, &hKey); if (lRet != ERROR_SUCCESS) { AfxMessageBox("打开自动启动注册表失败!"); RegCloseKey(hKey); return; } lRet = RegDeleteValue(hKey, "AttendServer"); if (lRet != ERROR_SUCCESS) { AfxMessageBox("删除该软件在自动启动注册表设置失败!"); RegCloseKey(hKey); return; } RegCloseKey(hKey); }

相关文章:

  • 2021-11-08
  • 2022-12-23
  • 2022-02-07
  • 2021-11-12
  • 2021-12-30
  • 2021-09-15
  • 2021-05-06
  • 2021-06-06
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2021-12-04
  • 2021-06-15
  • 2022-02-15
相关资源
相似解决方案