Ant*_*ean 7 windows serial wmi
我正在 Windows 7 信息亭上配置本地应用程序用户(BUILTIN\Users 的一部分)。自助服务终端有一个在虚拟 COM 端口上运行的特殊USB 设备。用户需要权限读取WMI类,MSSerial_PortName在root\WMI命名空间中,找到了COM端口。在 PowerShell 中(我用它来验证配置)
PS> Get-WmiObject -namespace 'root\WMI' -class 'MSSerial_PortName'
Run Code Online (Sandbox Code Playgroud)
并通过常规的 .NET 代码(这就是应用程序的编写方式)
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName");
Run Code Online (Sandbox Code Playgroud)
除非以管理员身份或提升的会话身份运行,否则我会收到“访问被拒绝”错误。我已经阅读了大量有关类似访问问题的问答,但大多数人似乎建议以管理员身份运行。这不是此用户/信息亭/配置的选项。而且,目前,我无法使用设备供应商提供的托管包装器。
我在 Microsoft 管理控制台中运行,加载 WMI 控件,并修改了属性 | 安全 | 命名空间:根\WMI。我将用户组设置为与管理员组具有相同的权限。但这不起作用(我只是猜测)。
我找不到任何的MSDN文档MSSerial_PortName 的MSSerial命名空间“基地”类或其他相关的类(这所建议的文章)。而且我对 WMI 安全性一无所知。
小智 0
我今天也撞到了同样的墙。这暂时对我有用...
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 });
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2253 次 |
| 最近记录: |