Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect a remote Windows machine by Java?

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 remote machine.

like image 495
Indranil Ghosh Avatar asked Apr 22 '11 17:04

Indranil Ghosh


People also ask

How do I connect to a remote desktop machine?

Use Remote Desktop to connect to the PC you set up: On your local Windows PC: In the search box on the taskbar, type Remote Desktop Connection, and then select Remote Desktop Connection. In Remote Desktop Connection, type the name of the PC you want to connect to (from Step 1), and then select Connect.


1 Answers

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.
like image 106
Yash Avatar answered Sep 28 '22 00:09

Yash