11 #define RNAME_CHUNK MAX_PATH 12 #define RDATA_CHUNK MAX_PATH 14 #ifdef __GNUC__ // Omissions and quirks... 24 if (!Key) SetLastError( ERROR_INVALID_HANDLE );
27 LSTATUS rc = RegCloseKey( Key );
28 if (rc == 0) Key = NULL;
else SetLastError( rc );
38 LSTATUS rc = RegOpenKey( BaseKey, RegPath, &hKey );
40 if (ok) RegCloseKey( hKey );
48 LONG rc = RegQueryValueEx( key, name, 0,NULL,NULL,NULL );
56 DWORD cbData = 0, dwData = 0;
58 LONG rc = RegQueryValueEx( hKey, ValName, NULL, pType, (
PBYTE)&dwData, &cbData );
59 if (pSize && (rc == ERROR_MORE_DATA))
74 BYTE tmpBuf[MAX_PATH], useHeap;
80 useHeap = (cbData >
sizeof(tmpBuf));
82 rc = RegQueryValueEx( hKey, OldName, NULL, &vType, pData, &cbData );
85 rc = RegSetValueEx( hKey, NewName, 0, vType, pData, cbData );
86 if (
REG_OK( rc )) RegDeleteValue( hKey, OldName );
97 return RegSetValueEx( hKey, ValName, 0, REG_DWORD, (
PBYTE)&Val,
sizeof(
DWORD) );
103 LONG rc = RegQueryValueEx( hKey, ValName, NULL, &type, (
PBYTE)pVal, &cbRd );
106 if (type != REG_DWORD || cbRd !=
sizeof(
DWORD)) rc = ERROR_INVALID_DATA;
128 return RegSetValueEx( hKey, ValName, 0, REG_BINARY, Val, Size );
134 LONG rc = RegQueryValueEx( hKey, ValName, NULL, &type, pVal, pSize );
137 if (type != REG_BINARY) rc = ERROR_INVALID_DATA;
147 size *=
sizeof(TCHAR);
148 return RegSetValueEx( hKey, ValName, 0, Type, (
PBYTE)Str, size );
153 LONG rc = RegQueryValueEx( hKey, ValName, 0, Type, (
PBYTE)Buf, Size );
158 if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_MULTI_SZ)
160 else rc = ERROR_INVALID_DATA;
169 HKEY Key; RECT R; LONG rc;
170 if (IsMinimized( hWnd )) rc = ERROR_INCORRECT_SIZE;
173 rc = RegCreateKeyEx( baseKey, regPath, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL );
176 GetWindowRect( hWnd, &R );
177 RegSetValueEx( Key, valName, 0, REG_BINARY, (
PBYTE)&R,
sizeof(RECT) );
187 LONG rc = RegOpenKeyEx( baseKey, regPath, 0, KEY_READ, &Key );
190 DWORD type = 0, cb =
sizeof(RECT);
191 rc = RegQueryValueEx( Key, valName, 0, &type, (
PBYTE)&R, &cb );
195 SIZE scrSiz = {
SYSMET( CXSCREEN ),
SYSMET( CYSCREEN ) };
196 if ((R.left < 0) || (R.left > scrSiz.cx)) OffsetRect( &R, -R.left, 0 );
197 if ((R.top < 0) || (R.top > scrSiz.cy)) OffsetRect( &R, 0, -R.top );
200 SetWindowPos( hWnd, NULL, R.left, R.top, R.right, R.bottom, SWP_NOZORDER );
215 DWORD nSubkeys, nRemain, ccKeyname, len;
221 rc = RegOpenKeyEx( Parent, SubkeyName, 0,KEY_ALL_ACCESS, &hSubkey );
231 else if (nSubkeys > 0)
235 bufSize = ccKeyname + 1;
239 rc = ERROR_OUTOFMEMORY;
252 rc = RegEnumKeyEx( hSubkey, 0, pKeyname,&len, NULL,NULL,NULL, &time );
259 if (
REG_OK( rc )) nRemain--;
260 else if (rc == ERROR_NO_MORE_ITEMS) nRemain = 0;
271 RegCloseKey( hSubkey );
277 rc = RegDeleteKey( Parent, SubkeyName );
298 #define tempName TEXT("_RegKey_Temp_.bin") // Temporary file name 299 #define PRIVI_BUFSIZE 256 303 PISECURITY_DESCRIPTOR secDesc;
304 SECURITY_ATTRIBUTES secAtt;
305 PTOKEN_PRIVILEGES savePriv;
310 BOOL privOk, allDone;
312 DWORD ccClass, cbSecDesc, dispo;
313 TCHAR szClass[ MAX_PATH ];
323 if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY| TOKEN_ADJUST_PRIVILEGES, &hTok )) {
328 hTok,
true, &savePriv, SE_BACKUP_NAME, SE_RESTORE_NAME, SE_SECURITY_NAME, 0
332 err = GetLastError();
333 privOk = (err == ERROR_NOT_ALL_ASSIGNED);
344 err = RegOpenKeyEx( BaseKey, Subkey, 0, KEY_ALL_ACCESS| ACCESS_SYSTEM_SECURITY, &hKey );
347 goto exit_RestorePriv;
353 err = RegSaveKey( hKey,
tempName, 0 );
362 err = RegQueryInfoKey( hKey, szClass, &ccClass, 0,0,0,0,0,0,0, &cbSecDesc, &ftWrit );
365 goto exit_DeleteTemp;
370 secDesc = (PISECURITY_DESCRIPTOR)
mem_Alloc( cbSecDesc );
371 if (secDesc) err = RegGetKeySecurity( hKey,
ALL_SECURITY_INFO, secDesc, &cbSecDesc );
372 else err = ERROR_OUTOFMEMORY;
375 goto exit_DeleteTemp;
380 secAtt.lpSecurityDescriptor = secDesc;
381 secAtt.bInheritHandle = FALSE;
382 secAtt.nLength =
sizeof(secAtt);
384 err = RegCreateKeyEx(
385 BaseKey, NewSubkeyName, 0, szClass, REG_OPTION_BACKUP_RESTORE,
386 KEY_ALL_ACCESS| ACCESS_SYSTEM_SECURITY, &secAtt, &newKey, &dispo
395 err = RegRestoreKey( newKey,
tempName, REG_FORCE_RESTORE );
403 RegCloseKey( newKey );
413 err = RegCloseKey( hKey );
430 if (hTok) CloseHandle( hTok );
438 #define ULONG_HKCR ULONG_PTR( HKEY_CLASSES_ROOT ) 442 static CCSTR SysKey[ 9 ] = {
443 _T(
"HKEY_CLASSES_ROOT"),
444 _T(
"HKEY_CURRENT_USER"),
445 _T(
"HKEY_LOCAL_MACHINE"),
447 _T(
"HKEY_PERFORMANCE_DATA"),
448 _T(
"HKEY_CURRENT_CONFIG"),
451 _T(
"HKEY_PERFORMANCE_TEXT"),
452 _T(
"HKEY_PERFORMANCE_NLSTEXT")
456 ULONG_PTR keyNr = ULONG_PTR( hkey ) -
ULONG_HKCR;
457 if (keyNr > 6) keyNr = (keyNr >> 4) + 2;
459 if (keyNr < 9)
return SysKey[ keyNr ];
461 static __thread_local TCHAR kname[ 24 ];
462 _stprintf_s( kname,
dimof(kname), _T(
"HKEY_%p"), (PVOID) hkey );
463 TRACE(
DP_WARNING, _T(
"Non-system key %p passed to RegSysKeyName.\n"), hkey );
469 static CCSTR SysAcro[ 9 ] = {
482 ULONG_PTR keyNr = ULONG_PTR( hkey ) -
ULONG_HKCR;
483 if (keyNr > 6) keyNr = (keyNr >> 4) + 2;
485 if (keyNr < 9)
return SysAcro[ keyNr ];
487 static __thread_local TCHAR kname[ 24 ];
488 _stprintf_s( kname,
dimof(kname), _T(
"HK%p"), (PVOID) hkey );
489 TRACE(
DP_WARNING, _T(
"Non-system key %p passed to RegSysKeyAcronym.\n"), hkey );
495 static CCSTR RegVType[ 12 ] = {
501 _T(
"REG_DWORD_BIG_ENDIAN"),
504 _T(
"REG_RESOURCE_LIST"),
505 _T(
"REG_FULL_RESOURCE_DESCRIPTOR"),
506 _T(
"REG_RESOURCE_REQUIREMENTS_LIST"),
509 if (type <= REG_QWORD)
return RegVType[ type ];
511 static __thread_local TCHAR sbuf[ 16 ];
512 _stprintf_s( sbuf,
dimof(sbuf), _T(
"REG_0x%lX"), type );
518 if (!name) name = _T(
"(null)");
519 else if (!*name) name = _T(
"(default)");
LONG RegSetString(HKEY hKey, CSTR ValName, CSTR Str, DWORD Type)
LONG RestoreWindowRect(HWND hWnd, HKEY baseKey, CSTR regPath, CSTR valName)
CSTR mem_FreeStr(CSTR Dup)
HKEY RegCloseKeyEx(HKEY Key)
bool FileExist(CSTR PathName)
CSTR RegValueName(CSTR name)
LONG RegGetDWord(HKEY hKey, CSTR ValName, PDWORD pVal)
void * mem_Alloc(size_t Bytes)
LONG RegGetBool(HKEY hKey, CSTR ValName, bool *pVal)
bool EnablePrivileges(IN HANDLE hToken, IN bool Enable, OPTOUT PTOKEN_PRIVILEGES *ppSave,...)
void __cdecl DPrint(int Level, CSTR Fmt,...)
BOOL RegKeyExist(HKEY BaseKey, CSTR RegPath)
LONG RegGetString(HKEY hKey, CSTR ValName, TSTR Buf, PDWORD Size, PDWORD Type)
LONG RegGetUInt(HKEY hKey, CSTR ValName, PUINT pVal)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
#define ALL_SECURITY_INFO
void * mem_Free(void *pBlk)
CSTR SysErrorMsg(DWORD Err=0, TSTR Buf=NULL, UINT Length=0)
CSTR RegSysKeyName(HKEY hkey)
LONG _RegRenameKey(HKEY BaseKey, CSTR Subkey, CSTR NewSubkeyName)
bool __forceinline bool_cast(BOOL B52)
CSTR RegSysKeyAcronym(HKEY hkey)
LONG RegSetBinary(HKEY hKey, CSTR ValName, PBYTE Val, DWORD Size)
LONG RegDeleteBranch(HKEY Parent, CSTR SubkeyName)
LONG RegGetBinary(HKEY hKey, CSTR ValName, PBYTE pVal, PDWORD pSize)
BOOL RegValueExist(HKEY key, CSTR name)
LONG SaveWindowRect(HWND hWnd, HKEY baseKey, CSTR regPath, CSTR valName)
LONG RegRenameValue(HKEY hKey, CSTR OldName, CSTR NewName)
bool RestorePrivileges(HANDLE hToken, PTOKEN_PRIVILEGES pSaved, bool Dispose)
LPRECT AbsToDimRect(LPRECT pRect)
LONG RegGetValueInfo(HKEY hKey, CSTR ValName, PDWORD pSize, PDWORD pType)
#define RegQuerySubkeys(hKey, pNrKeys, pCcKeyname)
LONG RegSetDWord(HKEY hKey, CSTR ValName, DWORD Val)
CSTR RegTypeName(DWORD type)