Question

I want to use mstsc /admin to login to a server silently. My batch file reads the code as

mstsc /v:xxx.xxx.xxx.xxx /admin

But it ask me to enter password. Can anyone help me to skip this step?

I went on to Google and found this site. But I am very new to this stuff (scripting) and could not understand what to do with given code. Is it a vbscript file? Can I do the same thing with a batch file. Please elaborate and I request you to spoon feed. This is not my arena but still I am pushed to fight without weapons.

My basic need is to kick off all users from a remote desktop except mine to perform some maintainable work. Thanks.

Was it helpful?

Solution 5

It became a popular question and I got a notification. I am sorry, I forgot to answer before which I should have done. I solved it long back.

net use \\10.100.110.120\C$ MyPassword /user:domain\username /persistent:Yes

Run it in a batch file and you should get what you are looking for.

OTHER TIPS

Re-posted as an answer: Found an alternative (Tested in Win8):

cmdkey /generic:"<server>" /user:"<user>" /pass:"<pass>"

Run that and if you run:

mstsc /v:<server>

You should not get an authentication prompt.

the command posted by Milad and Sandy did not work for me with mstsc. i had to add TERMSRV to the /generic switch. i found this information here: https://gist.github.com/jdforsythe/48a022ee22c8ec912b7e

cmdkey /generic:TERMSRV/<server> /user:<username> /pass:<password>

i could then use mstsc /v:<server> without getting prompted for the login.

to be secured, you should execute 3 commands :

cmdkey /generic:"server-address" /user:"username" /pass:"password"
mstsc /v:server-address
cmdkey /delete:server-address

first command to save the credential

second command to open remote desktop

and the third command to delete the credential for security reason

all of these commands can be saved in a batch file(bat). (if you save these command in a batch file, third command will not be executed until you close the remote desk)

Same problem but @Angelo answer didn't work for me, because I'm using same server with different credentials. I used the approach below and tested it on Windows 10.

cmdkey /add:server01 /user:<username> /pass:<password>

Then used mstsc /v:server01 to connect to the server.

The point is to use names instead of ip addresses to avoid conflict between credentials. If you don't have a DNS server locally accessible try c:\windows\system32\drivers\etc\hosts file.

Save your username, password and sever name in an RDP file and run the RDP file from your script

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top