how to connect remote windows machine by java?

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

I want to connect to a remote windows desktop from a local machine with a Java program.
I have to check the disk space and several other services in the remote machine.

回答1:

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); // min sec millisec // 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. 


回答2:

You could install an SSH server on your remote desktop and you can write a java program using jcraft and jsch libraries on your local machine to make ssh connection to your remote desktop.



回答3:

you could consider also an RDP java solution. There are a lot of solutions out there. Check them out here: http://en.wikipedia.org/wiki/Comparison_of_Java_Remote_Desktop_projects

cheers!



回答4:

The answer depends upon what OS your local machine (host) is using to connect to your remote target Windows box.

If it is a Unix based box, I would recommend using the open source library j-Interop

Note, that you may need to manually modify the registry on the target box so it can work correctly (make sure you peruse the FAQs of the project's website). If you find weird issues (Exceptions thrown while connecting), here's a good article that helped me resolve them: https://wiki.jenkins-ci.org/display/JENKINS/Windows+slaves+fail+to+start+via+DCOM

On the other hand, if you are using a Windows box as your host, then your life will be much easier. I would recommend using:

Note that all of the above are opensource projects.

The freeware version out there as mentioned above is j-Integra but I never tried using it.



回答5:

You can use WMI (Windows Management Instrumentation).

See these links:

http://henryranch.net/software/jwmi-query-windows-wmi-from-java/

http://j-integra.intrinsyc.com/support/com/doc/other_examples/WMI_Scripting_from_Java.htm

http://www.vijaykandy.com/2009/09/windows-management-instrumentation-wmi-from-java/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!