我有一个 WindowsForms vb.net Framework 4.6 应用程序,它必须将一些文件从 c:\sample
复制到网络驱动器 (\\servername\sample
)。
我必须使用其他凭据才能访问共享。但是我不能使用模拟,因为我必须在服务器上使用本地用户。服务器上的登录类似于 <.\Username> <password>
。
有没有办法使用服务器的本地用户凭据将我的文件复制到网络驱动器?
编辑 18.06:
我也试过这种方法,但对我不起作用。
Dim domain, username, passwordStr, remoteServerName As String
Dim password As New System.Security.SecureString
Dim command As New Process
domain = "servername"
username = "username"
passwordStr = "password"
remoteServerName = "\\servername\path\"
Dim impersonator As New AliasAccount(username, passwordStr)
For Each c As Char In passwordStr.ToCharArray
password.AppendChar(c)
Next
command.StartInfo.FileName = "test.pdf"
command.StartInfo.Arguments = remoteServerName
command.StartInfo.UserName = username
command.StartInfo.Password = password
command.StartInfo.Domain = domain
command.StartInfo.Verb = "open"
command.StartInfo.UseShellExecute = False
impersonator.BeginImpersonation()
command.Start()
impersonator.EndImpersonation()
我在服务器上的用户没有特定的域,因为该用户只存在于服务器上。所以我使用服务器名作为域。我也试过使用“.\”。
我总是收到同样的错误“用户名或密码错误”(从德语翻译成英语)。用户名和密码我检查了30多次……绝对是正确的。我还可以使用凭据连接网络驱动器...所以它们是正确的。
您还有其他建议吗?