Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get display adapter name using .Net framework

Posted on 2009-06-30
4
795 Views
Last Modified: 2013-11-25
Hi Experts,

I need to get the video adapter name, *similar* to what is availabe using DXDiag

Eg: Name: NVIDIA GeForce 7300 GT
etc

However! I can not use DirectX SDK to obtain this data (due to project restrictions). Therefore, I need to get the equivalent information either directly from the registry (ugly) or via the Win32 API, or *ideally* using .Net Framework 2.0

Can you please provide a code sample C++ .Net preferred which demonstrates how to get the display adaptor name and some other attributes if possible, such as installed video memory etc.

Thanks

0
Comment
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
abel earned 250 total points
ID: 24743524
You can do this using WMI via Win32_VideoController. This example shows more then that, but it should get you started (and you can copy the code that you need): http://www.codeproject.com/KB/cs/EverythingInWmi03.aspx
0
 
LVL 39

Assisted Solution

by:abel
abel earned 250 total points
ID: 24743533
Here's the reference, I think you need "Caption": http://msdn.microsoft.com/en-us/library/aa394512(VS.85).aspx
0
 
LVL 1

Author Closing Comment

by:A_Ridiculously_Long_Unique_Name
ID: 31598594
Here is the solution in C++ .Net

// Video properties demo
// Geoff Machell, July 2009

#using

using namespace System;
using namespace System::Text;


void IterateOverCollection()
{
    System::Management::ManagementClass ^mc = gcnew System::Management::ManagementClass("Win32_VideoController");

    System::Management::ManagementObjectCollection ^moc = mc->GetInstances();

    System::Management::ManagementObjectCollection::ManagementObjectEnumerator ^moe = moc->GetEnumerator();

    while(moe->MoveNext())
    {
        System::Management::ManagementBaseObject ^mbo = moe->Current;

        System::Management::PropertyDataCollection ^pdc = mbo->Properties;
        System::Management::PropertyDataCollection::PropertyDataEnumerator ^pde = pdc->GetEnumerator();

        while(pde->MoveNext())
        {
            System::Management::PropertyData ^pd = pde->Current;
            Console::WriteLine("{0} {1}", pd->Name, pd->Value);
        }
    }
}


int main(array ^args)
{
    Console::WriteLine("Demo by Geoff Machell");
    Console::WriteLine("July 2009");
    Console::WriteLine("\n=====================");

    IterateOverCollection();

    Console::WriteLine("\n=====================\n");

    System::Management::ManagementClass ^mc = gcnew System::Management::ManagementClass("Win32_VideoController");

    System::Management::ManagementObjectCollection ^moc = mc->GetInstances();

    System::Management::ManagementObjectCollection::ManagementObjectEnumerator ^moe = moc->GetEnumerator();

    while(moe->MoveNext())
    {
        System::Management::ManagementBaseObject ^mbo = moe->Current;

        Console::WriteLine( mbo->GetPropertyValue("Caption") );
        Console::WriteLine( mbo->GetPropertyValue("VideoModeDescription") );
        Console::WriteLine( mbo->GetPropertyValue("AdapterRAM") );
    }

    Console::WriteLine("\n=====================\n");
    return 0;
}
0
 
LVL 39

Expert Comment

by:abel
ID: 24750753
The asker has found an alternative solution but posted it inside the comment for grading which is only visible by asker and the one graded. Here's a copy so that everyone can view the final solution:

// Video properties demo
// Geoff Machell, July 2009
 
#using <System.Management.dll>
 
using namespace System;
using namespace System::Text;
 
 
void IterateOverCollection()
{
System::Management::ManagementClass ^mc = gcnew System::Management::ManagementClass("Win32_VideoController");
 
System::Management::ManagementObjectCollection ^moc = mc->GetInstances();
 
System::Management::ManagementObjectCollection::ManagementObjectEnumerator ^moe = moc->GetEnumerator();
 
while(moe->MoveNext())
{
System::Management::ManagementBaseObject ^mbo = moe->Current;
 
System::Management::PropertyDataCollection ^pdc = mbo->Properties;
System::Management::PropertyDataCollection::PropertyDataEnumerator ^pde = pdc->GetEnumerator();
 
while(pde->MoveNext())
{
System::Management::PropertyData ^pd = pde->Current;
Console::WriteLine("{0} {1}", pd->Name, pd->Value);
}
}
}
 
 
int main(array<System::String ^> ^args)
{
Console::WriteLine("Demo by Geoff Machell");
Console::WriteLine("July 2009");
Console::WriteLine("\n=====================");
 
IterateOverCollection();
 
Console::WriteLine("\n=====================\n");
 
System::Management::ManagementClass ^mc = gcnew System::Management::ManagementClass("Win32_VideoController");
 
System::Management::ManagementObjectCollection ^moc = mc->GetInstances();
 
System::Management::ManagementObjectCollection::ManagementObjectEnumerator ^moe = moc->GetEnumerator();
 
while(moe->MoveNext())
{
System::Management::ManagementBaseObject ^mbo = moe->Current;
 
Console::WriteLine( mbo->GetPropertyValue("Caption") );
Console::WriteLine( mbo->GetPropertyValue("VideoModeDescription") );
Console::WriteLine( mbo->GetPropertyValue("AdapterRAM") );
}
 
Console::WriteLine("\n=====================\n");
return 0;
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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