I have an .NET application that uses WMI to enumerate serial ports and find a device with a specific product id. The application runs fine when logged in as an administrator, but I need it to run on a Windows 7 machine as a standard user.
I have tried running it as administrator. Doesn't work. I have added the user to the administrator group. Doesn't work. I have changed all the security settings from the WMI control. Doesn't work.
Any help would be greatly appreciated.
Here is my WMI code.
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\WMI",
"SELECT * FROM MSSerial_PortName");
foreach开发者_StackOverflow社区 (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("MSSerial_PortName instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("PortName: {0} : Instance: {1} ", queryObj["PortName"], queryObj["InstanceName"]);
string instanceName = (string)queryObj["InstanceName"];
if (instanceName.Length > 0 && instanceName.Contains("6001"))
{
return (string)queryObj["PortName"];
}
}
精彩评论