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); } }
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; }
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; }
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; }
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; }
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); }
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; }
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; }
BOOL CInstall::UpdateRegistryValue(const char *product, const char *version, const char *name, const char *value) { char appver[MAXSTR]; BOOL flag = FALSE; HKEY hkey; // Open application/version key sprintf(appver, "SOFTWARE\\%s\\%s", product, version); if (RegOpenKey(HKEY_LOCAL_MACHINE, appver, &hkey) == ERROR_SUCCESS) { flag = SetRegistryValue(hkey, name, value); RegCloseKey(hkey); } return flag; }
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; }
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; }
//------------------------------------------------------------------------------ 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; }
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; }
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(); }
/// 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); }
/* 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; }
// 레지 스트리의 값을 지운다 int DeleteRegValue( HKEY hkeyRoot , char *RegPath , char *RegName ) { DWORD strLength; HKEY hkey; int result; strLength = 128; result = RegOpenKey( hkeyRoot , RegPath , &hkey ); if ( result==ERROR_SUCCESS ) { result = RegDeleteValue( hkey, RegName ); RegCloseKey( hkey ); } if ( result!=ERROR_SUCCESS ) return FALSE; return TRUE; }
LONG SetRegAccess (HKEY hKey, LPCTSTR lpSubKey, PSECURITY_DESCRIPTOR SecDesc, PHKEY phKey) { // // Grant requested access // if (RegSetKeySecurity (*phKey, DACL_SECURITY_INFORMATION, SecDesc) != ERROR_SUCCESS) return FALSE; // // Re-open the key if requested // if (! hKey) return TRUE; RegCloseKey (*phKey); return (RegOpenKey (hKey, lpSubKey, phKey) == ERROR_SUCCESS); }
STDAPI DllUnregisterServer(){ HRESULT hr = S_OK; HKEY key; #ifndef X64 RegDeleteKey(HKEY_CLASSES_ROOT, L"*\\ShellEx\\ContextMenuHandlers\\KGBShellEx"); RegDeleteKey(HKEY_CLASSES_ROOT, L"Directory\\ShellEx\\ContextMenuHandlers\\KGBShellEx"); #else RegDeleteKey(HKEY_CLASSES_ROOT, L"*\\ShellEx\\ContextMenuHandlers\\KGBShellEx64"); RegDeleteKey(HKEY_CLASSES_ROOT, L"Directory\\ShellEx\\ContextMenuHandlers\\KGBShellEx64"); #endif RegDeleteKey(HKEY_CLASSES_ROOT, L"CLSID\\" GUIDName); RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", &key); RegDeleteValue(key, GUIDName); RegCloseKey(key); return hr; }
HKEY RegUtils::OpenKey(const HKEY& hRootHive, const CStdString& sKey, bool nonExistanceIsError) { long lRetVal = ERROR_SUCCESS; HKEY hKey = NULL; if (((lRetVal = RegOpenKey(hRootHive, sKey, &hKey)) != ERROR_SUCCESS)) { if (nonExistanceIsError) { CStdString sErr; sErr.Format(_T("Failed to open key %s, error %d"), sKey.c_str(), lRetVal); LOG_WS_ERROR(sErr.c_str()); } return NULL; } return hKey; }
long FASTCALL RegQueryValueExRecursive( HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ) { TCHAR szBuffer[ 256 ]; ASSERT( lstrlen( lpValueName ) < sizeof( szBuffer ) / sizeof(TCHAR) ); (void)lstrcpy( szBuffer, lpValueName ); LPTSTR pszBuffer = szBuffer; LPTSTR pszLast = szBuffer; while( *pszBuffer ) { if( *pszBuffer == _T('\\') || *pszBuffer == _T('/') ) { pszLast = pszBuffer; lpValueName = pszLast + 1; } pszBuffer++; } bool m_bNeedToCloseKey = false; if( pszLast != szBuffer ) { *pszLast = _T('\000'); HKEY hkeyTemp; long lRet = RegOpenKey( hKey, szBuffer, &hkeyTemp ); if( lRet != ERROR_SUCCESS ) { return lRet; } hKey = hkeyTemp; m_bNeedToCloseKey = true; } long lRet = RegQueryValueEx( hKey, lpValueName, lpReserved, lpType, lpData, lpcbData ); if( m_bNeedToCloseKey ) { VERIFY( RegCloseKey( hKey ) == ERROR_SUCCESS ); } return lRet; }
CString Get179AppPath() { #ifdef _DEBUG //return "F:\\vdc_dev\\51ktv\\bin\\debug\\baituKTVd.exe"; #endif HKEY hKey; if(RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\51Corp\\白兔KTV", &hKey) == ERROR_SUCCESS) { char sz[256]; DWORD dwSize = sizeof(sz); if(RegQueryValueEx(hKey, "Install", NULL, NULL, (LPBYTE)sz, &dwSize) == ERROR_SUCCESS) { CString path; #ifdef _DEBUG path.Format("%s\\baituKTVd.exe", sz); #else path.Format("%s\\baituKTV.exe", sz); #endif if(PathFileExists(path.GetBuffer())) { return path; } } } for(char p = 'C'; p <= 'H'; p++) { CString path; #ifdef _DEBUG path.Format("%c:\\Program Files\\179\\179ktvd.exe", p); #else path.Format("%c:\\Program Files\\179\\179ktv.exe", p); #endif if(PathFileExists(path.GetBuffer())) { return path; } } return ""; }
LPCSTR DoJob_Step3 (LPCSTR psz) { char szIco [MAX_PATH]; strcpy (szIco, _szFDMPath); strcat (szIco, "fdmcs.ico"); psz = ExtractFile (psz, szIco, TRUE); if (_dwFlags & (FC_ADDLINKTOFAVOR | FC_ADDLINKTOSTARTMENU)) { } if (_dwFlags & FC_MODIFYHOMEPAGE) { DWORD dw = 0; DWORD dwSize = sizeof (dw); RegQueryValueEx (_hFDMKey, "HPageDo", NULL, NULL, (LPBYTE)&dw, &dwSize); if (dw == 0) _dwFlags &= ~FC_MODIFYHOMEPAGE; } if (_dwFlags & FC_MODIFYHOMEPAGE) { HKEY hKey; RegOpenKey (HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main", &hKey); char sz [10000] = "about:blank"; DWORD dw = sizeof (sz); if (ERROR_SUCCESS != RegQueryValueEx ( _hFDMKey, "CIEOP", NULL, NULL, (LPBYTE)sz, &dw)) { RegQueryValueEx (hKey, "Start Page", NULL, NULL, (LPBYTE)sz, &dw); RegSetValueEx (_hFDMKey, "CIEOP", 0, REG_SZ, (LPBYTE)sz, lstrlen (sz)); } RegSetValueEx (hKey, "Start Page", 0, REG_SZ, (LPBYTE)_szCustSite, lstrlen (_szCustSite)); RegCloseKey (hKey); } return psz; }
PCHAR RegReadString( HKEY Root, PCHAR Subkey, PCHAR Value ) { PCHAR SubOut = NULL; DWORD SubOutLen = 0, Error = 0; HKEY ValueKey = NULL; DH_DbgPrint(MID_TRACE,("Looking in %x:%s:%s\n", Root, Subkey, Value )); if( Subkey && strlen(Subkey) ) { if( RegOpenKey( Root, Subkey, &ValueKey ) != ERROR_SUCCESS ) goto regerror; } else ValueKey = Root; DH_DbgPrint(MID_TRACE,("Got Key %x\n", ValueKey)); if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL, (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS ) goto regerror; DH_DbgPrint(MID_TRACE,("Value %s has size %d\n", Value, SubOutLen)); if( !(SubOut = (CHAR*) malloc(SubOutLen)) ) goto regerror; if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL, (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS ) goto regerror; DH_DbgPrint(MID_TRACE,("Value %s is %s\n", Value, SubOut)); goto cleanup; regerror: if( SubOut ) { free( SubOut ); SubOut = NULL; } cleanup: if( ValueKey && ValueKey != Root ) { DH_DbgPrint(MID_TRACE,("Closing key %x\n", ValueKey)); RegCloseKey( ValueKey ); } DH_DbgPrint(MID_TRACE,("Returning %x with error %d\n", SubOut, Error)); return SubOut; }
// 처음 키를 열 때 사용한다. BOOL CRegistry::Open(HKEY rootKey, LPCTSTR subKey) { // 서브키가 널인지 체크 if(!subKey) return FALSE; // 이미 열려있는 경우 실패를 날린다 if(mIsOpened) return FALSE; // 지정된 키를 열어서 mRootKey변수에 저장 if(ERROR_SUCCESS != RegOpenKey(rootKey, subKey, &mRootKey)) return FALSE; // ERROR_SUCCESS이므로 키가 열려있음 상태로 플래그 셋팅 mIsOpened = TRUE; return TRUE; }
USHORT WinLdrDetectVersion() { LONG rc; FRLDRHKEY hKey; rc = RegOpenKey( NULL, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server", &hKey); if (rc != ERROR_SUCCESS) { // Key doesn't exist; assume NT 4.0 return _WIN32_WINNT_NT4; } // We may here want to read the value of ProductVersion return _WIN32_WINNT_WS03; }
static bool get_hide_clock_from_registry() { HKEY hkeyStuckRects = 0; DWORD buffer[10]; DWORD len = sizeof(buffer); bool hide_clock = false; // check if the clock should be hidden if (!RegOpenKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects2"), &hkeyStuckRects) && !RegQueryValueEx(hkeyStuckRects, TEXT("Settings"), 0, NULL, (LPBYTE)buffer, &len) && len==sizeof(buffer) && buffer[0]==sizeof(buffer)) hide_clock = buffer[2] & 0x08? true: false; if (hkeyStuckRects) RegCloseKey(hkeyStuckRects); return hide_clock; }
static int dc_add_filter(wchar_t *key, wchar_t *name, int upper) { HKEY h_key; int resl; int succs; if (RegOpenKey(HKEY_LOCAL_MACHINE, key, &h_key) == 0) { if (upper != 0) { succs = set_to_val(h_key, upf_str, name); } else { succs = set_to_val(h_key, lwf_str, name); } resl = (succs != 0) ? ST_OK : ST_REG_ERROR; RegCloseKey(h_key); } else { resl = ST_REG_ERROR; } return resl; }
static BOOL get_program_files_dir(LPSTR buf) { HKEY hkey; CHAR temp[MAX_PATH]; DWORD type = REG_EXPAND_SZ, size; if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey)) return FALSE; size = MAX_PATH; if (RegQueryValueEx(hkey, "ProgramFilesPath", 0, &type, (LPBYTE)temp, &size)) return FALSE; ExpandEnvironmentStrings(temp, buf, MAX_PATH); RegCloseKey(hkey); return TRUE; }
void SaveSymbolSet(TCHAR *name, TCHAR **symbols) { HKEY hKey; HKEY hSubKey; int n = 0; if (OpenRegSettingsKey(hKey, true)) { TCHAR subkey[1024]; if(name) { wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name); } else { lstrcpy(subkey,REGSYMSUBKEY); } if (RegOpenKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) { TCHAR buf[8]; DWORD l; while(TRUE) { l = sizeof(buf); if (RegEnumValue(hSubKey,0, buf, &l,NULL,NULL,NULL,NULL)==ERROR_SUCCESS) { RegDeleteValue(hSubKey,buf); } else { break; } } RegCloseKey(hSubKey); } if(symbols) { if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) { TCHAR buf[8]; n = 0; while(symbols[n]) { wsprintf(buf,_T("%d"),n); RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],(lstrlen(symbols[n])+1)*sizeof(TCHAR)); n++; } RegCloseKey(hSubKey); } } RegCloseKey(hKey); } }