在C#中使用的StreamWriter服务器 [英] using StreamWriter on server in C#
问题描述
我尝试写到远程计算机具有以下code:
I try to write to a remote machine with the following code:
StreamWriter(@"\\" + remoteMachine + "\\admin$\\" + fileName);
我得到以下错误的登录失败:未知的用户名或密码错误
我得到了用户名,域名和密码。我怎么能写凭据?
如果我已经去过那台电脑在这个环节是没有问题的,但如果它是一个新的会话的计算机无法识别的位置 -
i get the following error Logon failure: unknown user name or bad password.
i got the user name, domain and password. how can i write with credentials?
if i already been to that computer in this session there is no problem, but if it's a new session the computer doesn't recognize the location
我怎么能写凭据?
推荐答案
您需要使用的StreamWriter
前的模拟身份。 WindowsIdentity.Impersonate方法的文章有这样做的一个很好的例子。
You'll need to impersonate the identity before using the StreamWriter
. WindowsIdentity.Impersonate Method article has a great example of doing so.
这里面code,你会使用的StreamWriter
:
Inside this code you would use the StreamWriter
:
using (WindowsImpersonationContext impersonatedUser = newId.Impersonate()) {
StreamWriter(@"\\" + remoteMachine + "\\admin$\\" + fileName);
}
这篇关于在C#中使用的StreamWriter服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!