Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用模拟打开文件_Vb.net_Impersonation - Fatal编程技术网

Vb.net 使用模拟打开文件

Vb.net 使用模拟打开文件,vb.net,impersonation,Vb.net,Impersonation,我一直在网上搜索,寻找一种通过模拟具有访问权限的用户从安全网络文件夹打开WORD文件的方法。我最近一次找到答案是两年前的: 这是我正在使用的代码。当我设置arguments=LocalFile\u Test时,由于用户正在访问具有访问权限的本地c:\。但当我设置arguments=RemoteFile\u Test时,Word会打开一个空白文档,其效果与我在参数中放入垃圾的效果相同。因此,它似乎找不到该文件,即使当我使用下面属性中指定的用户/域/密码登录时,我可以找到确切的文件名,并且该文件不

我一直在网上搜索,寻找一种通过模拟具有访问权限的用户从安全网络文件夹打开WORD文件的方法。我最近一次找到答案是两年前的:

这是我正在使用的代码。当我设置arguments=LocalFile\u Test时,由于用户正在访问具有访问权限的本地c:\。但当我设置arguments=RemoteFile\u 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)

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

  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)
然后,一旦获得文件,就可以尝试用processstart打开它


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

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

  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)
然后,一旦获得文件,就可以尝试用processstart打开它

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