Feb 14, 2011 at 9:22am UTC
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 Feb 14, 2011 at 9:23am UTC
Feb 15, 2011 at 4:33am UTC
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.
Feb 15, 2011 at 7:03am UTC
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
Feb 15, 2011 at 7:12am UTC
Its also same as 1st error. You need to do same thing as 1st error. Good Luck buddy.
Last edited on Feb 15, 2011 at 8:55am UTC
Feb 16, 2011 at 6:05am UTC
I'll see what I can do :) I'm a bit swamped at work right now. Thanks for the advice though.
Regards
Feb 23, 2011 at 6:42am UTC
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;
}