【问题标题】:COM - Access is deniedCOM - 访问被拒绝
【发布时间】:2013-02-13 09:06:45
【问题描述】:

我现在被这个问题困扰了大约 5 天。

基本上,我正在尝试从远程 PC 连接到 OPC 服务器 (Kepware)。如果我在安装了 Kepware 的服务器上运行我编写的代码(在此示例中为 192.168.102.104),则我编写的代码有效。

但是,如果我从远程 PC 运行它,我会收到以下错误。

System.UnauthorizedAccesException: Access is denied 
(Error from HRESULT: 0x080070005 E_ACCESSIFDENIED))

我已按照以下说明设置服务器: http://www.kepware.com/Support_Center/SupportDocuments/Remote%20OPC%20DA%20-%20Quick%20Start%20Guide%20(DCOM).pdf

PC 不在域中,并且两台 PC 都包含具有相同密码的用户 Administrator。

谁能告诉我问题可能出在 PC 设置或我的代码上

代码::

class Program
{
    static void Main(string[] args)
    {
        try
        {
            Unmanaged.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero,
                                           Unmanaged.RpcAuthnLevel.Connect,
                                           Unmanaged.RpcImpLevel.Anonymous, IntPtr.Zero,
                                           Unmanaged.EoAuthnCap.None, IntPtr.Zero);

            using (new Impersonation("Administrator", "TEST", "Password"))
            {
                OPCServer opcServer = new OPCServer();
                opcServer.Connect("Kepware.KEPServerEx.V5", "192.168.102.104");
                Console.WriteLine(opcServer.ServerName);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Connection error:::\n\n{0}\n\n",ex);
            Console.ReadLine();
        }
        Console.ReadLine();
    }
}

非托管类::

partial class Unmanaged
{
    [DllImport("ole32.dll")]
    public static extern int CoInitializeSecurity(IntPtr pVoid, int
        cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level,
        RpcImpLevel impers, IntPtr pAuthList, EoAuthnCap dwCapabilities, IntPtr
        pReserved3);

    public enum RpcAuthnLevel
    {
        Default = 0,
        None = 1,
        Connect = 2,
        Call = 3,
        Pkt = 4,
        PktIntegrity = 5,
        PktPrivacy = 6
    }

    public enum RpcImpLevel
    {
        Default = 0,
        Anonymous = 1,
        Identify = 2,
        Impersonate = 3,
        Delegate = 4
    }

    public enum EoAuthnCap
    {
        None = 0x00,
        MutualAuth = 0x01,
        StaticCloaking = 0x20,
        DynamicCloaking = 0x40,
        AnyAuthority = 0x80,
        MakeFullSIC = 0x100,
        Default = 0x800,
        SecureRefs = 0x02,
        AccessControl = 0x04,
        AppID = 0x08,
        Dynamic = 0x10,
        RequireFullSIC = 0x200,
        AutoImpersonate = 0x400,
        NoCustomMarshal = 0x2000,
        DisableAAA = 0x1000
    }
}

模拟类只是模拟本地用户管理员。

当我使用 Kepware 在服务器上运行它时,我得到了输出 - Kepware.KepServerEx.V5 当我在客户端 PC 上运行它时,出现上述错误

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 你走错了路。您不能模拟仅由该计算机知道的用户帐户,用户名匹配无关紧要。您必须通过远程计算机上的 DCOM 配置 hoopla。

标签: c# com dcom opc


【解决方案1】:

找到问题的根源。

为什么总是一发我就想通了?

问题在于服务器的设置方式。我不会在这里详细介绍所有细节,但这与将 DCOM 设置(在 DCONcnfg 中)中的身份设置为错误的用户有关。

显然我忽略了服务器设置说明。

很抱歉浪费了任何人的时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 2012-02-21
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    相关资源
    最近更新 更多