I realize that in Windows 7, it is not possible to save different credentials for the same host, but I need some workaround.
Can I provide the username and password manually in the code? Store them in a temp .rdp file?
In the Local Group Policy Editor console go to the section Local Computer Policy > Computer Configuration > Administrative Templates > System > Credentials Delegation. Find the policy named “Allow delegating saved credentials with NTLM-only server authentication”.
Hit Start –> Run and type "gpedit. msc". Navigate to Local Computer Policy –> Computer Configuration –> Administrative Templates –> System –> Credentials Delegation. Double click the policy "Allow Delegating Default Credentials with NTLM-only Server Authentication".
MSTSC is the official command for Remote Desktop on Windows computers. The mstsc command can be used from the command prompt to perform special and specific tasks quickly along with parameters also called switches. Some switch example are: /v:computer: Specifies the remote computer to which you want to connect.
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();
The above code initiates a connection with .217 and I am not being prompted to provide a password. Thanks for help.
If you want to use powershell you could add the credentials using
cmdkey /generic:DOMAIN/"computername or IP" /user:"username" /pass:"password"
Then call RDP connection using
Start-Process -FilePath "$env:windir\system32\mstsc.exe" -ArgumentList "/v:computer name/IP" -Wait
If you want to delete the credentials run
cmdkey /delete:DOMAIN/"Computer name or IP"
Remember to remove ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With