Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to verify Windows Service is started or not through Java?

 
Kaarthick Ramamoorthy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could any one help me to verify whether Windows service is already started or not using Java?

Any API available?

Thanks in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this in two ways:
1) use JNI. You will need several native Windows calls for this: OpenSCManager, OpenService and QueryServiceStatus for retrieving, and CloseServiceHandle for cleaning up.

2) use the SC command. For instance, to query whether or not my IIS web server is running:

You'll need to run this using ProcessBuilder (or Runtime.exec), and then parse the output.
 
Kaarthick Ramamoorthy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this. It works. Thank you Prime.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic