Trouble getting WMI working

Hi guys,

I'm having a bit of a problem getting the WMI to work for me. I'm basically just trying to get the vendor name for the GPU and display it into a label on the form using a function like the one below. So it needs to eventually return the value as a string^

String^ Form1::GetGPUName () {

SelectQuery search = gcnew System::Management::SelectQuery("SELECT * FROM Win32_VideoController");
ManagementObjectSearcher searcher = gcnew ManagementObjectSearcher(search);

}

Im getting the following errors in VS though.

1. 'System::Management::SelectQuery::SelectQuery(System::String ^)' : cannot convert parameter 1 from 'System::Management::SelectQuery ^' to 'System::String ^

2. 'System::Management::ManagementObjectSearcher::ManagementObjectSearcher(System::String ^)' : cannot convert parameter 1 from 'System::Management::SelectQuery' to 'System::String ^'

The examples I found while googling used new instead of gcnew but that gives me an error aswell and VS says I should consider using gcnew.

Any help would be greatly appreaciated. I hope i've given enough info.

Thanks
Last edited on
You need to pass System::String to ManagementObjectSearcher() object. I don't think 1st error is correct one. Is it possible for you to check declaration in included header for SelectQuery() and ManagementObjectSearcher(). Please pass required data type.
Thanks.
Hi,

I'm still having problems I have the following declared:

namespace System::Management;
namespace System;

I can get around the first error by doing the following:

String^ search = ("SELECT * FROM Win32_VideoController");

But i still get the second error:

System::Management::ManagementObjectSearcher::ManagementObjectSearcher(System::String ^)' : cannot convert parameter 1 from 'System::Management::ManagementObjectSearcher ^' to 'System::String ^'

Any suggestions?

Thanks
Its also same as 1st error. You need to do same thing as 1st error. Good Luck buddy.
Last edited on
I'll see what I can do :) I'm a bit swamped at work right now. Thanks for the advice though.

Regards
Found the solution :)

String^ Form1::GetGPUName () {

String^ Vendor;
String^ search1 = ("SELECT * FROM Win32_VideoController");

ManagementObjectSearcher^ query = gcnew ManagementObjectSearcher(search1);
ManagementObjectCollection^ coll = query->Get();
for each (ManagementObject^ mo in coll)
{
Vendor = ("" + mo["name"]->ToString());
}



return Vendor;
}
Topic archived. No new replies allowed.