15

We use many remote desktops in our development environment and there are many servers deployed in multiple environments. It is tedious to remember their IP addresses, usernames, and passwords. I want to write a small utility with buttons on it. When clicked, I want to start those remote desktops, automatically fetching usernames and passwords from some list.

I know there is a command line equivalent for MS Remote Desktop: mstsc. This question suggests to do this as follows:

cmdkey /generic:TERMSRV/"computername or IP address" /user:"username" /pass:"password"
mstsc /v:"computer name or IP"

I run the first line, and it says credential successfully added. Then when I run the second line it simply runs Remote Desktop Connection for the specified IP address and asks for username and password. I would like it to simply open the remotely connected desktop at specified IP address by automatically applying the credential specified in cmdkey.

  • What's wrong here? Is it possible using such PowerShell script?
  • Can I invoke this script through an HTML page (since there are many other resources that I will be laying onto the webpage which will serve as one spot links for we developers, so that we will not be wasting time and effort finding them each time we want them)? Is it possible by registering the application to a URI scheme?
  • Is there another (standard) way?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahesha999
  • 22,693
  • 29
  • 116
  • 189
  • You cannot create buttons with powershell. PowerShell is a commmand line based language. For buttons, take a look to C# and Visual Studio Express – Solaflex May 10 '13 at 10:13
  • @Solaflex yes I know that I have to call this PowerShell scritps from app built using say .NET. Just removed that questions since I just realized that its very well possible. – Mahesha999 May 10 '13 at 10:17
  • Is the computer in a domain ? – Solaflex May 10 '13 at 10:40
  • yes All remotes computers are in a domain, I am able to connect to them using Remote Desktop Connection but not through PowerShell – Mahesha999 May 10 '13 at 10:53
  • Instead of /generic:TERMSRV/"computername or IP" try this: /generic:YourDomain/"computername or IP" – Solaflex May 10 '13 at 10:54
  • hey well sorry I meant they or on LAN. Even when connecting through Remote Desktop Connection we directly put IPs, And since when I run the second line it shows the dialog asking for username and password it does mean that it finds the remote desktop at the specified IP but need username and password. I think somehow it is not using the credentials I have added. – Mahesha999 May 10 '13 at 11:03
  • hey just realized that it is selecting the presaved username and showing blank password field for input instead of using the username I specified in credentials – Mahesha999 May 10 '13 at 11:07
  • well my office network blocks chat page :( let us continue here only – Mahesha999 May 10 '13 at 11:15
  • ok, try this please: cmdkey /generic:"computername or IP" /user:"username" /pass:"password" – Solaflex May 10 '13 at 11:38
  • Heya it worked can u just put in answer and explain what that meant? Well am noob in PowerShell – Mahesha999 May 10 '13 at 11:46
  • of course ;) Wait a few miinutes It has notihng to do with powershell – Solaflex May 10 '13 at 11:48
  • I editet and hope, that I can also answer your other questions. If you need a C# Class to call powershell scripts from your ASP.NET Page, call me ;) – Solaflex May 10 '13 at 12:05
  • 2
    why dont you just use a rdp manager like royal ts? – James Woolfenden May 10 '13 at 14:21

3 Answers3

17

The problem in your attempt is the parameter /generic.

According to the official website for cmdkey, /generic

identifies the computer or domain name that this entry will be associated with.

In my example, I will call the computer Computer01.

Do you want the credentials associated with TERMSRV/Computer01 ? (Like your example /generic:TERMSRV/"computername or IP address " said)

No, you want it associated to the normal computername Computer01.

Then you have to remove TERMSRV/.

The working result is:

cmdkey /generic:"computername or IP" /user:"username" /pass:"password"

To your other questions:

  1. See the answer above
  2. I don't know if it's possible with HTML only. I don't think so. But I also implement some PowerShell scripts into ASP.NET. This works.
  3. See answer above.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Solaflex
  • 1,382
  • 1
  • 13
  • 24
  • I tried it and it partially work in Windows 10. It asks for the password every time I use the batch script. Do you have any idea how do I make it work without promptly being asked for the password. – Varun Jain Sep 05 '19 at 12:36
2

A lot has changed since 2013. Many system operators already suggested to use ready-made tools which does this. Back in year 2013, Windows store wasn't that great a place (*my opinion). But now it's OK.

There is Microsoft's own Remote Desktop application in the store. The application is universal, that is, it runs on PCs, mobile phones, and holographic devices.

What's good? Microsoft has made the same app available on Android. I have tried for PC and Android. Both work great.

So have a try. I am regular user of these applications now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahesha999
  • 22,693
  • 29
  • 116
  • 189
  • 1
    It would be good if you added the minimum requirements: **Minimum OS**: Windows 10, Windows 8.1, Windows 10 Mobile, Windows Phone 8.1 **Architecture**: ARM, x86, x64 – tukan Jun 22 '17 at 06:01
0

This partially worked for me in Windows. After entering the below two commands in command prompt, it will open RDP for the specified IP address. But still it asked me to enter the password for a different username (already saved username in Remote Desktop Connection) other than the username I entered in my cmd command. Since the administrator does not allow the use of saved credentials to log on to the remote computer.

start cmdkey /generic:"enter your IP address" /user:"enter your username" /pass:"enter your password"
start mstsc /f /v:"enter your IP address"
Sanushi Salgado
  • 1,195
  • 1
  • 11
  • 18