使用模拟打开文件

问题描述 投票:1回答:1

我一直在网上寻找一种方法,通过冒充有访问权限的用户从安全的网络文件夹中打开WORD文件。我最接近找到答案的是2年前的情况: Impersonating in .net (C#) & opening a file via Process.start

这是我正在使用的代码。当我设置arguments = LocalFile_Test时,一切都运行正常,因为用户正在访问有权访问的本地c:\。但是当我设置arguments = RemoteFile_Test时,Word会打开一个空白文档,这与我在参数中放入垃圾的效果相同。所以它似乎无法找到该文件,即使我使用我在下面的属性中指定的用户/域/密码登录时,我可以找到确切的文件名并且它不是空的。有什么事情马上跳出来吗?我很感激你的时间。

Dim LocalFile_Test As String = "C:\New.docx"
Dim RemoteFile_Test As String = "\\Server1\Apps\File\New.docx"

Dim MyStartInfo As New System.Diagnostics.ProcessStartInfo
MyStartInfo.FileName = "C:\Program Files\Microsoft Office\Office12\WINWORD.exe "
MyStartInfo.Arguments = LocalFile_Test

MyStartInfo.LoadUserProfile = True
MyStartInfo.UseShellExecute = False

MyStartInfo.UserName = "specialuser"
MyStartInfo.Domain = "mydomainname"
MyStartInfo.Password = New System.Security.SecureString()
MyStartInfo.Password.AppendChar("p"c)
MyStartInfo.Password.AppendChar("a"c)
MyStartInfo.Password.AppendChar("s"c)
MyStartInfo.Password.AppendChar("s"c)

Process.Start(MyStartInfo)
vb.net impersonation
1个回答
1
投票

我的理解是,您正在尝试从服务器获取受密码保护的文件,并且当您执行进程启动时,它只会打开一个空白单词doc。我认为错误是你试图获取文件的方式,我认为你必须在服务器上映射文件的实际物理路径,如

  System.Web.HttpContext.Current.Server.MapPath("\\Server1\Apps\File\New.docx")

从那里,我相当肯定,你需要为用户创建网络凭证

  System.Net.NetworkCredential=New NetworkCredential(userName:=, password:=)

最后,一旦完成,您可以编写文件,也可以像这样传输文件......

    System.Web.HttpContext.Current.Response.TransmitFile(file name)
    System.Web.HttpContext.Current.Response.WriteFile(file name)

然后,一旦获得该文件,您可以尝试使用进程启动来打开它。

希望有所帮助,如果我所说的不起作用,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.