C++ 设置自动启动
WCHAR pFileName[MAX_PATH] = {0}; //得到程序自身的全路径 DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH); HKEY hKey; REGSAM flag = KEY_WOW64_64KEY; DWORD dwDisposition = REG_OPENED_EXISTING_KEY; LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS | flag, &hKey); if ( ERROR_SUCCESS != lRet){ AfxMessageBox(L"打开注册表失败"); return; } lRet = ::RegSetValueEx(hKey, TEXT("TaiSau_SmartCam"), NULL, REG_SZ, (LPBYTE)pFileName, wcslen(pFileName) * sizeof(WCHAR) + 1); //设置注册表项 if ( ERROR_SUCCESS != lRet){ AfxMessageBox(L"写注册表失败"); return; } ::RegCloseKey(hKey); //与RegCreateKeyEx配对写