Remote Desktop Connection by making .bat file

后端 未结 3 2065
有刺的猬
有刺的猬 2021-02-06 19:02

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 thi

3条回答
  •  太阳男子
    2021-02-06 19:34

    I found this

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

    from archive (or original)

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

    Along the comments I also saw this one:

    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%
    

提交回复
热议问题