• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ending Windows services using JAVA  RSS feed

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to end a windows service using java code? I mean say we open a notepad and we try to end it using a java code and end the service notepad.exe.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
notepad.exe is not a service but a regular application.

For actual Windows services you could use the "sc" command to query, start and stop them. But for applications this does not work.
Perhaps there is a command similar to "sc" or "tasklist" (which can only show current processes, not close them). If not, you will have to use JNI.

Should you choose to use JNI, you should get a handle "hwnd" to the Window, then call This will close the window nicely. The TerminateProcess system call can be used to really terminate the entire process.
 
Preet Prasannan.
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob.
I would try this and post if I I am stuck anywhere.
Thanks a lot again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!