2009-12-21 83 views
0

我在http://www.dotnet247.com/247reference/msgs/28/144136.aspx阅读.NET模拟后,这是基本代码我从工作。.NET假冒问题

我有一个文件复制到网络共享的问题。完成后,此控制台应用程序将在远程服务器上运行,并将文件复制到不同系统上的共享。这两个系统可以看到对方。

我能够将文件从我的机器直接复制到远程共享,让我有机会获得份额。

这是代码。我曾评论说,是导致问题的行:

Dim token1 As Integer 

Dim loggedOn As Boolean = LogonUser("scotts", "MyDomain", "AwesomePw", 3, 0, token1) 

Dim mWI1 As WindowsIdentity = WindowsIdentity.GetCurrent() 

Dim token2 As IntPtr = New IntPtr(token1) 

Dim mWI2 As WindowsIdentity = New WindowsIdentity(token2) 

'This file copies a file successfully 
File.Copy("c:\LogExtractorRecipients.txt", "\\RemoteServer\SHARED\QALogFiles\LogExtractorRecipients2.txt") 

Dim mWIC As WindowsImpersonationContext = mWI2.Impersonate() 

'This causes the error: "Access to the path '\\RemoteServer\SHARED\QALogFiles\QALogFiles\LogExtractorRecipients.txt' is denied." 
File.Copy("c:\LogExtractorRecipients.txt", "\\RemoteServer\SHARED\QALogFiles\QALogFiles\LogExtractorRecipients.txt") 

我冒充本人(以你自己的自我是真实的),以及具有读写权限的共享。我在本地运行此代码。在我使用模拟之前,我可以复制文件。假冒后,我不能。模仿似乎是成功的 - mWI2变量正在填充名称,标记和其他属性。 ImpersonationLevel为3,而之前,在wMI1上,ImpersonationLevel为0.这是我能看到的唯一区别。

有什么建议吗?

+0

请注意,您只能同时相同的“LAN Manager会话”中只有一个帐户连接到特定的主机。 你能更详细地描述你遇到的异常情况吗? – Alex 2009-12-21 19:14:12

+0

我可能失去了一些东西,但看的错误:“获得‘\\ REMOTESERVER \ SHARED \ QALogFiles \ QALogFiles \ LogExtractorRecipients.txt’被拒绝的路径。”你有一个不同的副本目录比正常工作。这条道路是否存在? – ajdams 2009-12-21 19:28:18

回答

0

这是一个长镜头,但考虑试图冒充用户,因为它应该返回了用户的安全上下文中主令牌之前调用DuplicateToken(...)。