本文整理汇总了C++中RegCreateKeyExA函数的典型用法代码示例。如果您正苦于以下问题:C++ RegCreateKeyExA函数的具体用法?C++ RegCreateKeyExA怎么用?C++ RegCreateKeyExA使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegCreateKeyExA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteWindowsRegistryInt
//----- (00464D32) --------------------------------------------------------
void __fastcall WriteWindowsRegistryInt(const char *pKey, int val)
{
const char *lpValueName; // [sp+4h] [bp-1Ch]@1
BYTE Data[4]; // [sp+8h] [bp-18h]@1
DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
HKEY hKey; // [sp+10h] [bp-10h]@1
HKEY phkResult; // [sp+14h] [bp-Ch]@1
HKEY v7; // [sp+18h] [bp-8h]@1
HKEY v8; // [sp+1Ch] [bp-4h]@1
*(int *)Data = val;
lpValueName = pKey;
v8 = 0;
v7 = 0;
hKey = 0;
phkResult = 0;
if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
{
if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
{
if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v7, &dwDisposition) )
{
if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
{
RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
RegCloseKey(v8);
}
RegCloseKey(v7);
}
RegCloseKey(phkResult);
}
RegCloseKey(hKey);
}
}
示例2: My_RegCreateKeyExA
BOOL My_RegCreateKeyExA()
{
HKEY hKey=NULL;
LPCSTR lpSubKey=NULL;
DWORD Reserved=NULL;
LPSTR lpClass=NULL;
DWORD dwOptions=NULL;
REGSAM samDesired=NULL;
LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL;
PHKEY phkResult=NULL;
LPDWORD lpdwDisposition=NULL;
LONG returnVal_Real = NULL;
LONG returnVal_Intercepted = NULL;
DWORD error_Real = 0;
DWORD error_Intercepted = 0;
__try{
disableInterception();
returnVal_Real = RegCreateKeyExA (hKey,lpSubKey,Reserved,lpClass,dwOptions,samDesired,lpSecurityAttributes,phkResult,lpdwDisposition);
error_Real = GetLastError();
enableInterception();
returnVal_Intercepted = RegCreateKeyExA (hKey,lpSubKey,Reserved,lpClass,dwOptions,samDesired,lpSecurityAttributes,phkResult,lpdwDisposition);
error_Intercepted = GetLastError();
}__except(puts("in filter"), 1){puts("exception caught");}
return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
示例3: RegisterServer
BOOL RegisterServer()
{
DWORD dw;
HKEY hKey;
HKEY hSubKey;
BOOL fRet;
char achIMEKey[ARRAYSIZE(c_szInfoKeyPrefix) + CLSID_STRLEN];
TCHAR achFileName[MAX_PATH];
if (!CLSIDToStringA(c_clsidTextService, achIMEKey + ARRAYSIZE(c_szInfoKeyPrefix) - 1))
return FALSE;
memcpy(achIMEKey, c_szInfoKeyPrefix, sizeof(c_szInfoKeyPrefix) - 1);
if (fRet = RegCreateKeyExA(HKEY_CLASSES_ROOT, achIMEKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dw) == ERROR_SUCCESS)
{
fRet &= RegSetValueExA(hKey, NULL, 0, REG_SZ, (BYTE *) TEXTSERVICE_DESC_A, (strlen(TEXTSERVICE_DESC_A) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS;
if (fRet &= RegCreateKeyExA(hKey, c_szInProcSvr32, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dw) == ERROR_SUCCESS)
{
dw = GetModuleFileName(g_hInst, achFileName, ARRAYSIZE(achFileName));
fRet &= RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (BYTE *) achFileName, (lstrlen(achFileName) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS;
fRet &= RegSetValueExA(hSubKey, c_szModelName, 0, REG_SZ, (BYTE *) TEXTSERVICE_MODEL, (strlen(TEXTSERVICE_MODEL) + 1)) == ERROR_SUCCESS;
RegCloseKey(hSubKey);
}
RegCloseKey(hKey);
}
return fRet;
}
示例4: GetAppProfileKey
static HKEY GetAppProfileKey()
{
if (!regapp || !regcomp) return NULL;
HKEY hsoft = NULL;
HKEY hcomp = NULL;
HKEY happ = NULL;
if (RegOpenKeyExA(HKEY_CURRENT_USER, "software", 0, KEY_WRITE|KEY_READ,
&hsoft) == ERROR_SUCCESS) {
DWORD dw;
if (RegCreateKeyExA(hsoft, COMPANY, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hcomp, &dw) == ERROR_SUCCESS)
{
RegCreateKeyExA(hcomp, APPNAME, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&happ, &dw);
}
}
if (hsoft != NULL) RegCloseKey(hsoft);
if (hcomp != NULL) RegCloseKey(hcomp);
return happ;
}
示例5: test_delete
static void test_delete(void)
{
HKEY hkey, hsubkey;
LONG err;
DWORD r;
const DWORD deadbeef = 0xdeadbeef;
run_reg_exe("reg delete", &r);
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
run_reg_exe("reg delete /?", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegCreateKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
ok(err == ERROR_SUCCESS, "got %d\n", err);
err = RegSetValueExA(hkey, "foo", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
ok(err == ERROR_SUCCESS, "got %d\n" ,err);
err = RegSetValueExA(hkey, "bar", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
ok(err == ERROR_SUCCESS, "got %d\n" ,err);
err = RegSetValueExA(hkey, "", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
ok(err == ERROR_SUCCESS, "got %d\n" ,err);
err = RegCreateKeyExA(hkey, "subkey", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hsubkey, NULL);
ok(err == ERROR_SUCCESS, "got %d\n" ,err);
RegCloseKey(hsubkey);
run_reg_exe("reg delete HKCU\\" KEY_BASE " /v bar /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegQueryValueExA(hkey, "bar", NULL, NULL, NULL, NULL);
ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegQueryValueExA(hkey, "", NULL, NULL, NULL, NULL);
ok(err == ERROR_FILE_NOT_FOUND, "got %d, expected 2\n", err);
run_reg_exe("reg delete HKCU\\" KEY_BASE " /va /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegQueryValueExA(hkey, "foo", NULL, NULL, NULL, NULL);
ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
err = RegOpenKeyExA(hkey, "subkey", 0, KEY_READ, &hsubkey);
ok(err == ERROR_SUCCESS, "got %d\n", err);
RegCloseKey(hsubkey);
RegCloseKey(hkey);
run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
}
示例6: ReadWindowsRegistryString
//----- (00464BEF) --------------------------------------------------------
void __fastcall ReadWindowsRegistryString(const char *pKeyName, char *pOutString, int uBufLen, const char *pDefaultValue)
{
LSTATUS (__stdcall *v4)(HKEY); // [email protected]
LSTATUS result; // [email protected]
DWORD Type; // [sp+Ch] [bp-24h]@5
LPCSTR lpValueName; // [sp+10h] [bp-20h]@1
DWORD cbData; // [sp+14h] [bp-1Ch]@1
LPBYTE Dest; // [sp+18h] [bp-18h]@1
DWORD dwDisposition; // [sp+1Ch] [bp-14h]@2
HKEY phkResult; // [sp+20h] [bp-10h]@1
HKEY hKey; // [sp+24h] [bp-Ch]@1
HKEY v13; // [sp+28h] [bp-8h]@1
HKEY v14; // [sp+2Ch] [bp-4h]@1
cbData = uBufLen;
Dest = (LPBYTE)pOutString;
lpValueName = pKeyName;
v14 = 0;
v13 = 0;
hKey = 0;
phkResult = 0;
v4 = RegCloseKey;
if ( RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey)
|| RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition)
|| RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v13, &dwDisposition)
|| RegCreateKeyExA(v13, "1.0", 0, "", 0, 0xF003Fu, 0, &v14, &dwDisposition) )
{
result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
}
else if ( RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData) )
{
RegCloseKey(v14);
v14 = 0;
result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
}
else
{
v4 = RegCloseKey;
RegCloseKey(v14);
v14 = 0;
RegCloseKey(v13);
v13 = 0;
RegCloseKey(phkResult);
phkResult = 0;
result = RegCloseKey(hKey);
hKey = 0;
}
if ( v14 )
result = v4(v14);
if ( v13 )
result = v4(v13);
if ( hKey )
result = v4(hKey);
if ( phkResult )
result = v4(phkResult);
}
示例7: good1
/* good1() uses the GoodSink on both sides of the "if" statement */
static void good1()
{
if(globalReturnsTrueOrFalse())
{
{
char * keyName = "TEST\\TestKey";
HKEY hKey;
/* FIX: Call RegCreateKeyExA() without KEY_ALL_ACCESS as the 6th parameter to limit access */
if (RegCreateKeyExA(
HKEY_CURRENT_USER,
keyName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey,
NULL) != ERROR_SUCCESS)
{
printLine("Registry key could not be created");
}
else
{
printLine("Registry key created successfully");
RegCloseKey(hKey);
}
}
}
else
{
{
char * keyName = "TEST\\TestKey";
HKEY hKey;
/* FIX: Call RegCreateKeyExA() without KEY_ALL_ACCESS as the 6th parameter to limit access */
if (RegCreateKeyExA(
HKEY_CURRENT_USER,
keyName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey,
NULL) != ERROR_SUCCESS)
{
printLine("Registry key could not be created");
}
else
{
printLine("Registry key created successfully");
RegCloseKey(hKey);
}
}
}
}
开发者ID:gpwi970725,项目名称:testJuliet2,代码行数:56,代码来源:CWE284_Improper_Access_Control__w32_char_RegCreateKeyEx_12.c
示例8: SaveSetting
VOID SaveSetting(VOID)
{
HKEY hCompanyKey, hSoftwareKey;
LONG result;
INT i, n;
DWORD dwDisp, dwSize;
float e;
CHAR szValue[256];
result = RegCreateKeyExA(HKEY_CURRENT_USER, pszCompany, 0,
NULL, 0, KEY_ALL_ACCESS, NULL, &hCompanyKey, &dwDisp);
if (result != ERROR_SUCCESS)
return;
result = RegCreateKeyExA(hCompanyKey, progname, 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hSoftwareKey, &dwDisp);
if (result == ERROR_SUCCESS)
{
for (i = 0; i < hack_argcount; i++)
{
switch (hack_arginfo[i].type)
{
case t_Bool:
if (*(Bool *)hack_arginfo[i].data)
strcpy(szValue, "True");
else
strcpy(szValue, "False");
break;
case t_Int:
n = *(INT *)hack_arginfo[i].data;
sprintf(szValue, "%d", n);
break;
case t_Float:
e = *(float *)hack_arginfo[i].data;
sprintf(szValue, "%g", e);
break;
case t_String:
strcpy(szValue, *(char **)hack_arginfo[i].data);
break;
}
dwSize = (strlen(szValue) + 1) * sizeof(CHAR);
RegSetValueExA(hSoftwareKey, hack_arginfo[i].name,
0, REG_SZ, (LPBYTE)szValue, dwSize);
}
RegCloseKey(hSoftwareKey);
}
RegCloseKey(hCompanyKey);
}
示例9: init_original_display_mode
static void init_original_display_mode(void)
{
BOOL success = FALSE;
HKEY mac_driver_hkey, parent_hkey;
DWORD disposition;
struct macdrv_display *displays = NULL;
int num_displays, i;
if (inited_original_display_mode)
return;
/* @@ Wine registry key: HKLM\Software\Wine\Mac Driver */
if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Mac Driver", 0, NULL,
0, KEY_ALL_ACCESS, NULL, &mac_driver_hkey, NULL))
return;
/* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode */
if (RegCreateKeyExA(mac_driver_hkey, initial_mode_key, 0, NULL,
REG_OPTION_VOLATILE, KEY_WRITE, NULL, &parent_hkey, &disposition))
{
parent_hkey = NULL;
goto fail;
}
/* If we didn't create a new key, then it already existed. Something already stored
the initial display mode since Wine was started. We don't want to overwrite it. */
if (disposition != REG_CREATED_NEW_KEY)
goto done;
if (macdrv_get_displays(&displays, &num_displays))
goto fail;
for (i = 0; i < num_displays; i++)
{
if (!write_display_settings(parent_hkey, displays[i].displayID))
goto fail;
}
done:
success = TRUE;
fail:
macdrv_free_displays(displays);
RegCloseKey(parent_hkey);
if (!success && parent_hkey)
RegDeleteTreeA(mac_driver_hkey, initial_mode_key);
RegCloseKey(mac_driver_hkey);
if (success)
inited_original_display_mode = TRUE;
}
示例10: RegCreateKeyExA
int CGlobalSettings::SetGlobalValue(const char *product, const char *key, const char *value, const char *buffer)
{
HKEY hKey,hSubKey;
DWORD dwLen;
cvs::string regkey;
if(!isAdmin())
return -1;
if(!product || !strcmp(product,"cvsnt"))
regkey="Software\\CVS";
else
cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product);
if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) &&
RegCreateKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL))
{
return -1; // Couldn't open or create key
}
if(key)
{
if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) &&
RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL))
{
RegCloseKey(hKey);
return -1; // Couldn't open or create key
}
RegCloseKey(hKey);
hKey=hSubKey;
}
if(!buffer)
{
RegDeleteValueA(hKey,value);
}
else
{
dwLen=(DWORD)strlen(buffer);
if(RegSetValueExA(hKey,value,0,REG_SZ,(LPBYTE)buffer,dwLen+1))
{
RegCloseKey(hKey);
return -1;
}
}
RegCloseKey(hKey);
return 0;
}
示例11: setVolumeIcon
static void setVolumeIcon(char letter, bool create)
{
HRESULT hr;
WCHAR data[MAX_PATH];
DWORD cbDataSize = sizeof(data);
HKEY hKey;
char path[] = "Software\\Classes\\Applications\\explorer.exe\\Drives\\a\\DefaultIcon";
path[sizeof(path)-sizeof("DefaultIcon")-2] = letter;
if (create)
{
hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\PCloud\\pCloud", 0, KEY_READ, &hKey);
if (!hr)
{
hr = RegQueryValueEx(hKey, L"Install_Dir", NULL, NULL, (LPBYTE)data, &cbDataSize);
wcscat(data, L"\\pCloud.exe,0");
RegCloseKey(hKey);
if (!hr)
{
hr = RegCreateKeyExA(HKEY_LOCAL_MACHINE, path, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
if(!hr)
{
hr = RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)data, 2*(wcslen(data)+1));
RegCloseKey(hKey);
}
}
}
}
else
{
hr = RegDeleteKeyA(HKEY_LOCAL_MACHINE, path);
}
}
示例12: CheckTokenMembership
/******************************************************************************
* CheckTokenMembership [[email protected]]
*
* PARAMS
* TokenHandle []
* SidToCheck []
* IsMember []
*/
BOOL WINAPI
CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
PBOOL IsMember )
{
FIXME("(0x%08x %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
if (RunAsAdmin == -1)
{
HKEY hKey = 0;
char buf[16];
DWORD size = sizeof (buf);
RunAsAdmin = 1;
if (!RegCreateKeyExA (HKEY_LOCAL_MACHINE,
"Software\\Wine\\Wine\\Config\\wine", 0, NULL,
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey, NULL) &&
!RegQueryValueExA (hKey, "NotAdministrator", 0, NULL, (LPBYTE)buf,
&size) && size)
{
if ((buf[0] == 'y') || (buf[0] == 'Y') || (buf[0] == 't') ||
(buf[0] == 'T') || (buf[0] == '1'))
RunAsAdmin = 0;
}
if (hKey)
RegCloseKey (hKey);
}
*IsMember = RunAsAdmin;
return TRUE;
}
示例13: register_progids
/***********************************************************************
* register_progids
*/
static HRESULT register_progids(struct progid const *list)
{
LONG res = ERROR_SUCCESS;
for (; res == ERROR_SUCCESS && list->name; ++list) {
WCHAR buf[39];
HKEY progid_key;
res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->name, 0,
NULL, 0, KEY_READ | KEY_WRITE, NULL,
&progid_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
(CONST BYTE*)list->description,
strlen(list->description) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
StringFromGUID2(list->clsid, buf, 39);
res = register_key_defvalueW(progid_key, clsid_keyname, buf);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
if (list->curver) {
res = register_key_defvalueA(progid_key, curver_keyname, list->curver);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
error_close_clsid_key:
RegCloseKey(progid_key);
}
return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
}
示例14: check
Registry::Registry(std::string const & subKey, OpenMode openMode, HKEY root)
{
if (openMode == OpenMode::Create)
{
check(
RegCreateKeyExA(
root, subKey.size() ? subKey.c_str() : nullptr, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE | DELETE,
nullptr, &hKey_, nullptr),
"Error creating key: " + subKey);
}
else
{
REGSAM mode;
switch (openMode)
{
case OpenMode::Read: mode = KEY_READ; break;
case OpenMode::ReadWrite: mode = KEY_READ | KEY_WRITE | DELETE; break;
default: throw std::runtime_error("Unknown OpenMode.");
}
check(
RegOpenKeyExA(root, subKey.size() ? subKey.c_str() : nullptr, 0, mode, &hKey_),
"Error opening key: " + subKey);
}
}
示例15: heapTraceEXE
bool heapTraceEXE(const char* name)
{
std::string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\";
key += name;
HKEY hKey = NULL;
LONG lRet = RegCreateKeyExA(
HKEY_LOCAL_MACHINE,
key.c_str(),
0,
NULL,
0,
KEY_ALL_ACCESS,
NULL,
&hKey,
NULL
);
if (lRet != ERROR_SUCCESS)
return false;
DWORD dw = 1;
RegSetValueExA(
hKey,
"TracingFlags",
0,
REG_DWORD,
(const BYTE*)&dw,
sizeof(dw)
);
RegCloseKey(hKey);
return true;
}