通过创建.bat文件进行远程桌面连接 [英] Remote Desktop Connection by making .bat file

查看:273
本文介绍了通过创建.bat文件进行远程桌面连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过制作.bat文件将我的电脑连接到另一台电脑.当我运行该文件时,它应该连接到另一台PC.当我执行此文件时,我写了"mstsc/v:192.168.15.102"命令,它将打开远程桌面窗口并要求用户名和密码.我如何才能避开该窗口并在.bat文件中传递凭据.

I want to connect my pc to another pc by making .bat file. When i run that file it should connect to the other pc. I wrote "mstsc /v:192.168.15.102" command when i execute this file it opens remote desktop window and demands username and password. How can i avoid that window and pass the credential in .bat file.

推荐答案

我发现了这个

    cmdkey /generic:TERMSRV/$server /user:$user /pass:$Password
mstsc /v:$Server

来自存档(或原始)

但是我认为这仅适用于powershell,并且我对Windows没有经验.

But I think that's for powershell only and I'm inexperienced with windows.

在评论中,我也看到了这一点:

Along the comments I also saw this one:

对于那些正在寻找这个想法但想使用批处理的人,我创建了以下内容.从记事本中将其保存为mstscup.cmd(不要忘了最后删除.txt!) 从命令行如下调用它: mstscup服务器名"用户""pass" 我不喜欢离开用户并传递密码库的想法,因此它会在120秒后清除(打开命令提示符窗口). 随时随意修改!

For people that were looking for this idea but want to use batch instead I created the following. Save this a mstscup.cmd from notepad (don’t forget to remove the .txt at the end!) Call it from the command line as follows: mstscup "servername" "user" "pass" I didn’t like the idea of leaving the user and pass in the password vault so it clears it after 120 seconds (leaves a command prompt window opened). Feel free to modify at will!

@echo off
setlocal
:: Check if the user passed at least 1 argument
if "%1%" == "" (
echo Remoted Desktop connection with user and password
echo.
echo Missing arguments. Syntax:
echo %~nx0% "servername" "username" "password"
echo.
echo Jean Morin, v0.1, 2013-02-23
pause
goto :eof
)
:: Next line removes surrounding quotes from server name
set sServer=%~1%
:: Keep the quotes for the username and password (in case spaces exists)
set sUser=%2%
set sPass=%3%
:: Seconds to wait before clearing the newly added password from the vault (see control panel, manage your credentials)
:: You may want to modify this if the server takes longer to connect (WAN). You could add this as a fourth argument.
set sSeconds=120
:: Add a new connection definition method to the vault
cmdkey /generic:TERMSRV/%sServer% /user:%sUser% /pass:%sPass%
:: Connect to the server as a new task
start mstsc /v:%sServer%
:: ping ourselves for x seconds (acts like a pause) then removes the newly added password from the vault
ping -n %sSeconds% 127.0.0.1 >nul:
cmdkey /delete:TERMSRV/%sServer%

这篇关于通过创建.bat文件进行远程桌面连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