Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,957 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,341 people online right now. Registration is fast and FREE... Join Now!




deviceIOcontrol query

 
Reply to this topicStart new topic

deviceIOcontrol query

tootypegs
19 Jan, 2008 - 02:18 PM
Post #1

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
I was searching the msdn forum and came across the follwoing quote

"DeviceIoControl can accept a handle to a specific device. For example, to open a handle to the logical drive A: with CreateFile, specify \\.\a:. Alternatively, you can use the names \\.\PhysicalDrive0, \\.\PhysicalDrive1, and so on, to open handles to the physical drives on a system."

I have implimented deviceIOcontrol for logical drive E - However i was to call device E by its phyical name - does anyone know how to determine physical device names


.........i know this is not strictly a programming question but i was hoping that u guys could hlp me


thanks
User is offlineProfile CardPM
+Quote Post

skaoth
RE: DeviceIOcontrol Query
21 Jan, 2008 - 01:23 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 356



Thanked: 12 times
Dream Kudos: 100
My Contributions
There was a tool from sysinternals that I used to use for things of this nature.
The program is called winobj. It can be found here

http://www.microsoft.com/technet/sysintern...ion/winobj.mspx

Give that a shot and see if it provides you with the information you want.
User is offlineProfile CardPM
+Quote Post

tootypegs
RE: DeviceIOcontrol Query
21 Jan, 2008 - 03:08 PM
Post #3

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
hi, thanks il give it ago. I was hoping that i could obtain it trough code. I have had a look round and come across IOCTL_STORAGE_GET_DEVICE_NUMBER and i think this is the sort of thing im after but has anyone seen this before?
User is offlineProfile CardPM
+Quote Post

skaoth
RE: DeviceIOcontrol Query
22 Jan, 2008 - 11:17 AM
Post #4

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 356



Thanked: 12 times
Dream Kudos: 100
My Contributions
I haven't heard of that particular IOCTL. By the way is is your program trying to send the device drivers IOCTL's?

Anyways here is a small app that can get this information using WMI.
I have not considered all errors in the sample below.

CODE

HRESULT GetWbemService(IWbemServices **pWbemService)
{
    IWbemServices *pWbemServ = NULL;
    IWbemLocator *pLoc = 0;
    HRESULT hr;

    hr = CoCreateInstance(CLSID_WbemLocator, 0,
        CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);

    if (FAILED(hr))
    {
        cout << "Failed to create IWbemLocator object. Err code = 0x"
             << hex << hr << endl;
        CoUninitialize();
        return hr;     // Program has failed.
    }

    // Connect to the root\default namespace with the current user.
    hr = pLoc->ConnectServer(
            BSTR(L"ROOT\\cimv2"),
            NULL, NULL, 0, NULL, 0, 0, pWbemService);

    if (FAILED(hr))
    {
        cout << "Could not connect. Error code = 0x"
             << hex << hr << endl;
        pLoc->Release();
        CoUninitialize();
        return hr;      // Program has failed.
    }

    return S_OK;    
}

void InitCOM()
{
    CoInitializeEx(0, COINIT_MULTITHREADED);

    CoInitializeSecurity(
        NULL,
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
        NULL,                        // Authentication info
        EOAC_NONE,                   // Additional capabilities
        NULL                         // Reserved
        );


}
void WMIQuery()
{


    BSTR language = SysAllocString(L"WQL");
    BSTR query = SysAllocString(L"Select * FROM Win32_DiskDrive");
    // Other query otptions may be 1) Win32_LogicalDisk 2) Win32_DiskDrivePhysicalMedia

    // Create querying object
    IWbemClassObject *pObj = NULL;
    IWbemServices *pServ = NULL;
    IEnumWbemClassObject *pEnum = NULL;
    HRESULT hRet;

    if(FAILED(GetWbemService(&pServ))) { return; }

    // Issue the query.
    hRet = pServ->ExecQuery(
        language,
        query,
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,         // Flags
        0,                              // Context
        &pEnum
        );


    SysFreeString(language);
    SysFreeString(query);
        
    if(FAILED(hRet)) { return; }
    // Get the disk drive information
    ULONG uTotal = 0;

    // Retrieve the objects in the result set.
    for (;;)
    {
        ULONG uReturned = 0;

        hRet = pEnum->Next(
            0,                  // Time out
            1,                  // One object
            &pObj,
            &uReturned
            );

        uTotal += uReturned;

        if (uReturned == 0)
            break;
        VARIANT val;

        pObj->Get(L"Name", 0, &val, NULL, NULL);
        wcout << "name: " << val.bstrVal << endl;

        pObj->Release();    // Release objects not owned.            
    }

    // All done.
    pEnum->Release();
    pServ->Release();

        
}

int main()
{
    // Initialize COM
    InitCOM();

    WMIQuery();

    CoUninitialize();
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 06:04PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month