static BOOL InputList_PrepareUserRegistry(VOID) { BOOL bResult = FALSE; HKEY hTempKey = NULL; HKEY hKey = NULL; if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Keyboard Layout", 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { RegDeleteKeyW(hKey, L"Preload"); RegDeleteKeyW(hKey, L"Substitutes"); RegCloseKey(hKey); } if (RegCreateKeyW(HKEY_CURRENT_USER, L"Keyboard Layout", &hKey) != ERROR_SUCCESS) { goto Cleanup; } if (RegCreateKeyW(hKey, L"Preload", &hTempKey) != ERROR_SUCCESS) { goto Cleanup; } RegCloseKey(hTempKey); if (RegCreateKeyW(hKey, L"Substitutes", &hTempKey) != ERROR_SUCCESS) { goto Cleanup; } RegCloseKey(hTempKey); bResult = TRUE; Cleanup: if (hTempKey != NULL) RegCloseKey(hTempKey); if (hKey != NULL) RegCloseKey(hKey); return bResult; }
/*********************************************************************** * drvSetDefaultCommConfigW (SERIALUI.@) * * Used by Win98 KERNEL to set the default config for a COMM port * FIXME: uses the wrong registry key... should use a digit, not * the comm port name. */ BOOL WINAPI drvSetDefaultCommConfigW( LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize) { HKEY hKeyReg=0, hKeyPort=0; WCHAR szKeyName[100]; DWORD r,dwDCBSize; static const WCHAR fmt[] = {'%','s','\\','%','s',0 }; TRACE("%p %p %lx\n",lpszDevice,lpCommConfig,dwSize); if(!lpCommConfig) return FALSE; if(dwSize < sizeof (COMMCONFIG)) return FALSE; r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg); if(r != ERROR_SUCCESS) return FALSE; snprintfW(szKeyName, sizeof(szKeyName)/sizeof(WCHAR), fmt, lpszCommKey ,lpszDevice); r = RegCreateKeyW(hKeyReg, szKeyName, &hKeyPort); if(r == ERROR_SUCCESS) { dwDCBSize = sizeof (DCB); r = RegSetValueExW( hKeyPort, lpszDCB, 0, REG_BINARY, (LPBYTE)&lpCommConfig->dcb,dwDCBSize); TRACE("write key r=%ld\n",r); RegCloseKey(hKeyPort); } RegCloseKey(hKeyReg); return (r==ERROR_SUCCESS); }
/* good1() uses if(globalReturnsFalse()) instead of if(globalReturnsTrue()) */ static void good1() { if(globalReturnsFalse()) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); } else { { wchar_t * keyName = L"TEST\\TestKey"; HKEY hKey; /* FIX: Call RegCreateKeyW() with HKEY_CURRENT_USER */ if (RegCreateKeyW( HKEY_CURRENT_USER, keyName, &hKey) != ERROR_SUCCESS) { printLine("Registry key could not be created"); } else { printLine("Registry key created successfully"); RegCloseKey(hKey); } } } }
static BOOL ConnectRegistry( IN HKEY RootKey, IN PCMHIVE HiveToConnect, IN LPCWSTR Path) { NTSTATUS Status; MEMKEY NewKey; LONG rc; Status = CmiInitializeTempHive(HiveToConnect); if (!NT_SUCCESS(Status)) { DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status); return FALSE; } /* Create key */ rc = RegCreateKeyW( RootKey, Path, (PHKEY)&NewKey); if (rc != ERROR_SUCCESS) return FALSE; NewKey->RegistryHive = HiveToConnect; NewKey->KeyCellOffset = HiveToConnect->Hive.BaseBlock->RootCell; NewKey->KeyCell = (PCM_KEY_NODE)HvGetCell (&HiveToConnect->Hive, NewKey->KeyCellOffset); return TRUE; }
BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name, DWORD *value) { static const WCHAR safer[] = { 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\', 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m', 'C','e','r','t','i','f','i','c','a','t','e','s','\\', 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\', 'S','a','f','e','r',0 }; HKEY key; LONG rc; BOOL ret = FALSE; TRACE("(%s, %p)\n", debugstr_w(name), value); rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key); if (rc == ERROR_SUCCESS) { DWORD size = sizeof(DWORD); if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size)) ret = TRUE; RegCloseKey(key); } return ret; }
/********************************************************************** * DEVENUM_CreateAMCategoryKey (INTERNAL) * * Creates a registry key for a category at HKEY_CURRENT_USER\Software\ * Microsoft\ActiveMovie\devenum\{clsid} */ static HRESULT DEVENUM_CreateAMCategoryKey(const CLSID * clsidCategory) { WCHAR wszRegKey[MAX_PATH]; HRESULT res = S_OK; HKEY hkeyDummy = NULL; strcpyW(wszRegKey, wszActiveMovieKey); if (!StringFromGUID2(clsidCategory, wszRegKey + strlenW(wszRegKey), sizeof(wszRegKey)/sizeof(wszRegKey[0]) - strlenW(wszRegKey))) res = E_INVALIDARG; if (SUCCEEDED(res)) { LONG lRes = RegCreateKeyW(HKEY_CURRENT_USER, wszRegKey, &hkeyDummy); res = HRESULT_FROM_WIN32(lRes); } if (hkeyDummy) RegCloseKey(hkeyDummy); if (FAILED(res)) ERR("Failed to create key HKEY_CURRENT_USER\\%s\n", debugstr_w(wszRegKey)); return res; }
/************************************************************************* * AddERExcludedApplicationW [FAULTREP.@] * * Adds an application to a list of applications for which fault reports * shouldn't be generated * * PARAMS * lpAppFileName [I] The filename of the application executable * * RETURNS * TRUE on success, FALSE of failure * * NOTES * Wine doesn't use this data but stores it in the registry (in the same place * as Windows would) in case it will be useful in a future version * */ BOOL WINAPI AddERExcludedApplicationW(LPCWSTR lpAppFileName) { WCHAR *bslash; DWORD value = 1; HKEY hkey; LONG res; TRACE("(%s)\n", wine_dbgstr_w(lpAppFileName)); bslash = strrchrW(lpAppFileName, '\\'); if (bslash != NULL) lpAppFileName = bslash + 1; if (*lpAppFileName == '\0') { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } res = RegCreateKeyW(HKEY_LOCAL_MACHINE, SZ_EXCLUSIONLIST_KEY, &hkey); if (!res) { RegSetValueExW(hkey, lpAppFileName, 0, REG_DWORD, (LPBYTE)&value, sizeof(value)); RegCloseKey(hkey); } return !res; }
/*********************************************************************** * MSACM_WriteCache */ static BOOL MSACM_WriteCache(const WINE_ACMDRIVERID *padid) { LPWSTR key = MSACM_GetRegistryKey(padid); HKEY hKey; if (!key) return FALSE; if (RegCreateKeyW(HKEY_LOCAL_MACHINE, key, &hKey)) goto errCleanUp; if (RegSetValueExA(hKey, "cFormatTags", 0, REG_DWORD, (const void*)&padid->cFormatTags, sizeof(DWORD))) goto errCleanUp; if (RegSetValueExA(hKey, "cFilterTags", 0, REG_DWORD, (const void*)&padid->cFilterTags, sizeof(DWORD))) goto errCleanUp; if (RegSetValueExA(hKey, "fdwSupport", 0, REG_DWORD, (const void*)&padid->fdwSupport, sizeof(DWORD))) goto errCleanUp; if (RegSetValueExA(hKey, "aFormatTagCache", 0, REG_BINARY, (void*)padid->aFormatTag, padid->cFormatTags * sizeof(padid->aFormatTag[0]))) goto errCleanUp; HeapFree(MSACM_hHeap, 0, key); return TRUE; errCleanUp: HeapFree(MSACM_hHeap, 0, key); return FALSE; }
/* * RegisterAllClasses() */ static HRESULT SetupRegisterAllClasses(const CFactoryTemplate * pList, int num, LPCWSTR szFileName, BOOL bRegister) { HRESULT hr = NOERROR; HKEY hkey; OLECHAR szCLSID[CHARS_IN_GUID]; LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey); if (ERROR_SUCCESS != ret) return HRESULT_FROM_WIN32(ret); for (i = 0; i < num; i++, pList++) { /* (un)register CLSID and InprocServer32 */ hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID); if (SUCCEEDED(hr)) { if (bRegister ) hr = SetupRegisterClass(hkey, szCLSID, pList->m_Name, szFileName, ips32_keyname, tmodel_both); else hr = DeleteEntireSubKey(hkey, szCLSID); } } RegCloseKey(hkey); return hr; }
void CWE272_Least_Privilege_Violation__w32_wchar_t_RegCreateKey_15_bad() { switch(6) { case 6: { wchar_t * keyName = L"TEST\\TestKey"; HKEY hKey; /* FLAW: Call RegCreateKeyW() with HKEY_LOCAL_MACHINE violating the least privilege principal */ if (RegCreateKeyW( HKEY_LOCAL_MACHINE, keyName, &hKey) != ERROR_SUCCESS) { printLine("Registry key could not be created"); } else { printLine("Registry key created successfully"); RegCloseKey(hKey); } } break; default: /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); break; } }
UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create) { UINT rc; WCHAR squished_pc[GUID_SIZE]; WCHAR keypath[0x200]; LPWSTR usersid; TRACE("%s\n", debugstr_w(szProduct)); if (!squash_guid(szProduct, squished_pc)) return ERROR_FUNCTION_FAILED; TRACE("squished (%s)\n", debugstr_w(squished_pc)); rc = get_user_sid(&usersid); if (rc != ERROR_SUCCESS || !usersid) { ERR("Failed to retrieve user SID: %d\n", rc); return rc; } sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc); if (create) rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); else rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); LocalFree(usersid); return rc; }
static HRESULT register_clsid(LPCGUID guid) { static const WCHAR clsid[] = {'C','L','S','I','D','\\',0}; static const WCHAR ips[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0}; static const WCHAR hlink[] = {'h','l','i','n','k','.','d','l','l',0}; static const WCHAR threading_model[] = {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0}; static const WCHAR apartment[] = {'A','p','a','r','t','m','e','n','t',0}; WCHAR path[80]; HKEY key = NULL; LONG r; lstrcpyW(path, clsid); StringFromGUID2(guid, &path[6], 80); lstrcatW(path, ips); r = RegCreateKeyW(HKEY_CLASSES_ROOT, path, &key); if (r != ERROR_SUCCESS) return E_FAIL; RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE *)hlink, sizeof hlink); RegSetValueExW(key, threading_model, 0, REG_SZ, (const BYTE *)apartment, sizeof apartment); RegCloseKey(key); return S_OK; }
UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create) { WCHAR squished_pc[GUID_SIZE]; WCHAR keypath[0x200]; LPWSTR usersid; UINT r; TRACE("%s\n", debugstr_w(szProductCode)); if (!squash_guid(szProductCode, squished_pc)) return ERROR_FUNCTION_FAILED; TRACE("squished (%s)\n", debugstr_w(squished_pc)); r = get_user_sid(&usersid); if (r != ERROR_SUCCESS || !usersid) { ERR("Failed to retrieve user SID: %d\n", r); return r; } sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc); LocalFree(usersid); if (create) return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); }
/* good2() reverses the blocks in the switch */ static void good2() { switch(6) { case 6: { wchar_t * keyName = L"TEST\\TestKey"; HKEY hKey; /* FIX: Call RegCreateKeyW() with HKEY_CURRENT_USER */ if (RegCreateKeyW( HKEY_CURRENT_USER, keyName, &hKey) != ERROR_SUCCESS) { printLine("Registry key could not be created"); } else { printLine("Registry key created successfully"); RegCloseKey(hKey); } } break; default: /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); break; } }
/** * set_config_key: convenience wrapper to set a key/value pair * * const char *subKey : the name of the config section * const char *valueName : the name of the config value * const char *value : the value to set the configuration key to * * Returns 0 on success, non-zero otherwise * * If valueName or value is NULL, an empty section will be created */ static int set_config_key(HKEY root, const WCHAR *subkey, const WCHAR *name, const void *value, DWORD type) { DWORD res = 1; HKEY key = NULL; WINE_TRACE("subkey=%s: name=%s, value=%p, type=%d\n", wine_dbgstr_w(subkey), wine_dbgstr_w(name), value, type); assert( subkey != NULL ); if (subkey[0]) { res = RegCreateKeyW(root, subkey, &key); if (res != ERROR_SUCCESS) goto end; } else key = root; if (name == NULL || value == NULL) goto end; switch (type) { case REG_SZ: res = RegSetValueExW(key, name, 0, REG_SZ, value, (lstrlenW(value)+1)*sizeof(WCHAR)); break; case REG_DWORD: res = RegSetValueExW(key, name, 0, REG_DWORD, value, sizeof(DWORD)); break; } if (res != ERROR_SUCCESS) goto end; res = 0; end: if (key && key != root) RegCloseKey(key); if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s, res=%d\n", wine_dbgstr_w(name), wine_dbgstr_w(subkey), res); return res; }
/// <summary> /// Load arbitrary driver /// </summary> /// <param name="svcName">Driver service name</param> /// <param name="path">Driver file path</param> /// <returns>Status</returns> NTSTATUS Utils::LoadDriver( const std::wstring& svcName, const std::wstring& path ) { HKEY key1, key2; BYTE dwType = 1; UNICODE_STRING Ustr; LSTATUS status = 0; WCHAR wszLocalPath[MAX_PATH] = { 0 }; swprintf_s( wszLocalPath, ARRAYSIZE( wszLocalPath ), L"\\??\\%s", path.c_str() ); status = RegOpenKey( HKEY_LOCAL_MACHINE, L"system\\CurrentControlSet\\Services", &key1 ); if (status) return status; status = RegCreateKeyW( key1, svcName.c_str(), &key2 ); if (status) { RegCloseKey( key1 ); return status; } status = RegSetValueEx( key2, L"ImagePath", 0, REG_SZ, reinterpret_cast<const BYTE*>(wszLocalPath), static_cast<DWORD>(sizeof(WCHAR)* (wcslen( wszLocalPath ) + 1)) ); if (status) { RegCloseKey( key2 ); RegCloseKey( key1 ); return status; } status = RegSetValueEx( key2, L"Type", 0, REG_DWORD, &dwType, sizeof(DWORD) ); if (status) { RegCloseKey( key2 ); RegCloseKey( key1 ); return status; } RegCloseKey( key2 ); RegCloseKey( key1 ); std::wstring regPath = L"\\registry\\machine\\SYSTEM\\CurrentControlSet\\Services\\" + svcName; GET_IMPORT( RtlInitUnicodeString )(&Ustr, regPath.c_str()); DynImport::load( "NtUnloadDriver", GetModuleHandleW( L"ntdll.dll" ) ); DynImport::load( "NtLoadDriver", GetModuleHandleW( L"ntdll.dll" ) ); // Remove previously loaded instance GET_IMPORT( NtUnloadDriver )(&Ustr); return GET_IMPORT( NtLoadDriver )(&Ustr); }
/* create the platform-specific environment registry keys */ static void create_environment_registry_keys( void ) { static const WCHAR EnvironW[] = {'S','y','s','t','e','m','\\', 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', 'C','o','n','t','r','o','l','\\', 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\', 'E','n','v','i','r','o','n','m','e','n','t',0}; static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0}; static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0}; static const WCHAR x86W[] = {'x','8','6',0}; static const WCHAR IA64W[] = {'I','A','6','4',0}; static const WCHAR AMD64W[] = {'A','M','D','6','4',0}; static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0}; static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0}; static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0}; static const WCHAR PercentDW[] = {'%','d',0}; static const WCHAR Percent04XW[] = {'%','0','4','x',0}; static const WCHAR IntelCpuDescrW[] = {'%','s',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d', ' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0}; HKEY env_key; SYSTEM_CPU_INFORMATION sci; WCHAR buffer[60]; const WCHAR *arch; NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL ); if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return; sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors ); set_reg_value( env_key, NumProcW, buffer ); switch(sci.Architecture) { case PROCESSOR_ARCHITECTURE_AMD64: arch = AMD64W; break; case PROCESSOR_ARCHITECTURE_IA64: arch = IA64W; break; default: case PROCESSOR_ARCHITECTURE_INTEL: arch = x86W; break; } set_reg_value( env_key, ProcArchW, arch ); /* TODO: currently hardcoded Intel, add different processors */ sprintfW( buffer, IntelCpuDescrW, arch, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) ); set_reg_value( env_key, ProcIdW, buffer ); sprintfW( buffer, PercentDW, sci.Level ); set_reg_value( env_key, ProcLvlW, buffer ); /* Properly report model/stepping */ sprintfW( buffer, Percent04XW, sci.Revision ); set_reg_value( env_key, ProcRevW, buffer ); RegCloseKey( env_key ); }
LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val ) { HKEY hsubkey = 0; LONG r; r = RegCreateKeyW( hkey, path, &hsubkey ); if (r != ERROR_SUCCESS) return r; r = msi_reg_set_val_str( hsubkey, name, val ); RegCloseKey( hsubkey ); return r; }
/*********************************************************************** * UXTHEME_SetActiveTheme * * Change the current active theme */ static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf) { HKEY hKey; WCHAR tmp[2]; HRESULT hr; if(tf && !bThemeActive) UXTHEME_BackupSystemMetrics(); hr = MSSTYLES_SetActiveTheme(tf, TRUE); if(FAILED(hr)) return hr; if(tf) { bThemeActive = TRUE; lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0])); lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0])); lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0])); } else { UXTHEME_RestoreSystemMetrics(); bThemeActive = FALSE; szCurrentTheme[0] = '\0'; szCurrentColor[0] = '\0'; szCurrentSize[0] = '\0'; } TRACE("Writing theme config to registry\n"); if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) { tmp[0] = bThemeActive?'1':'0'; tmp[1] = '\0'; RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2); if(bThemeActive) { RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor, (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize, (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme, (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR)); } else { RegDeleteValueW(hKey, szColorName); RegDeleteValueW(hKey, szSizeName); RegDeleteValueW(hKey, szDllName); } RegCloseKey(hKey); } else TRACE("Failed to open theme registry key\n"); UXTHEME_SaveSystemMetrics (); return hr; }
BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry, LPCWSTR lpszString, LPCWSTR lpszFilename) { LONG ret; HKEY hkey; WCHAR softwareodbc[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0}; clear_errors(); TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry), debugstr_w(lpszString), debugstr_w(lpszFilename)); if(!lpszFilename || !*lpszFilename) { push_error(ODBC_ERROR_INVALID_STR, odbc_error_invalid_param_string); return FALSE; } if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, softwareodbc, &hkey)) == ERROR_SUCCESS) { HKEY hkeyfilename; if ((ret = RegCreateKeyW(hkey, lpszFilename, &hkeyfilename)) == ERROR_SUCCESS) { HKEY hkey_section; if ((ret = RegCreateKeyW(hkeyfilename, lpszSection, &hkey_section)) == ERROR_SUCCESS) { ret = RegSetValueExW(hkey_section, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR)); RegCloseKey(hkey_section); } RegCloseKey(hkeyfilename); } RegCloseKey(hkey); } return ret == ERROR_SUCCESS; }
/* * SetupRegisterClass() */ static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID, LPCWSTR szDescription, LPCWSTR szFileName, LPCWSTR szServerType, LPCWSTR szThreadingModel) { HKEY hkey, hsubkey; LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey); if (ERROR_SUCCESS != ret) return HRESULT_FROM_WIN32(ret); /* set description string */ ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription, sizeof(WCHAR) * (lstrlenW(szDescription) + 1)); if (ERROR_SUCCESS != ret) goto err_out; /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"} passed back by last call to RegCreateKeyW(). */ ret = RegCreateKeyW(hkey, szServerType, &hsubkey); if (ERROR_SUCCESS != ret) goto err_out; /* set server path */ ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName, sizeof(WCHAR) * (lstrlenW(szFileName) + 1)); if (ERROR_SUCCESS != ret) goto err_out; /* set threading model */ ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ, (const BYTE*)szThreadingModel, sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1)); err_out: if (hsubkey) RegCloseKey(hsubkey); RegCloseKey(hkey); return HRESULT_FROM_WIN32(ret); }
PluginSettings( #ifdef FAR3 FARAPISETTINGSCONTROL settingsControl, const GUID &guid) { SettingsControl = settingsControl; handle = INVALID_HANDLE_VALUE; FarSettingsCreate settings = {sizeof settings,guid,handle}; if(SettingsControl(INVALID_HANDLE_VALUE,SCTL_CREATE,PSL_ROAMING,&settings)) handle = settings.Handle; #else bool bWrite) { extern TCHAR PluginRootKey[]; DWORD disp; if((bWrite ? RegCreateKeyEx(HKEY_CURRENT_USER, PluginRootKey, 0, 0, 0, KEY_WRITE|KEY_READ, 0, &hKey, &disp) : RegOpenKeyEx(HKEY_CURRENT_USER, PluginRootKey, 0, KEY_READ, &hKey)) !=ERROR_SUCCESS) hKey = 0; #endif } ~PluginSettings() { #ifdef FAR3 SettingsControl(handle,SCTL_FREE,0,0); #else for each(HKEY hk in subKeys) //for(HKEY hk : subKeys) after moving to a newer VC RegCloseKey(hk); subKeys.clear(); if(hKey) RegCloseKey(hKey); hKey = 0; #endif } KEY_TYPE CreateSubKey(PCWSTR Name, KEY_TYPE root = 0) { #ifdef FAR3 FarSettingsValue value = {sizeof value, root, Name}; return (KEY_TYPE)SettingsControl(handle,SCTL_CREATESUBKEY,0,&value); #else if(root == 0) root = hKey; HKEY hk; if(RegCreateKeyW(root, Name, &hk) != ERROR_SUCCESS) return 0; subKeys.push_back(hk); return hk; #endif }
/*********************************************************************** * UXTHEME_ApplyTheme * * Change the current active theme */ static HRESULT UXTHEME_ApplyTheme(PTHEME_FILE tf) { HKEY hKey; WCHAR tmp[2]; HRESULT hr; TRACE("UXTHEME_ApplyTheme\n"); if (tf && !ActiveThemeFile) { UXTHEME_BackupSystemMetrics(); } hr = UXTHEME_SetActiveTheme(tf); if (FAILED(hr)) return hr; if (!tf) { UXTHEME_RestoreSystemMetrics(); } TRACE("Writing theme config to registry\n"); if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) { tmp[0] = ActiveThemeFile?'1':'0'; tmp[1] = '\0'; RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2); if (ActiveThemeFile) { RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)tf->pszSelectedColor, (lstrlenW(tf->pszSelectedColor)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)tf->pszSelectedSize, (lstrlenW(tf->pszSelectedSize)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)tf->szThemeFile, (lstrlenW(tf->szThemeFile)+1)*sizeof(WCHAR)); } else { RegDeleteValueW(hKey, szColorName); RegDeleteValueW(hKey, szSizeName); RegDeleteValueW(hKey, szDllName); } RegCloseKey(hKey); } else TRACE("Failed to open theme registry key\n"); UXTHEME_SaveSystemMetrics (); return hr; }
static HKEY GetKeyW(LPCWSTR appname, BOOL * closekey, BOOL fCreate) { HKEY key = 0; WCHAR achName[MAX_PATH]; #if !MMPROFILECACHE *closekey = TRUE; #else UINT n; ATOM atm; *closekey = FALSE; // // See if we have already used this key // atm = FindAtomW(appname); if (atm != 0) { // Atom exists... search the table for it. for (n=0; n<keyscached; ++n) { if (akeyatoms[n] == atm) { DPF2(("(W)Found existing key for %ls\n", appname)); return ahkey[n]; } } } DPF2(("(W)No key found for %ls\n", appname)); #endif StringCchCopyW(achName, MAX_PATH, KEYNAME ); StrCchCatW(achName, MAX_PATH, appname); if ((!fCreate && RegOpenKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS) || (fCreate && RegCreateKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS)) { #if MMPROFILECACHE if (keyscached < KEYSCACHED && (atm = AddAtomW(appname))) { // Add this key to the cache array akeyatoms[keyscached] = atm; ahkey[keyscached] = key; DPF1(("Adding key %ls to cache array in position %d\n", appname, keyscached)); ++keyscached; } else { DPF2(("Not adding key to cache array\n")); *closekey = TRUE; } #endif } return(key); }
UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create) { UINT rc; WCHAR keypath[0x200]; TRACE("%s\n",debugstr_w(szProduct)); sprintfW(keypath,szUninstall_fmt,szProduct); if (create) rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); else rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); return rc; }
LONG WINAPI RegCreateKeyA( IN HKEY hKey, IN LPCSTR lpSubKey, OUT PHKEY phkResult) { PWSTR lpSubKeyW; LONG rc; lpSubKeyW = MultiByteToWideChar(lpSubKey); if (!lpSubKeyW) return ERROR_OUTOFMEMORY; rc = RegCreateKeyW(hKey, lpSubKeyW, phkResult); free(lpSubKeyW); return rc; }
/// <summary> /// Fill minimal required driver registry entry /// </summary> /// <param name="svcName">Driver service name</param> /// <param name="path">Driver path</param> /// <returns>Status code</returns> LSTATUS DriverControl::PrepareDriverRegEntry( const std::wstring& svcName, const std::wstring& path ) { HKEY key1, key2; DWORD dwType = 1; LSTATUS status = 0; WCHAR wszLocalPath[MAX_PATH] = { 0 }; swprintf_s( wszLocalPath, ARRAYSIZE( wszLocalPath ), L"\\??\\%s", path.c_str() ); status = RegOpenKeyW( HKEY_LOCAL_MACHINE, L"system\\CurrentControlSet\\Services", &key1 ); if (status) return status; status = RegCreateKeyW( key1, svcName.c_str(), &key2 ); if (status) { RegCloseKey( key1 ); return status; } status = RegSetValueExW( key2, L"ImagePath", 0, REG_SZ, reinterpret_cast<const BYTE*>(wszLocalPath), static_cast<DWORD>(sizeof( WCHAR )* (wcslen( wszLocalPath ) + 1)) ); if (status) { RegCloseKey( key2 ); RegCloseKey( key1 ); return status; } status = RegSetValueExW( key2, L"Type", 0, REG_DWORD, reinterpret_cast<const BYTE*>(&dwType), sizeof( dwType ) ); if (status) { RegCloseKey( key2 ); RegCloseKey( key1 ); return status; } RegCloseKey( key2 ); RegCloseKey( key1 ); return status; }
DWORD save_service_config(struct service_entry *entry) { DWORD err; HKEY hKey = NULL; err = RegCreateKeyW(entry->db->root_key, entry->name, &hKey); if (err != ERROR_SUCCESS) goto cleanup; if ((err = reg_set_string_value(hKey, SZ_DISPLAY_NAME, entry->config.lpDisplayName)) != 0) goto cleanup; if ((err = reg_set_string_value(hKey, SZ_IMAGE_PATH, entry->config.lpBinaryPathName)) != 0) goto cleanup; if ((err = reg_set_string_value(hKey, SZ_GROUP, entry->config.lpLoadOrderGroup)) != 0) goto cleanup; if ((err = reg_set_string_value(hKey, SZ_OBJECT_NAME, entry->config.lpServiceStartName)) != 0) goto cleanup; if ((err = reg_set_string_value(hKey, SZ_DESCRIPTION, entry->description)) != 0) goto cleanup; if ((err = reg_set_multisz_value(hKey, SZ_DEPEND_ON_SERVICE, entry->dependOnServices)) != 0) goto cleanup; if ((err = reg_set_multisz_value(hKey, SZ_DEPEND_ON_GROUP, entry->dependOnGroups)) != 0) goto cleanup; if ((err = RegSetValueExW(hKey, SZ_START, 0, REG_DWORD, (LPBYTE)&entry->config.dwStartType, sizeof(DWORD))) != 0) goto cleanup; if ((err = RegSetValueExW(hKey, SZ_ERROR, 0, REG_DWORD, (LPBYTE)&entry->config.dwErrorControl, sizeof(DWORD))) != 0) goto cleanup; if ((err = RegSetValueExW(hKey, SZ_TYPE, 0, REG_DWORD, (LPBYTE)&entry->config.dwServiceType, sizeof(DWORD))) != 0) goto cleanup; if ((err = RegSetValueExW(hKey, SZ_PRESHUTDOWN, 0, REG_DWORD, (LPBYTE)&entry->preshutdown_timeout, sizeof(DWORD))) != 0) goto cleanup; if (entry->config.dwTagId) err = RegSetValueExW(hKey, SZ_TAG, 0, REG_DWORD, (LPBYTE)&entry->config.dwTagId, sizeof(DWORD)); else err = RegDeleteValueW(hKey, SZ_TAG); if (err != 0 && err != ERROR_FILE_NOT_FOUND) goto cleanup; err = ERROR_SUCCESS; cleanup: RegCloseKey(hKey); return err; }
/* * Helper for CryptSIPAddProvider * * Add a registry key containing a dll name and function under * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>" */ static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey, LPCWSTR szDll, LPCWSTR szFunction ) { static const WCHAR szOID[] = { 'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'C','r','y','p','t','o','g','r','a','p','h','y','\\', 'O','I','D','\\', 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\', 'C','r','y','p','t','S','I','P','D','l','l', 0 }; static const WCHAR szBackSlash[] = { '\\', 0 }; static const WCHAR szDllName[] = { 'D','l','l',0 }; static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 }; WCHAR szFullKey[ 0x100 ]; LONG r; HKEY hKey; if( !szFunction ) return ERROR_SUCCESS; /* max length of szFullKey depends on our code only, so we won't overrun */ lstrcpyW( szFullKey, szOID ); lstrcatW( szFullKey, szKey ); lstrcatW( szFullKey, szBackSlash ); CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] ); lstrcatW( szFullKey, szBackSlash ); TRACE("key is %s\n", debugstr_w( szFullKey ) ); r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey ); if( r != ERROR_SUCCESS ) return r; /* write the values */ RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction, ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) ); RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll, ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) ); RegCloseKey( hKey ); return ERROR_SUCCESS; }
UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create) { WCHAR squished_pc[GUID_SIZE]; WCHAR keypath[0x200]; TRACE("%s\n", debugstr_w(szProductCode)); if (!squash_guid(szProductCode, squished_pc)) return ERROR_FUNCTION_FAILED; TRACE("squished (%s)\n", debugstr_w(squished_pc)); sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc); if (create) return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); }