Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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;
        try
        {
            // Open the port
            m_comport.Open();
        }
        catch (UnauthorizedAccessException) { bSucceed = false; }
        catch (IOException) { bSucceed = false; }
        catch (ArgumentException) { bSucceed = false; }

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

    }
share|improve this answer
1  
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. –  Anthony Mastrean Jun 14 '12 at 14:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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