Windows Administration: Difference between revisions

From miki
Jump to navigation Jump to search
(New page: == Convert Logical Drive Letter to PhysicalDrive == The following C program illustrates what Win32 API to use to convert a logical drive letter like C: to the corresponding ''PhysicalDriv...)
 
No edit summary
Line 1: Line 1:
== Device Management ==
=== View and Delete Unused Devices ===
Open a '''cmd.exe''' console:
<source lang="winbatch">
> set devmgr_show_nonpresent_devices=1
> devmgmt.msc
</source>
In the ''Device Management Console'', select '''show hidden devices'''. Unused devices are grayed out.

== Convert Logical Drive Letter to PhysicalDrive ==
== Convert Logical Drive Letter to PhysicalDrive ==



Revision as of 16:57, 23 March 2009

Device Management

View and Delete Unused Devices

Open a cmd.exe console:

> set devmgr_show_nonpresent_devices=1
> devmgmt.msc

In the Device Management Console, select show hidden devices. Unused devices are grayed out.

Convert Logical Drive Letter to PhysicalDrive

The following C program illustrates what Win32 API to use to convert a logical drive letter like C: to the corresponding PhysicalDrive specification.

#include <stdio.h>
#include <w32api/wtypes.h>
#include <w32api/ddk/ntdddisk.h>

int main()
{
    HANDLE hDeviceHandle = NULL;

    char drive[] = {'\\', '\\', '.', '\\', 'A', ':', 0};
    DWORD driveMask = GetLogicalDrives();

    for(int i = 0; i < 26; i++)
    {
        drive[4] = 'A' + i;
        printf("Drive: %s\n", drive);
        hDeviceHandle = CreateFile(drive , 0, 0, NULL,
        OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
        if (hDeviceHandle != (HANDLE)-1)
        {
            STORAGE_DEVICE_NUMBER sdn;
            DWORD returned;
            if (DeviceIoControl(
                hDeviceHandle,IOCTL_STORAGE_GET_DEVICE_NUMBER,NULL ,0,&sdn,sizeof(sdn),&returned,NULL));
            {
                printf("\tDevice type: %d number: %d partition: %d\n",sdn.DeviceType,
                sdn.DeviceNumber, sdn.PartitionNumber);
                if(sdn.DeviceType == 7)
                    printf("\t-->\t\\\\.\\PhysicalDrive%d\n",sdn.DeviceNumber);
            }
        }
    }

    return 0;
}

Compile with:

% gcc logicalToPhysicalDrive.cpp

Example of output:

Drive: \\.\C:
        Device type: 7 number: 0 partition: 1
        -->     \\.\PhysicalDrive0