VC写入注册表,使程序开机启动


 if(autoopendlp == 1)
 {
  HKEY hKey;
  LPCTSTR lpRun = "Software//Microsoft//Windows//CurrentVersion//Run";
  long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);
  if(lRet == ERROR_SUCCESS)
  {
   char pFileName[MAX_PATH] = {0};
   DWORD dwRet = GetModuleFileName(GetModuleHandle(AfxGetApp()-> m_pszAppName), pFileName, MAX_PATH);
   lRet = RegSetValueEx(hKey, "ctrl", 0, REG_SZ, (LPBYTE)pFileName, strlen(pFileName));

   MessageBox(pFileName);
   if(lRet != ERROR_SUCCESS)
   {
    AfxMessageBox("系统参数错误,不能随系统启动");
   }
  }else
   RegDeleteValue(hKey,"ctrl");
  RegCloseKey(hKey);
 }

posted on 2012-07-06 13:42  wps712  阅读(1178)  评论(0编辑  收藏  举报

导航