我意识到在Windows 7中,无法为同一主机保存不同的凭据,但我需要一些解决方法.
我可以在代码中手动提供用户名和密码吗?将它们存储在临时.rdp文件中?
Krz*_*iek 39
Process rdcProcess = new Process();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/192.168.0.217 /user:" + "username" + " /pass:" + "password";
rdcProcess.Start();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.Arguments = "/v " + "192.168.0.217"; // ip or name of computer to connect
rdcProcess.Start();
Run Code Online (Sandbox Code Playgroud)
上面的代码启动与.217的连接,我没有被提示提供密码.感谢帮助.
Sam*_*son 36
如果要使用powershell,可以使用添加凭据
cmdkey /generic:DOMAIN/"computername or IP" /user:"username" /pass:"password"
Run Code Online (Sandbox Code Playgroud)
然后使用调用RDP连接
Start-Process -FilePath "$env:windir\system32\mstsc.exe" -ArgumentList "/v:computer name/IP" -Wait
Run Code Online (Sandbox Code Playgroud)
如果要删除运行的凭据
cmdkey /delete:DOMAIN/"Computer name or IP"
Run Code Online (Sandbox Code Playgroud)
记得删除""
这是Krzysiek的帖子的更新版本.
var rdcProcess = new Process
{
StartInfo =
{
FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe"),
Arguments = String.Format(@"/generic:TERMSRV/{0} /user:{1} /pass:{2}",
fp.ipAddress,
(String.IsNullOrEmpty(fp.accountDomain)) ? fp.accountUserName : fp.accountDomain + "\\" + fp.accountUserName,
fp.accountPassword),
WindowStyle = ProcessWindowStyle.Hidden
}
};
rdcProcess.Start();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
rdcProcess.StartInfo.Arguments = String.Format("/f /v {0}", fp.ipAddress); // ip or name of computer to connect
rdcProcess.Start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89046 次 |
| 最近记录: |