This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to verify Windows Service is started or not through Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to verify Windows Service is started or not through Java?" Watch "How to verify Windows Service is started or not through Java?" New topic
Author

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

Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
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

Joined: Oct 27, 2005
Posts: 19845
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
I tried this. It works. Thank you Prime.
 
Consider Paul's rocket mass heater.
 
subject: How to verify Windows Service is started or not through Java?