本文整理汇总了C++中RegCreateKeyW函数的典型用法代码示例。如果您正苦于以下问题:C++ RegCreateKeyW函数的具体用法?C++ RegCreateKeyW怎么用?C++ RegCreateKeyW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegCreateKeyW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InputList_PrepareUserRegistry
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;
}
示例2: drvSetDefaultCommConfigW
/***********************************************************************
* drvSetDefaultCommConfigW ([email protected])
*
* 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);
}
示例3: good1
/* 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);
}
}
}
}
开发者ID:gpwi970725,项目名称:testJuliet2,代码行数:29,代码来源:CWE272_Least_Privilege_Violation__w32_wchar_t_RegCreateKey_11.c
示例4: ConnectRegistry
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;
}
示例5: I_CryptReadTrustedPublisherDWORDValueFromRegistry
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;
}
示例6: DEVENUM_CreateAMCategoryKey
/**********************************************************************
* 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;
}
示例7: AddERExcludedApplicationW
/*************************************************************************
* AddERExcludedApplicationW [[email protected]]
*
* 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;
}
示例8: SetupRegisterAllClasses
/*
* 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;
}
示例9: CWE272_Least_Privilege_Violation__w32_wchar_t_RegCreateKey_15_bad
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;
}
}
开发者ID:gpwi970725,项目名称:testJuliet2,代码行数:29,代码来源:CWE272_Least_Privilege_Violation__w32_wchar_t_RegCreateKey_15.c
示例10: MSIREG_OpenUserDataProductKey
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;
}
示例11: register_clsid
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;
}
示例12: MSIREG_OpenLocalManagedProductKey
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);
}
示例13: good2
/* 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;
}
}
开发者ID:gpwi970725,项目名称:testJuliet2,代码行数:30,代码来源:CWE272_Least_Privilege_Violation__w32_wchar_t_RegCreateKey_15.c
示例14: swprintf_s
/// <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);
}
示例15: create_environment_registry_keys
/* 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 );
}