Beispiel #1
0
BOOL SFRegistry::OpenRegistryKey(const  TCHAR* szSubKey)
{
	CloseRegistryKey();

	if (RegOpenKey(m_hRootKey, szSubKey, &m_hRegKey) != ERROR_SUCCESS)
		return FALSE;	

	return TRUE;
}
Beispiel #2
0
BOOL SFRegistry::DeleteKey(const  TCHAR* szSubKey )
{
	CloseRegistryKey();
			
	if( ERROR_SUCCESS  != RegDeleteKey( m_hRootKey, szSubKey ))
	{ 	
			return false;
	}
	
	return true;
}
Beispiel #3
0
SFRegistry::~SFRegistry()
{
	CloseRegistryKey();	
}
Beispiel #4
0
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;
}
Beispiel #5
0
LPENV_VAR
FindNextRegistryEnvironmentVariableW(
    )

/*++

Routine Description:

    FindNextRegistryEnvironmentVariable continues an enumeration that has been
    initialized by a previous call to FindFirstRegistryEnvironmentVariable. For
    each environment variable that it finds it converts it to two simple
    strings, the variable and the value.

Arguments:

    None.

Return Value:

    LPENV_VAR - Returns a pointer to a static ENV_VAR object containing the next
                environment variable in the list, NULL if there are none.

--*/

{
    BOOL        Success;
    DWORD       Length;
    static
    WCHAR       Buffer[ MAX_PATH ];
    static
    ENV_VAR     EnvVar;

    //
    // If there is another environment variable...
    //

    if( QueryNextValue( hRegEnvironKey )) {

        //
        // Remember the environment variable's name.
        //

        EnvVar.Variable = hRegEnvironKey->ValueName;

        switch( hRegEnvironKey->Type ) {

        case REG_SZ:

            //
            // Remember the environment variable's value.
            //

            EnvVar.Value = ( LPWSTR ) hRegEnvironKey->Data;
            break;

        case REG_EXPAND_SZ:

            //
            // Replace the variable portion of the environment variable by
            // expanding into the static buffer.
            //

            EnvVar.Value = Buffer;
            Length = ExpandEnvironmentStrings(
                        ( LPTSTR ) hRegEnvironKey->Data,
                        Buffer,
                        sizeof( Buffer )
                        );
            DbgAssert( Length <= sizeof( Buffer ));
            break;

        default:

            DbgAssert( FALSE );
        }

        //
        // Return the curent environment variable.
        //

        return &EnvVar;

    } else {

        //
        // There are no more environment variables so close the key and
        // return NULL.
        //

        Success = CloseRegistryKey( hRegEnvironKey );
        DbgAssert( Success );
        return NULL;

    }
    DbgAssert( FALSE );
}
Beispiel #6
0
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;
}
Beispiel #7
0
BOOL InitializeSystemResourceLists(
    IN HREGKEY hRegKey
    )

/*++

Routine Description:

    InitializeSystemResourceLists recursively walks the resource map in the
    registry and builds the SYSTEM_RESOURCE lists. This is a data structure
    that links all resources of the same type together, as well as linking all
    resources belonging to a specific device/driver together. Lastly each
    resource is independently linked to the device/driver that owns it. This
    leds to a 'mesh' of linked lists with back pointers to the owning
    device/driver object.

Arguments:

    hRegKey - Supplies a handle to a REGKEY object where the search is to
              continue.

Return Value:

    BOOL    - returns TRUE if the resource lists are succesfully built.

--*/

