[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Scripting Help

Posted on 2014-02-06
1
Medium Priority
?
299 Views
Last Modified: 2014-02-06
Experts,

I am looking to modify the following script:

#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")

void DumpDevice(const DISPLAY_DEVICE& dd, size_t nSpaceCount )
{
    printf("%*sDevice Name: %s\n", nSpaceCount, "", dd.DeviceName );
    printf("%*sDevice String: %s\n", nSpaceCount, "", dd.DeviceString );
    printf("%*sState Flags: %x\n", nSpaceCount, "", dd.StateFlags );
    printf("%*sDeviceID: %s\n", nSpaceCount, "", dd.DeviceID );
    printf("%*sDeviceKey: ...%s\n\n", nSpaceCount, "", dd.DeviceKey+42 );
}

int main()
{
    DISPLAY_DEVICE dd;

    dd.cb = sizeof(DISPLAY_DEVICE);

    DWORD deviceNum = 0;
    while( EnumDisplayDevices(NULL, deviceNum, &dd, 0) ){
        DumpDevice( dd, 0 );
        DISPLAY_DEVICE newdd = {0};
        newdd.cb = sizeof(DISPLAY_DEVICE);
        DWORD monitorNum = 0;
        while ( EnumDisplayDevices(dd.DeviceName, monitorNum, &newdd, 0))
        {
            DumpDevice( newdd, 4 );
            monitorNum++;
        }
        puts("");
        deviceNum++;
    }

    return 0;
}

Open in new window


The output of this code should display only the monitor information:

IE
\\.\DISPLAY1\Monitor0
\\.\DISPLAY1\Monitor1
\\.\DISPLAY1\Monitor2

I also need to know if the device is PnP or UPnp

Device Name: \\.\DISPLAY1\Monitor0
   Device String: Generic PnP Monitor
   State Flags: 3
   DeviceID: MONITOR\DEL4016\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002
   DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002

Thanks in advance for you assistance with this.
0
Comment
Question by:ionmanage
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 39839569
That would be quite straightfoward, e.g.

#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")

void DumpDevice(const DISPLAY_DEVICE& dd, size_t nSpaceCount )
{
    char* pPnP = NULL;

    if (strstr(dd.DeviceString, "PnP")) pPnP = "PnP";

    if (strstr(dd.DeviceString, "UPnP")) pPnP = "UPnP";
    
    printf("%*sDevice Name: %s, Mode: %s\n", nSpaceCount, "", dd.DeviceName, pPnP ? pPnP : "None detected" );
}

int main()
{
    DISPLAY_DEVICE dd;

    dd.cb = sizeof(DISPLAY_DEVICE);

    DWORD deviceNum = 0;
    while( EnumDisplayDevices(NULL, deviceNum, &dd, 0) ){

        DISPLAY_DEVICE newdd = {0};
        newdd.cb = sizeof(DISPLAY_DEVICE);
        DWORD monitorNum = 0;
        while ( EnumDisplayDevices(dd.DeviceName, monitorNum, &newdd, 0))
        {
            DumpDevice( newdd, 0 );
            monitorNum++;
        }
        puts("");
        deviceNum++;
    }

    return 0;
}
                                  

Open in new window


However, "PnP" can only be detected when that info is included in the device string...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question