How do I connect a remote Windows machine by Java?

前端 未结 4 598
南笙
南笙 2021-01-13 17:05

I want to connect to a remote Windows desktop machine from a local machine with a Java program.

I have to check the disk space and several other services on the remo

4条回答
  •  我在风中等你
    2021-01-13 17:30

    Remote Desktop Connection

    Java

    // Creating credentials
    Process p = Runtime.getRuntime().exec("cmdkey /generic:" + ip +
                                          " /user:" + userName +
                                          " /pass:" + password);
    p.destroy();
    
    Runtime.getRuntime().exec("mstsc /v: " + ip + " /f /console");
    
    Thread.sleep(2*60*1000); // Minutes seconds milliseconds
    // Deleting credentials
    Process p1 = Runtime.getRuntime().exec("cmdkey /delete:" + ip);
    p1.destroy();
    
    • By using cmdkey we can create or delete our credentials which specific to current user.

    Command line

    C:> cmdkey /generic:192.168.0.11 /user:XXXXX /pass:XXXXX
         CMDKEY: Credential added successfully.
    C:> mstsc.exe /v:192.168.0.11 /w:800 /h:600
         Connecting to Remote Desktop.
    C:> cmdkey /delete:192.168.0.11
         CMDKEY: Credential deleted successfully.
    

提交回复
热议问题