BOOL ScreenSaverConfig::IsEnabled( BOOL &enable ) { const TCHAR config_key_path[] = TEXT("Control Panel\\Desktop"); const TCHAR active_name[] = TEXT("ScreenSaveActive"); const TCHAR security_name[] = TEXT("ScreenSaverIsSecure"); CString active_value; if (!RegQueryString(HKEY_CURRENT_USER, config_key_path, active_name, active_value)) { return FALSE; } CString security_value; if (!RegQueryString(HKEY_CURRENT_USER, config_key_path, security_name, security_value)) { return FALSE; } enable = active_value.Compare(TEXT("1")) == 0 && security_value.Compare(TEXT("1")) == 0; return TRUE; }
bool InstanceManager::IsAutoStart() { HKEY hkey; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_READ, &hkey) != ERROR_SUCCESS) return false; string path; RegQueryString(hkey, "Apctray", path); RegCloseKey(hkey); return !path.empty(); }
BOOL __stdcall USBHistoryLog::EnumKey(HKEY key, LPCTSTR subkey_name, LPFILETIME file_time, PVOID context) { Json::Value *log_value = (Json::Value *)context; do { ULONG flags = KEY_READ; if (IsWow64()) { flags |= KEY_WOW64_64KEY; } CRegKey reg_key; LONG l = reg_key.Open(key, subkey_name, flags); if (l != ERROR_SUCCESS) { break; } TCHAR key_name[1024] = {0}; ULONG key_name_length = _countof(key_name); FILETIME ft = {0}; if (FAILED(reg_key.EnumKey(0, key_name, &key_name_length, &ft))) { break; } CString usb_friendly_name; if (RegQueryString(reg_key.m_hKey, key_name, TEXT("FriendlyName"), usb_friendly_name)) { if (!usb_friendly_name.IsEmpty()) { Json::Value item; item["device_name"] = CT2A(usb_friendly_name.GetString()).m_psz; FILETIME lft; FileTimeToLocalFileTime(&ft, &lft); SYSTEMTIME st; FileTimeToSystemTime(&lft, &st); CStringA access_time; access_time.Format("%04u%02u%02u%02u%02u%02u", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); item["access_time"] = access_time.GetString(); log_value->append(item); } } } while (0); return TRUE; }
InstanceManager::InstanceConfig InstanceManager::ReadConfig(HKEY key, const string & id) { InstanceConfig config; config.mcfg = DEFAULT_CONFIG; config.mcfg.id = id; // Read instance config from registry HKEY subkey; if (RegOpenKeyExA(key, id.c_str(), 0, KEY_READ, &subkey) == ERROR_SUCCESS) { DWORD port; RegQueryString(subkey, "host", config.mcfg.host); RegQueryDWORD(subkey, "port", port); RegQueryDWORD(subkey, "refresh", config.mcfg.refresh); RegQueryDWORD(subkey, "popups", config.mcfg.popups); RegQueryDWORD(subkey, "order", config.order); RegCloseKey(subkey); config.mcfg.port = (unsigned short) port; } return config; }
DWORD WINAPI ReadPerInstanceRegistryParameters ( _In_ HKEY hKey, _In_ PSVCHOST_OPTIONS pOptions ) { DWORD dwError, dwData; HKEY hSubKey; /* We should have a name for this service group... */ ASSERT(pOptions->ServiceGroupName); /* Query the group to see what services are part of it */ dwError = RegQueryString(hKey, pOptions->ServiceGroupName, REG_MULTI_SZ, (PBYTE*)&ServiceNames); if ((dwError == ERROR_SUCCESS) && ((ServiceNames == NULL) || (*ServiceNames == UNICODE_NULL))) { /* If the key exists but there's no data, fail */ return ERROR_INVALID_DATA; } /* Open the key for this group */ if (RegOpenKeyExW(hKey, pOptions->ServiceGroupName, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS) { /* If we couldn't, bail out */ return dwError; } /* Check if we should initialize COM */ if (RegQueryDword(hSubKey, L"CoInitializeSecurityParam", &dwData) == ERROR_SUCCESS) { /* Yes, remember the parameter to be sent when we do so */ pOptions->CoInitializeSecurityParam = dwData; } /* Also, if COM is requested, we must read a bunch more data... */ if (pOptions->CoInitializeSecurityParam) { /* First, read the authentication level, use a default if none is set */ if (RegQueryDword(hSubKey, L"AuthenticationLevel", &dwData)) { pOptions->AuthenticationLevel = RPC_C_AUTHN_LEVEL_PKT; } else { pOptions->AuthenticationLevel = dwData; } /* Do the same for the impersonation level */ if (RegQueryDword(hSubKey, L"ImpersonationLevel", &dwData)) { pOptions->ImpersonationLevel = RPC_C_IMP_LEVEL_IDENTIFY; } else { pOptions->ImpersonationLevel = dwData; } /* Do the same for the authentication capabilities */ if (RegQueryDword(hSubKey, L"AuthenticationCapabilities", &dwData)) { pOptions->AuthenticationCapabilities = EOAC_NO_CUSTOM_MARSHAL | EOAC_DISABLE_AAA; } else { pOptions->AuthenticationCapabilities = dwData; } } /* Check if we need a specific RPC stack size, if not, we'll set it later */ if (!RegQueryDword(hSubKey, L"DefaultRpcStackSize", &dwData)) { pOptions->DefaultRpcStackSize = dwData; } /* Finally, check if the services should be marked critical later on */ if (!RegQueryDword(hSubKey, L"SystemCritical", &dwData)) { pOptions->SystemCritical = dwData; } /* All done reading the settings */ RegCloseKey(hSubKey); return dwError; }