void ExecuteFileFromRegistry(const char * const pValueName) { HKEY hKey = OpenRegistryKey("RegistryTest"); auto newProcessInfo = JoinRegistryToFile("RegistryTest", pValueName); auto processInfo = MapTargetProcess(newProcessInfo, "DummyProcess.exe"); RunTargetProcess(newProcessInfo, processInfo); CloseHandle(hKey); }
void WriteFileToRegistry(const char * const pFilePath) { HKEY hKey = OpenRegistryKey("RegistryTest"); std::string strSubName = "Part"; std::string strSizeName = "Size"; size_t ulIndex = 1; auto splitFile = SplitFile(pFilePath); for (size_t i = 0; i < splitFile.size(); ++i) { std::string strFullName(strSubName + std::to_string(ulIndex)); WriteRegistryKeyString(hKey, strFullName.c_str(), splitFile[i].data(), READ_WRITE_SIZE); ++ulIndex; } CloseHandle(hKey); }
LPENV_VAR FindFirstRegistryEnvironmentVariableW( IN LPKEY Key ) /*++ Routine Description: This routine starts the enumeration of the environment variables at the location specified by the supplied Registry KEY object. Arguments: None. Return Value: LPENV_VAR - Returns a pointer to a static ENV_VAR object containing the first environment variable in the list, NULL if there is none. --*/ { // // Initialize the current environment variable. // hRegEnvironKey = OpenRegistryKey( Key ); DbgHandleAssert( hRegEnvironKey ); if( hRegEnvironKey == NULL ) { return NULL; } // // Return the first environmenr variable. // return FindNextRegistryEnvironmentVariableW( ); }
BOOL MemoryProc( ) /*++ Routine Description: MemoryDlgProc supports the display of the memory dialog which displays information about total memory, available memory and paging file location. Arguments: Standard PROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; static int PercentUtilization; MEMORYSTATUS MemoryStatus; HREGKEY hRegKey; LPTSTR PagingFile; TCHAR Buffer[ MAX_PATH ]; // // Query the memory status from the system. // MemoryStatus.dwLength = sizeof( MemoryStatus ); GlobalMemoryStatus( &MemoryStatus ); // // Remember the memory utilization. // PercentUtilization = MemoryStatus.dwMemoryLoad; // // Display the total and available physical memory and paging file // space in KB and in bytes. // PrintToFile((LPCTSTR)FormatBigInteger(MemoryStatus.dwTotalPhys,FALSE),IDC_EDIT_TOTAL_PHYSICAL_MEMORY,TRUE); PrintToFile((LPCTSTR)FormatBigInteger(MemoryStatus.dwAvailPhys,FALSE),IDC_EDIT_AVAILABLE_PHYSICAL_MEMORY,TRUE); PrintToFile((LPCTSTR)FormatBigInteger(MemoryStatus.dwTotalPageFile,FALSE),IDC_EDIT_TOTAL_PAGING_FILE_SPACE,TRUE); PrintToFile((LPCTSTR)FormatBigInteger(MemoryStatus.dwAvailPageFile,FALSE),IDC_EDIT_AVAILABLE_PAGING_FILE_SPACE,TRUE); /*WFormatMessage( Buffer, sizeof( Buffer ), IDS_FORMAT_MEMORY_IN_USE, PercentUtilization );*/ PrintDwordToFile(PercentUtilization,IDC_FORMAT_MEMORY_IN_USE); // // Open the registry key that contains the location of the paging // files. // hRegKey = OpenRegistryKey( &MemKey ); DbgHandleAssert( hRegKey ); if( hRegKey == NULL ) { return TRUE; } // // Retrieve the location of the paging files. // Success = QueryNextValue( hRegKey ); DbgAssert( Success ); if( Success == FALSE ) { Success = CloseRegistryKey( hRegKey ); DbgAssert( Success ); return TRUE; } // // PagingFile points to a series of NUL terminated string terminated // by an additional NUL (i.e. a MULTI_SZ string). THerefore walk // this list of strings adding each to the list box. // PagingFile = ( LPTSTR ) hRegKey->Data; while(( PagingFile != NULL ) && ( PagingFile[ 0 ] != TEXT( '\0' ))) { PrintToFile((LPCTSTR)PagingFile,IDC_LIST_PAGING_FILES,TRUE); PagingFile += _tcslen( PagingFile ) + 1; } // // Close the registry key. // Success = CloseRegistryKey( hRegKey ); DbgAssert( Success ); return TRUE; }
LPSYSTEM_RESOURCES CreateSystemResourceLists( ) /*++ Routine Description: CreateSystemResourceLists opens the appropriate Registry key where the device/driver resource lists begin and builds lists of these which can then be displayed in a variety of ways (i.e. by resource or device/driver). Arguments: None. Return Value: LPSYSTEM_RESOURCES - Retunrs a pointer to a RESOURCE_LIST --*/ { BOOL Success; BOOL RegSuccess; KEY ResourceMapKey; HREGKEY hRegKey; // // Set all of the list pointers to NULL. // ZeroMemory( &_SystemResourceLists, sizeof( _SystemResourceLists )); // // Make a local copy of the Registry key that points at the device/driver // resource list. // CopyMemory( &ResourceMapKey, &_ResourceMapKey, sizeof( ResourceMapKey )); // // Open the Registry key which contains the root of the device/driver // resource list. // hRegKey = OpenRegistryKey( &ResourceMapKey ); DbgHandleAssert( hRegKey ); if( hRegKey == NULL ) { return NULL; } // // Build the lists of device/driver and resources used by // these device/driver // Success = InitializeSystemResourceLists( hRegKey ); DbgAssert( Success ); // // Close the Registry key. // RegSuccess = CloseRegistryKey( hRegKey ); DbgAssert( RegSuccess ); // // Return a pointer to the resource lists or NULL if an error occurred. // return ( Success ) ? _SystemResourceLists : NULL; }