title: COM - Access is denied
body: <p>I have been stuck now for about 5 days with this problem now. </p>
  
  <p>Basically I'm trying to connect to an OPC server (Kepware) from a remote pc. The code I have written works if I run it on the server where Kepware is installed (in this example 192.168.102.104).</p>
  
  <p>However if I run it from a remote PC I get the following error.</p>
  
  <pre><code>System.UnauthorizedAccesException: Access is denied 
  (Error from HRESULT: 0x080070005 E_ACCESSIFDENIED))
  </code></pre>
  
  <p>I have setup the server following these instructions:
  <a href="http://www.kepware.com/Support_Center/SupportDocuments/Remote%20OPC%20DA%20-%20Quick%20Start%20Guide%20(DCOM).pdf" rel="nofollow noreferrer">http://www.kepware.com/Support_Center/SupportDocuments/Remote%20OPC%20DA%20-%20Quick%20Start%20Guide%20(DCOM).pdf</a></p>
  
  <p>The PCs are not in a domain and both PCs contain the user Administrator with the same password.</p>
  
  <p>Could anyone tell me if the problem might be with the PCs setup or my Code</p>
  
  <p>CODE::</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>Unmanaged Class::</p>
  
  <pre><code>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
      }
  }
  </code></pre>
  
  <p>The impersonation class just impersonates the local user Administrator.</p>
  
  <p>When I run this on the server with Kepware I get the output - Kepware.KepServerEx.V5
  When I run it on the client PC I get the above error</p>
  
  <p>Any help would be greatly greatly appreciated. Thanks.</p>