本文整理汇总了C++中RegOpenKey函数的典型用法代码示例。如果您正苦于以下问题:C++ RegOpenKey函数的具体用法?C++ RegOpenKey怎么用?C++ RegOpenKey使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegOpenKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unloadPasswordDLL
void SSPassword::loadPasswordDLL(void)
{
HKEY hKey;
if (runningOnNT)
{
return;
}
if (hInstPwdDLL)
{
unloadPasswordDLL();
}
// look in registry to see if password turned on, otherwise don't
// bother to load password handler DLL
if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE, &hKey) ==
ERROR_SUCCESS)
{
DWORD dwVal,dwSize=sizeof(dwVal);
if ((RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD,
NULL,NULL,(BYTE *) &dwVal,&dwSize) == ERROR_SUCCESS)
&& dwVal)
{
// try to load the DLL that contains password proc.
hInstPwdDLL = LoadLibrary(_UC("PASSWORD.CPL"));
if (hInstPwdDLL)
{
verifyPasswordProc = (VERIFYPWDPROC) GetProcAddress(hInstPwdDLL,
"VerifyScreenSavePwd");
if (verifyPasswordProc)
{
hogMachine(TRUE);
}
else
{
unloadPasswordDLL();
}
}
}
RegCloseKey(hKey);
}
}
示例2: DllRegisterServer
STDAPI DllRegisterServer(){
HRESULT hr = S_OK;
HKEY key;
wchar_t module[MAX_PATH];
GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), module, sizeof(module)/sizeof(*module));
#ifndef X64
if(ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, L"*\\ShellEx\\ContextMenuHandlers\\KGBShellEx", &key))
hr = E_UNEXPECTED;
#else
if(ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, L"*\\ShellEx\\ContextMenuHandlers\\KGBShellEx64", &key))
hr = E_UNEXPECTED;
#endif
if(ERROR_SUCCESS != RegSetValue(key, L"", REG_SZ, GUIDName, sizeof(wchar_t)*wcslen(GUIDName)))
hr = E_UNEXPECTED;
RegCloseKey(key);
#ifndef X64
if(ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, L"Directory\\ShellEx\\ContextMenuHandlers\\KGBShellEx", &key))
hr = E_UNEXPECTED;
#else
if(ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, L"Directory\\ShellEx\\ContextMenuHandlers\\KGBShellEx64", &key))
hr = E_UNEXPECTED;
#endif
if(ERROR_SUCCESS != RegSetValue(key, L"", REG_SZ, GUIDName, sizeof(wchar_t)*wcslen(GUIDName)))
hr = E_UNEXPECTED;
RegCloseKey(key);
if(ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, L"CLSID\\" GUIDName L"\\InProcServer32", &key))
hr = E_UNEXPECTED;
if(ERROR_SUCCESS != RegSetValue(key, L"", REG_SZ, module, sizeof(wchar_t)*wcslen(module)))
hr = E_UNEXPECTED;
if(ERROR_SUCCESS != RegSetValue(key, L"ThreadingModel", REG_SZ, L"Apartment", sizeof(wchar_t)*wcslen(L"Apartment")))
hr = E_UNEXPECTED;
RegCloseKey(key);
if(ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", &key))
hr = E_UNEXPECTED;
if(ERROR_SUCCESS != RegSetValue(key, GUIDName, REG_SZ, L"KGB Archiver shell extension", sizeof(wchar_t)*wcslen(L"KGB Archiver shell extension")))
hr = E_UNEXPECTED;
RegCloseKey(key);
return hr;
}
示例3: strlen
PCHAR *GetSubkeyNames( PCHAR MainKeyName, PCHAR Append ) {
int i = 0;
DWORD Error;
HKEY MainKey;
PCHAR *Out, OutKeyName;
DWORD CharTotal = 0, AppendLen = 1 + strlen(Append);
DWORD MaxSubKeyLen = 0, MaxSubKeys = 0;
Error = RegOpenKey( HKEY_LOCAL_MACHINE, MainKeyName, &MainKey );
if( Error ) return NULL;
Error = RegQueryInfoKey
( MainKey,
NULL, NULL, NULL,
&MaxSubKeys, &MaxSubKeyLen,
NULL, NULL, NULL, NULL, NULL, NULL );
DH_DbgPrint(MID_TRACE,("MaxSubKeys: %d, MaxSubKeyLen %d\n",
MaxSubKeys, MaxSubKeyLen));
CharTotal = (sizeof(PCHAR) + MaxSubKeyLen + AppendLen) * (MaxSubKeys + 1);
DH_DbgPrint(MID_TRACE,("AppendLen: %d, CharTotal: %d\n",
AppendLen, CharTotal));
Out = (CHAR**) malloc( CharTotal );
OutKeyName = ((PCHAR)&Out[MaxSubKeys+1]);
if( !Out ) { RegCloseKey( MainKey ); return NULL; }
i = 0;
do {
Out[i] = OutKeyName;
Error = RegEnumKey( MainKey, i, OutKeyName, MaxSubKeyLen );
if( !Error ) {
strcat( OutKeyName, Append );
DH_DbgPrint(MID_TRACE,("[%d]: %s\n", i, OutKeyName));
OutKeyName += strlen(OutKeyName) + 1;
i++;
} else Out[i] = 0;
} while( Error == ERROR_SUCCESS );
RegCloseKey( MainKey );
return Out;
}
示例4: FindAdapterKey
HKEY FindAdapterKey( PDHCP_ADAPTER Adapter ) {
int i = 0;
PCHAR EnumKeyName =
"SYSTEM\\CurrentControlSet\\Control\\Class\\"
"{4D36E972-E325-11CE-BFC1-08002BE10318}";
PCHAR TargetKeyNameStart =
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
PCHAR TargetKeyName = NULL;
PCHAR *EnumKeysLinkage = GetSubkeyNames( EnumKeyName, "\\Linkage" );
PCHAR *EnumKeysTop = GetSubkeyNames( EnumKeyName, "" );
PCHAR RootDevice = NULL;
HKEY EnumKey, OutKey = NULL;
DWORD Error = ERROR_SUCCESS;
if( !EnumKeysLinkage || !EnumKeysTop ) goto cleanup;
Error = RegOpenKey( HKEY_LOCAL_MACHINE, EnumKeyName, &EnumKey );
if( Error ) goto cleanup;
for( i = 0; EnumKeysLinkage[i]; i++ ) {
RootDevice = RegReadString
( EnumKey, EnumKeysLinkage[i], "RootDevice" );
if( RootDevice &&
!strcmp( RootDevice, Adapter->DhclientInfo.name ) ) {
TargetKeyName =
(CHAR*) malloc( strlen( TargetKeyNameStart ) +
strlen( RootDevice ) + 1);
if( !TargetKeyName ) goto cleanup;
sprintf( TargetKeyName, "%s%s",
TargetKeyNameStart, RootDevice );
Error = RegCreateKeyExA( HKEY_LOCAL_MACHINE, TargetKeyName, 0, NULL, 0, KEY_READ, NULL, &OutKey, NULL );
break;
} else {
free( RootDevice ); RootDevice = 0;
}
}
cleanup:
if( RootDevice ) free( RootDevice );
if( EnumKeysLinkage ) free( EnumKeysLinkage );
if( EnumKeysTop ) free( EnumKeysTop );
if( TargetKeyName ) free( TargetKeyName );
return OutKey;
}
示例5: dc_load_conf
int dc_load_conf(dc_conf_data *conf)
{
dc_conf d_conf;
HKEY h_key = NULL;
int resl;
u32 cb;
do
{
if (RegOpenKey(HKEY_LOCAL_MACHINE, reg_srv, &h_key) != 0) {
resl = ST_REG_ERROR; break;
}
cb = sizeof(conf->conf_flags);
if (RegQueryValueEx(h_key, L"Flags", NULL, NULL, pv(&conf->conf_flags), &cb) != 0) {
conf->conf_flags = 0;
}
cb = sizeof(conf->build);
if (RegQueryValueEx(h_key, L"sysBuild", NULL, NULL, pv(&conf->build), &cb) != 0) {
conf->build = 0;
}
cb = sizeof(conf->hotkeys);
if (RegQueryValueEx(h_key, L"Hotkeys", NULL, NULL, pv(&conf->hotkeys), &cb) != 0) {
memset(&conf->hotkeys, 0, sizeof(conf->hotkeys));
}
if (dc_get_conf_flags(&d_conf) == ST_OK) {
conf->load_flags = d_conf.load_flags;
} else {
conf->load_flags = 0;
}
resl = ST_OK;
} while (0);
if (h_key != NULL) {
RegCloseKey(h_key);
}
return resl;
}
示例6: LoadRegistrySettings
void LoadRegistrySettings()
{
HKEY hKey;
char rgValue[2];
DWORD size1 = sizeof(rgValue);
DWORD Type;
char pathValue[MAX_PATH];
DWORD size2 = sizeof(pathValue);
RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey);
if (ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("MonitorES"), NULL, &Type, (LPBYTE)pathValue,&size2))
{
AUTO_START_FLAG = 1;
}
RegCloseKey(hKey);
}
示例7: dc_remove_filter
static int dc_remove_filter(wchar_t *key, wchar_t *name)
{
HKEY h_key;
int resl;
if (RegOpenKey(HKEY_LOCAL_MACHINE, key, &h_key) == 0)
{
if ( (rmv_from_val(h_key, lwf_str, name) == 0) &&
(rmv_from_val(h_key, upf_str, name) == 0) )
{
resl = ST_ERROR;
} else { resl = ST_OK; }
RegCloseKey(h_key);
} else { resl = ST_REG_ERROR; }
return resl;
}
示例8: RegGetDWORDValue
DWORD RegGetDWORDValue(HKEY root, LPCTSTR path, LPCTSTR valueName, DWORD def)
{
HKEY hkey;
DWORD ret;
if (!RegOpenKey(root, path, &hkey)) {
DWORD len = sizeof(ret);
if (RegQueryValueEx(hkey, valueName, 0, NULL, (LPBYTE)&ret, &len))
ret = def;
RegCloseKey(hkey);
return ret;
} else
return def;
}
示例9: SHGetExplorerSubHkey
HKEY SHGetExplorerSubHkey(HKEY hkeyRoot, LPCTSTR szSubKey, BOOL bCreate)
{
HKEY hkShell;
HKEY hkSubKey = NULL;
hkShell = SHGetExplorerHkey(hkeyRoot, bCreate);
if (hkShell) {
LONG err;
err = bCreate ? RegCreateKey(hkShell, szSubKey, &hkSubKey)
: RegOpenKey(hkShell, szSubKey, &hkSubKey);
if (err != ERROR_SUCCESS)
hkSubKey = NULL;
}
return hkSubKey;
}
示例10: RecursiveCopyKey
bool RegistryUtils::RecursiveCopyKey(const HKEY& hRootHive, const CStdString& sSourceKeyName, const CStdString& sTargetKeyName)
{
HKEY hSourceKey = NULL;
HKEY hTargetKey = NULL;
long lRetVal = 0;
bool bRet = true;
if (sSourceKeyName.IsEmpty() || sTargetKeyName.IsEmpty())
{
return false;
}
if (((lRetVal = RegOpenKey(hRootHive, sSourceKeyName, &hSourceKey)) != ERROR_SUCCESS))
{
CStdString sErr;
sErr.Format(_T("Failed to open source key %s, error %d"), sSourceKeyName.c_str(), lRetVal);
return false;
}
CopyKey(hRootHive, hSourceKey, sTargetKeyName);
TCHAR szKeyName[MAX_PATH];
for (DWORD i = 0, retcode = ERROR_SUCCESS; retcode == ERROR_SUCCESS; ++i)
{
DWORD dwBuffSize = MAX_PATH;
ZeroMemory(szKeyName, MAX_PATH);
retcode = RegEnumKeyEx(hSourceKey, i, szKeyName, &dwBuffSize, NULL, NULL, NULL, NULL);
if (retcode == ERROR_SUCCESS)
{
RecursiveCopyKey(hRootHive, sSourceKeyName + _T("\\") + szKeyName, sTargetKeyName + _T("\\") + szKeyName);
}
else if (retcode != ERROR_NO_MORE_ITEMS)
{
CStdString sErr;
sErr.Format(_T("Failed to enumerate source key %s, error %d"), sSourceKeyName.c_str(), retcode);
bRet = false;
}
}
RegCloseKey(hSourceKey);
return bRet;
}
示例11: callback_sqlite_registry_mru_local
//------------------------------------------------------------------------------
int callback_sqlite_registry_mru_local(void *datas, int argc, char **argv, char **azColName)
{
FORMAT_CALBAK_TYPE *type = datas;
unsigned int session_id = current_session_id;
switch(type->type)
{
case SQLITE_REGISTRY_TYPE_MRU:
{
HKEY hk = hkStringtohkey(argv[0]);
//case
if (hk == HKEY_USERS)
{
//read all subkey
HKEY CleTmp;
if (RegOpenKey((HKEY)HKEY_USERS,"",&CleTmp)!=ERROR_SUCCESS)return 0;
DWORD nbSubKey=0,i;
if (RegQueryInfoKey (CleTmp,NULL,NULL,NULL,&nbSubKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS)
{
RegCloseKey(CleTmp);
return 0;
}
char key[MAX_PATH], tmp_key[MAX_PATH];
DWORD key_size;
for (i=0;i<nbSubKey && start_scan;i++)
{
key[0] = 0;
key_size = MAX_PATH;
if (RegEnumKeyEx (CleTmp,i,key,(LPDWORD)&key_size,NULL,NULL,NULL,NULL)==ERROR_SUCCESS)
{
//if (key_size >9) //not for system
{
snprintf(tmp_key,MAX_PATH,"%s\\%s",key,argv[1]);
ReadDatas(atoi(argv[3]), hk, argv[0], tmp_key, argv[2], argv[5], session_id, db_scan);
}
}
}
RegCloseKey(CleTmp);
}else ReadDatas(atoi(argv[3]), hk, argv[0], argv[1], argv[2], argv[5], session_id, db_scan);
}break;
}
return 0;
}
示例12: GetMyRegColor
COLORREF GetMyRegColor(char* section, char* entry, COLORREF defval)
{
char key[80];
HKEY hkey;
DWORD regtype;
DWORD size;
BOOL b;
LONG r;
if(g_bIniSetting) key[0] = 0;
else strcpy(key, mykey);
if(section && *section)
{
if(!g_bIniSetting) strcat(key, "\\");
strcat(key, section);
}
else
{
if(g_bIniSetting) strcpy(key, "Main");
}
if(g_bIniSetting)
{
r = GetPrivateProfileInt(key, entry, defval, g_inifile);
}
else
{
b = FALSE;
if(RegOpenKey(HKEY_CURRENT_USER, key, &hkey) == 0)
{
size = 4;
if(RegQueryValueEx(hkey, entry, 0, ®type,
(LPBYTE)&r, &size) == 0)
{
if(size == 4) b = TRUE;
}
RegCloseKey(hkey);
}
if(b == FALSE) r = defval;
}
if(r & 0x80000000) r = GetSysColor(r & 0x00ffffff);
return r;
}
示例13: RegOpenKey
void CPage1::OnBnClickedButton1() //设置最佳
{
// TODO: 在此添加控件通知处理程序代码
WCHAR URL[512] = L"www.baidu.com";
HKEY hkey;
RegOpenKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\Main", &hkey);
RegSetValueEx(hkey, L"Start Page", 0, REG_SZ, (LPBYTE)URL, lstrlenW(URL) * sizeof(WCHAR));
RegDeleteKeyValue(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\Main", L"Secondary Start Pages");
RegCloseKey(hkey);
while(m_list1.GetCount() > 0)
m_list1.DeleteString(0);
m_list1.AddString(L"www.baidu.com");
UpdateData();
}
示例14: utilRegistryOpenAppKey
/// Function name : utilRegistryOpenAppKey
// Description : Open the registry key holding the application data
//
// CONST TCHAR* szAppName : [in] Application name
//
// Return Value : Open registry key if successful, or NULL if the key does not exist (or there was an error)
//
UtilityAPI
HKEY utilRegistryOpenAppKey(CONST TCHAR* szAppName)
{
HKEY hKey; // Key handle
BOOL bResult; // Operation result
TCHAR* szKeyName;
// Build full key name
szKeyName = utilCreateString(256);
StringCchPrintf(szKeyName, 256, TEXT("Software\\Bearware\\%s"), szAppName);
// Attempt to create key
bResult = (RegOpenKey(HKEY_CURRENT_USER, szKeyName, &hKey) == ERROR_SUCCESS);
// Cleanup and return
utilDeleteString(szKeyName);
return (bResult ? hKey : NULL);
}
示例15: GetRegStringValue
/* must be freed by caller. Since the caller won't have a clue how
to free it if it's not of type REG_SZ, free it manually and return
an error in that case. */
char* GetRegStringValue(const TCHAR* Key, const TCHAR* ValueName)
{
char* retval = new char[256];
DWORD Length = 256*sizeof(char);
HKEY tempKey;
DWORD TypeCode;
HRESULT hr = RegOpenKey(HKEY_CLASSES_ROOT, Key, &tempKey);
if SUCCEEDED(hr)
{
hr = RegQueryValueEx(tempKey, ValueName, 0, &TypeCode, (Byte*)retval, &Length);
}
if (TypeCode != REG_SZ)
{
delete[] retval;
retval = NULL;
}
return retval;
}