Remote Desktop Connection by making .bat file

后端 未结 3 2270
有刺的猬
有刺的猬 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:49

    Remote Login using java and batch file by double click

    1. Create batch file Remote.bat and write the following code,

      @echo off
      java Remote DEV
      
    2. Create a java file Remote.java and write following code, also change the IP address of your remote computer in code.

      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());
              }
          }
      
      
      }
      

    Now save the code and double click on Remote.bat. it will automatically open your remote computer. Enjoyyyyyyy

提交回复
热议问题