访问被拒绝。查找COM端口时为0x80070005(E_ACCESSDENIED)

时间:2019-01-22 20:32:10

标签: c# vb.net serial-port wmi user-permissions

我们遇到了这样一种情况:少数PC上的某些用户帐户正在获取:

  

访问被拒绝:0x80070005(E_ACCESSDENIED)

当试图进入正在寻找连接了条形码扫描器的COM端口的应用程序的一部分时。
我认为它正在破坏以下代码之一:

Public Shared Function ProcessConnectionOptions() As ConnectionOptions
    Dim options As New ConnectionOptions()
    options.Impersonation = ImpersonationLevel.Impersonate
    options.Authentication = AuthenticationLevel.[Default]
    options.EnablePrivileges = True
    Return options
End Function

OR

Public Shared Function ConnectionScope(ByVal machineName As String, ByVal options As ConnectionOptions, ByVal path As String) As ManagementScope
    Dim connectScope As New ManagementScope()

    connectScope.Path = New ManagementPath("\\" & machineName & path)
    connectScope.Options = options
    connectScope.Connect()
    Return connectScope
End Function

OR

Dim options As ConnectionOptions = ProcessConnection.ProcessConnectionOptions()
Dim connectionScope As ManagementScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, "\root\CIMV2")

Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0")
Dim comPortSearcher As New ManagementObjectSearcher(connectionScope, objectQuery)

要访问PC上的COM端口,是否必须具有特定用户帐户的特定权限?

0 个答案:

没有答案