{
    BOOL    Success;
    HREGKEY hRegSubkey;

    DbgHandleAssert( hRegKey );

    //
    // While there are still more device/driver resource descriptors...
    //

    while( QueryNextValue( hRegKey )) {

        PCM_FULL_RESOURCE_DESCRIPTOR    FullResource;
        LPSYSTEM_RESOURCES              SystemResource;
        LPDEVICE                        Device;
        LPTSTR                          Extension;
        DWORD                           Count;
        DWORD                           i;
        DWORD                           j;

        //
        // Based on the type of key, prepare to walk the list of
        // RESOURCE_DESCRIPTORS (the list may be one in length).
        //

        if( hRegKey->Type == REG_FULL_RESOURCE_DESCRIPTOR ) {

            Count           = 1;
            FullResource    = ( PCM_FULL_RESOURCE_DESCRIPTOR ) hRegKey->Data;

        } else if( hRegKey->Type == REG_RESOURCE_LIST ) {

            Count           = (( PCM_RESOURCE_LIST ) hRegKey->Data )->Count;
            FullResource    = (( PCM_RESOURCE_LIST ) hRegKey->Data )->List;

        } else {

            DbgAssert( FALSE );
            continue;
        }

        //
        // Allocate a DEVICE object.
        //

        Device = AllocateObject( DEVICE, 1 );
        DbgPointerAssert( Device );
        if( Device == NULL ) {
            Success = DestroySystemResourceLists( _SystemResourceLists );
            DbgAssert( Success );
            return FALSE;
        }

        //
        // Allocate a buffer for the device/driver name. The maximum size of
        // the name will be the number of characters in both the key and
        // value name.
        //

        Device->Name = AllocateObject(
                            TCHAR,
                              _tcslen( hRegKey->Name )
                            + _tcslen( hRegKey->ValueName )
                            + sizeof( TCHAR )
                            );
        DbgPointerAssert( Device->Name );
        if( Device->Name == NULL ) {
            Success = DestroySystemResourceLists( _SystemResourceLists );
            DbgAssert( Success );
            return FALSE;
        }

        //
        // Rationalize the device name such that it is of the form Device.Raw
        // or Device.Translated.
        //

        Device->Name[ 0 ] = TEXT( '\0' );
        if(     ( _tcsnicmp( hRegKey->ValueName, TEXT( ".Raw" ), 4 ) == 0 )
            ||  ( _tcsnicmp( hRegKey->ValueName, TEXT( ".Translated" ), 11 ) == 0 )) {

            _tcscpy( Device->Name, hRegKey->Name );
        }
        _tcscat( Device->Name, hRegKey->ValueName );

        //
        // Based on the device name, determine if the resource descriptors
        // should be added to the RAW or TRANSLATED lists.
        //

        if( Extension = _tcsstr( Device->Name, TEXT( ".Raw" ))) {

            SystemResource = &_SystemResourceLists[ RAW ];

        } else if( Extension = _tcsstr( Device->Name, TEXT( ".Translated" ))) {

            SystemResource = &_SystemResourceLists[ TRANSLATED ];

        } else {

            DbgAssert( FALSE );
            Success = DestroySystemResourceLists( _SystemResourceLists );
            DbgAssert( Success );
            return FALSE;
        }

        //
        // Strip off the extension (.Raw or .Translated) from the device name.
        //

        Device->Name[ Extension - Device->Name ] = TEXT( '\0' );

        //
        // Set the signature in the DEVICE object.
        //

        SetSignature( Device );

        //
        // If the DEVICE object list is empty, add the device to the beginning
        // of the list else add it to the end of the list.
        //

        if( SystemResource->DeviceHead == NULL ) {

            SystemResource->DeviceHead = Device;
            SystemResource->DeviceTail = Device;

        } else {

            LPDEVICE    ExistingDevice;

            //
            // See if the DEVICE object is already in the list.
            //

            ExistingDevice = SystemResource->DeviceHead;
            while( ExistingDevice ) {

                if( _tcsicmp( ExistingDevice->Name, Device->Name ) == 0 ) {
                    break;
                }
                ExistingDevice = ExistingDevice->Next;
            }

            //
            // If the DEVICE object is not already in the list, add it else
            // free the DEICE object.
            //

            if( ExistingDevice == NULL ) {

                SystemResource->DeviceTail->Next = Device;
                SystemResource->DeviceTail       = Device;

            } else {

                Success = FreeObject( Device );
                DbgAssert( Success );
            }
        }

        //
        // NULL terminate the DEVICE object list.
        //

        SystemResource->DeviceTail->Next = NULL;

        //
        // For each CM_FULL_RESOURCE DESCRIPTOR in the current value...
        //

        for( i = 0; i < Count; i++ ) {

            PCM_PARTIAL_RESOURCE_DESCRIPTOR   PartialResourceDescriptor;

            //
            // For each CM_PARTIAL_RESOURCE_DESCRIPTOR in the list...
            //

            for( j = 0; j < FullResource->PartialResourceList.Count; j++ ) {

                LPRESOURCE_DESCRIPTOR   ResourceDescriptor;
                LPRESOURCE_DESCRIPTOR*  Head;
                LPRESOURCE_DESCRIPTOR*  Tail;

                //
                // Allocate a RESOURCE_DESCRIPTOR object.
                //

                ResourceDescriptor = AllocateObject( RESOURCE_DESCRIPTOR, 1 );
                DbgPointerAssert( ResourceDescriptor );
                if( ResourceDescriptor == NULL ) {
                    Success = DestroySystemResourceLists( _SystemResourceLists );
                    DbgAssert( Success );
                    return FALSE;
                }

                //
                // Get a pointer to the current CM_PARTIAL_RESOURCE_DESCRIPTOR
                // in the current CM_FULLRESOURCE_DESCRIPTOR in the list.
                //

                PartialResourceDescriptor = &( FullResource[ i ].PartialResourceList.PartialDescriptors[ j ]);

                //
                // Based on the resource type grab the pointers to the head and
                // tail of the appropriate list.
                //

                switch( PartialResourceDescriptor->Type ) {

                case CmResourceTypePort:

                    Head = &SystemResource->PortHead;
                    Tail = &SystemResource->PortTail;
                    break;

                case CmResourceTypeInterrupt:

                    Head = &SystemResource->InterruptHead;
                    Tail = &SystemResource->InterruptTail;
                    break;

                case CmResourceTypeMemory:

                    Head = &SystemResource->MemoryHead;
                    Tail = &SystemResource->MemoryTail;
                    break;

                case CmResourceTypeDma:

                    Head = &SystemResource->DmaHead;
                    Tail = &SystemResource->DmaTail;
                    break;

                case CmResourceTypeDeviceSpecific:

                    //
                    // Since device specific data is not be collected, free the
                    // associated RESOURCCE_DESCRIPTOR object.
                    //

                    Success = FreeObject( ResourceDescriptor );
                    DbgAssert( Success );
                    break;

                default:

                    DbgPrintf(( L"Winmsd : Unknown PartialResourceDescriptor->Type == %1!d!\n", PartialResourceDescriptor->Type ));
                    continue;
                }

                //
                // If the list is empty add the RESOURCE_DESCRIPTOR object to
                // the beginning of the list, else add it to the end.
                //

                if( *Head == NULL ) {

                    *Head = ResourceDescriptor;
                    *Tail = ResourceDescriptor;

                } else {

                    ( *Tail )->NextSame = ResourceDescriptor;
                    *Tail = ResourceDescriptor;
                }

                //
                // NULL terminate the list.
                //

                ( *Tail )->NextSame = NULL;

                //
                // Make a copy of the actual resource descriptor data.
                //

                CopyMemory(
                    &ResourceDescriptor->CmResourceDescriptor,
                    PartialResourceDescriptor,
                    sizeof( CM_PARTIAL_RESOURCE_DESCRIPTOR )
                    );

                //
                // Note the owner (device/driver) of this resource descriptor.
                //

                ResourceDescriptor->Owner = SystemResource->DeviceTail;

                //
                // The RESOURCE_DESCRIPTOR is complete so set its signature.
                //

                SetSignature( ResourceDescriptor );

                //
                // Add the RESOURCE_DESCRIPTOR to the list of resources owned
                // by the current DEVICE.
                //

                if( SystemResource->DeviceTail->ResourceDescriptorHead == NULL ) {

                    SystemResource->DeviceTail->ResourceDescriptorHead
                        = ResourceDescriptor;

                    SystemResource->DeviceTail->ResourceDescriptorTail
                        = ResourceDescriptor;

                } else {

                    SystemResource->DeviceTail->ResourceDescriptorTail->NextDiff
                        = ResourceDescriptor;

                    SystemResource->DeviceTail->ResourceDescriptorTail
                        = ResourceDescriptor;

                }

                //
                // NULL terminate the list.
                //

                SystemResource->DeviceTail->ResourceDescriptorTail->NextDiff
                    = NULL;
            }

            //
            // Get the next CM_FULL_RESOURCE_DESCRIPTOR from the list.
            //

            FullResource = ( PCM_FULL_RESOURCE_DESCRIPTOR )( PartialResourceDescriptor + 1 );
        }
    }

    //
    // Traverse the list of keys in the resource descriptor portion of the
    // registry and continue building the lists.
    //

    while(( hRegSubkey = QueryNextSubkey( hRegKey )) != NULL ) {

        Success = InitializeSystemResourceLists( hRegSubkey );
        DbgAssert( Success );
        if( Success == FALSE ) {

            Success = DestroySystemResourceLists( _SystemResourceLists );
            DbgAssert( Success );
            return FALSE;
        }

        Success = CloseRegistryKey( hRegSubkey );
        DbgAssert( Success );
        if( Success == FALSE ) {

            Success = DestroySystemResourceLists( _SystemResourceLists );
            DbgAssert( Success );
            return FALSE;
        }
    }

    //
    // Set the signatures in both of the fully initialized lists.
    //

    SetSignature( &_SystemResourceLists[ RAW ]);
    SetSignature( &_SystemResourceLists[ TRANSLATED ]);

    return TRUE;
}