void fsDownloads_GroupsMgr::DeleteGroup(LPCSTR pszGroup) { int grp = FindGroupByName (pszGroup); if (grp == -1) return; m_vGroups.del (grp); CRegKey key; key.Attach (m_hGroups); key.RecurseDeleteKey (pszGroup); key.Detach (); }
//------------------------------------------------------------------* HKEY CSysVarPool::OpenCommonBasepath(BOOL bWritable) { assert(g_StartParam != NULL); CRegKey keySW; CRegKey key4C; CRegKey keyApp; CRegKey keySysVar; CRegKey keyResult; LONG lRes; if (bWritable) { lRes = keySW.Open(HKEY_LOCAL_MACHINE, _T("Software")); } else { lRes = keySW.Open(HKEY_LOCAL_MACHINE, _T("Software"), KEY_READ); } if (lRes == ERROR_SUCCESS) { if (bWritable) { lRes = key4C.Create(keySW, g_cs4Control); } else { lRes = key4C.Open(keySW, g_cs4Control, KEY_READ); } if (lRes == ERROR_SUCCESS) { if (bWritable) { lRes = keyApp.Create(key4C, g_csApp); } else { lRes = keyApp.Open(key4C, g_csApp, KEY_READ); } if (lRes == ERROR_SUCCESS) { if (bWritable) { lRes = keySysVar.Create(keyApp, g_csSysVar); } else { lRes = keySysVar.Open(keyApp, g_csSysVar, KEY_READ); } if (lRes == ERROR_SUCCESS) { if (bWritable) { lRes = keyResult.Create(keySysVar, g_StartParam); } else { lRes = keyResult.Open(keySysVar, g_StartParam, KEY_READ); } } } } } return keyResult.Detach(); }
//------------------------------------------------------------------* HKEY CSysVarPool::OpenSysVarPath(BOOL bWritable) { HKEY hkBase = OpenCommonBasepath(bWritable); if (hkBase == NULL) { return NULL; } CRegKey keyBase; CRegKey keySRT; CRegKey keyRet; CString strEnum; strEnum.Format(_T("%d"), m_iEnumerator); keyBase.Attach(hkBase); switch (m_poolType) { case configGlobal: keyRet.Attach(keyBase.Detach()); break; case srtGlobal: { if (bWritable) { if (keySRT.Create(keyBase, g_csSoftRT) == ERROR_SUCCESS) { keyRet.Create(keySRT, strEnum); } } else { if (keySRT.Open(keyBase, g_csSoftRT, KEY_READ) == ERROR_SUCCESS) { keyRet.Open(keySRT, strEnum, KEY_READ); } } } break; case consoleGlobal: if (bWritable) { keyRet.Create(keyBase, g_csConsole); } else { keyRet.Open(keyBase, g_csConsole, KEY_READ); } break; default: assert(0); break; } if (!m_strSimplePath.IsEmpty()) { if (keyRet.m_hKey == NULL) { return NULL; } CRegKey keyPath; if (bWritable) { keyPath.Create(keyRet, m_strSimplePath); } else { keyPath.Open(keyRet, m_strSimplePath, KEY_READ); } keyRet.Close(); keyRet.Attach(keyPath.Detach()); } return keyRet.Detach(); }
// AppID Helpers HRESULT TCUserAccount::ResolveAppID(LPWSTR pszAppID, HKEY* phKey, REGSAM samDesired) { USES_CONVERSION; // Is the specified string a GUID string? GUID appid; HRESULT hr = CLSIDFromString(pszAppID, &appid); if (FAILED(hr)) { // Is the specified string a ProgID? if (FAILED(hr = CLSIDFromProgID(pszAppID, &appid))) return hr; // Convert the ProgID's CLSID to a string _VERIFYE(StringFromGUID2(appid, pszAppID, 48)); // Recursively call into ourself to resolve the CLSID string into an AppID return ResolveAppID(pszAppID, phKey, samDesired); } // Convert the AppID back to a string RETURN_FAILED(StringFromGUID2(appid, pszAppID, 48)); // Format a string for the AppID's registry key TCHAR szKey[_MAX_PATH]; _stprintf(szKey, TEXT("AppID\\%ls"), pszAppID); // Does the AppID exist in the registry? LONG lr; CRegKey key; if (ERROR_SUCCESS != (lr = key.Open(HKEY_CLASSES_ROOT, szKey, samDesired))) { // Format a string for the CLSID's registry key TCHAR szKey[_MAX_PATH]; _stprintf(szKey, TEXT("CLSID\\%ls"), pszAppID); // Open the CLSID's registry key if (ERROR_SUCCESS != (lr = key.Open(HKEY_CLASSES_ROOT, szKey, samDesired))) return HRESULT_FROM_WIN32(lr); // Read the CLSID's AppID value TCHAR szAppID[48]; DWORD cbData = sizeof(szAppID); if (ERROR_SUCCESS != (lr = RegQueryValueEx(key, TEXT("AppID"), 0, NULL, (BYTE*)szAppID, &cbData))) return HRESULT_FROM_WIN32(lr); // Copy the AppID String to the [in/out] parameter wcscpy(pszAppID, T2CW(szAppID)); // Recursively call into ourself to resolve and verify the APPID string return ResolveAppID(pszAppID, phKey, samDesired); } // Detach the AppID key from the CRegKey object if (phKey) *phKey = key.Detach(); // Indicate success return S_OK; }
/* GetPlatformInfo() */ void CWindowsVersion::GetPlatformInfo(LPSTR pBuffer,int cbBuffer) { CRegKey regkey; char key[REGKEY_MAX_KEY_NAME+1]; char value[REGKEY_MAX_KEY_VALUE+1]; int n = 0; n += _snprintf(pBuffer+n,cbBuffer-1-n,"%s - %s\r\n",m_szWindowsPlatform,m_szOsType); // NT if(m_OsVersionType==WINDOWS_NT || m_OsVersionType==WINDOWS_2000 || m_OsVersionType==WINDOWS_XP || m_OsVersionType==WINDOWS_VISTA || m_OsVersionType==WINDOWS_SEVEN) { regkey.Attach(HKEY_LOCAL_MACHINE); strcpyn(key,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",sizeof(key)); if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS) { DWORD dwSize; dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"CurrentBuildNumber",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"build: %s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"CurrentType",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"type: %s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"ProductId",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"product id: %s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"RegisteredOrganization",&dwSize)==ERROR_SUCCESS) if(value[0]!='\0') n += _snprintf(pBuffer+n,cbBuffer-1-n,"registered to: %s\r\n",value); regkey.Close(); } regkey.Detach(); regkey.Attach(HKEY_LOCAL_MACHINE); strcpyn(key,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",sizeof(key)); if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS) { DWORD dwSize; dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"VendorIdentifier",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"\r\nMain CPU:\r\n%s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"Identifier",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"%s\r\n",value); DWORD dwValue = 0L; if(regkey.QueryValue(dwValue,"~MHz")==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"%ld Mhz\r\n",dwValue); regkey.Close(); } regkey.Detach(); } else // Cartoons { regkey.Attach(HKEY_LOCAL_MACHINE); strcpyn(key,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",sizeof(key)); if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS) { DWORD dwSize; dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"VersionNumber",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"version number: %s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"ProductId",&dwSize)==ERROR_SUCCESS) n += _snprintf(pBuffer+n,cbBuffer-1-n,"product id: %s\r\n",value); dwSize = sizeof(value); memset(value,'\0',sizeof(value)); if(regkey.QueryValue(value,"RegisteredOrganization",&dwSize)==ERROR_SUCCESS) if(value[0]!='\0') n += _snprintf(pBuffer+n,cbBuffer-1-n,"registered to: %s\r\n",value); regkey.Close(); } regkey.Detach(); } }