gpt4 book ai didi

windows - 通过制作 .bat 文件进行远程桌面连接

转载 作者:行者123 更新时间:2023-12-03 11:08:11 33 4
gpt4 key购买 nike

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

最佳答案

我找到了这个

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

来自 archive (或 original )

但我认为这仅适用于 powershell,而且我对 windows 缺乏经验。

沿着评论我也看到了这个:

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

关于windows - 通过制作 .bat 文件进行远程桌面连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20810510/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com