I am configuring a local application user (part of BUILTIN\Users) on a Windows 7 kiosk. The kiosk has a special USB device running on a virtual COM port. The user needs permission to read the WMI class, MSSerial_PortName, in the root\WMI namespace, to find the COM port. In PowerShell (which I'm using to verify the configuration)

PS> Get-WmiObject -namespace 'root\WMI' -class 'MSSerial_PortName'

and by regular .NET code (which is how the application is written)

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName");

I get "access denied" errors unless running as an Administrator or elevated session. I have read plenty of Q&A on similar access problems, but most seem to recommend running as Administrator. That's not an option for this user/kiosk/configuration. And, at the moment, I am unable to use the managed wrapper from the device vendor.

I played around in the Microsoft Management Console, loading the WMI Control, and modified the Properties | Security | namespace: Root\WMI. I set the Users group to have the same permissions as the Administrators group. But that didn't work (I was just guessing anyway).

I can't find any MSDN documentation on MSSerial_PortName the MSSerial "base" class or other related classes in the namespace (as suggested by this article). And I don't know anything else about WMI security.


I hit the same wall today. This works for me temporarily...

catch (ManagementException ex)
    Debug.WriteLine( string.Format( "##DBG An error occurred while querying for WMI data to find available COM ports:\n Message: {0}\n Stacktrace: {1}",  ex.Message, ex.StackTrace) );

    bool bSucceed = true;

    // TODO Q&D solutions. As it does not work as expected (on windows 7 ) we create our ow default list here and check if we can open the ports
    for (int x = 1; x <= 9; x++)
        bSucceed = true;
        cComportName = string.Format("COM{0}", x);

        // Check if we can open it here

        // Set the port's settings
        m_comport.BaudRate = 9600; 
        m_comport.DataBits = 8; // int.Parse(cmbDataBits.Text);
        m_comport.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "1" );
        m_comport.Parity = (Parity)Enum.Parse(typeof(Parity), "None" );
        m_comport.PortName = cComportName;
            // Open the port
        catch (UnauthorizedAccessException) { bSucceed = false; }
        catch (IOException) { bSucceed = false; }
        catch (ArgumentException) { bSucceed = false; }

        if (bSucceed) 
            m_listComPorts.Add(new string[ConstComPortAttr.COMPORT_MAX_COLUMNS] { cComportName, cInstanceName });

  • 3
    I can't just try every COM port. There are several serial devices on this kiosk and I have to query and select a very specific one. Jun 14 '12 at 14:27

I've found another way in PowerShell and it does not require admin privileges:

PS> Get-WmiObject -Namespace root/cimv2 -Class Win32_PnPEntity -Filter "ClassGuid='{4d36e978-e325-11ce-bfc1-08002be10318}'"

Unfortunately it does not give you portname in COMx form, but using a simple text parsing you should be able to extract the port name from device name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.