开发者

WMI Permissions for windows 7 standard user

开发者 https://www.devze.com 2023-04-11 06:15 出处:网络
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

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"];
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号