【问题标题】:Remote Desktop Connection by making .bat file通过制作 .bat 文件进行远程桌面连接
【发布时间】:2013-12-28 02:50:22
【问题描述】:

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

【问题讨论】:

    标签: windows batch-file remote-desktop


    【解决方案1】:

    我找到了这个

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

    来自archive(或original

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

    沿着cmets我也看到了这个:

    对于正在寻找这个想法但想要使用批处理的人,我创建了以下内容。从记事本中保存这个 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%
    

    【讨论】:

      【解决方案2】:

      我能找到的最佳解决方案是保存 rdp 配置。 比这些选项相对简单得多。 所以通过开始菜单或win+rmstsc.exe打开远程桌面连接。 然后选择高级选项,更改您想要的所有内容,然后另存为。 这将创建一个 .rdp 文件,可以单击该文件以运行或在命令提示符下运行。 :)

      【讨论】:

        【解决方案3】:

        通过双击远程登录使用java和批处理文件

        1. 创建批处理文件Remote.bat并编写如下代码,

          @echo off
          java Remote DEV
          
        2. 创建一个java文件Remote.java并编写如下代码, 还可以在代码中更改远程计算机的 IP 地址。

          import java.awt.MouseInfo;
          import java.awt.Robot;
          import java.awt.event.InputEvent;
          import java.awt.event.KeyEvent;
          import java.util.concurrent.TimeUnit; 
          
          public class Remote
          {
              public static void main(String args[])
              {
                  try 
                  {
                      //showPosition();
          
                      System.out.println("Remote Desktop for-->"+args[0]);
                      String IP = "";
          
                      if("DEV".equalsIgnoreCase(args[0]))
                      {
                          IP = "mstsc /v:10.0.41.101";
                      }
                      else if("UAT".equalsIgnoreCase(args[0]))
                      {
                          IP = "mstsc /v:10.0.45.43";
                      }
                      else if("PRE-PROD".equalsIgnoreCase(args[0]))
                      {
                          IP = "mstsc /v:10.0.45.209";
                      }
          
                      Process p = Runtime. getRuntime(). exec(IP);
                      Robot bot = new Robot();
                      long mask = InputEvent.MOUSE_EVENT_MASK;
          
                      TimeUnit.SECONDS.sleep((long) 2.5);
          
                      bot.mouseMove(607, 290);           
                      bot.mousePress((int) mask);     
                      bot.mouseRelease((int) mask);
          
                      bot.keyPress(KeyEvent.VK_SHIFT);
                      bot.keyPress(KeyEvent.VK_Y);
                      bot.keyRelease(KeyEvent.VK_SHIFT);
                      bot.keyPress(KeyEvent.VK_E);
                      bot.keyPress(KeyEvent.VK_S);
                      bot.keyPress(KeyEvent.VK_B);
                      bot.keyPress(KeyEvent.VK_A);
                      bot.keyPress(KeyEvent.VK_N);
                      bot.keyPress(KeyEvent.VK_K);
                      bot.keyPress(KeyEvent.VK_1);
          
                      bot.mouseMove(765, 508);           
                      bot.mousePress((int) mask);     
                      bot.mouseRelease((int) mask);
          
                  } 
                  catch (Exception e) 
                  {
                      System.out.println("Exception send--->"+e.getMessage());
                      e.printStackTrace();
                  } 
              }
          
              public static void showPosition() throws InterruptedException
              {
                  try
                  {
                      while(true == true)
                      {
                          TimeUnit.SECONDS.sleep(1/2);
                          double mouseX = MouseInfo.getPointerInfo().getLocation().getX();
                          double mouseY = MouseInfo.getPointerInfo().getLocation().getY();
                          System.out.println("X:" + mouseX);
                          System.out.println("Y:" + mouseY);
                          //make sure to import 
                      }
                  }
                  catch(Exception e)
                  {
                      System.out.println("Excpetion inside showPosition-->"+e.getMessage());
                  }
              }
          
          
          }
          

        现在保存代码并双击 Remote.bat。 它会自动打开您的远程计算机。 开心啊啊啊啊

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-30
          • 1970-01-01
          • 1970-01-01
          • 2018-10-10
          相关资源
          最近更新 更多