[英]COM - Access is denied
我已經被這個問題困擾了大約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
}
}
模擬類僅模擬本地用戶Administrator。
當我在帶有Kepware的服務器上運行它時,我得到輸出-Kepware.KepServerEx.V5在客戶端PC上運行它時,我得到了上面的錯誤
任何幫助將不勝感激。 謝謝。
找到了問題的根源。
為什么總是這樣一來,我一發布就知道了嗎?
問題在於服務器的設置方式。 我不會在這里為您提供所有詳細信息,但這與將DCOM設置(在DCONcnfg中)的標識設置為錯誤的用戶有關。
顯然,我忽略了服務器設置指令的那一部分。
很抱歉浪費任何人的時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.