• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

How do I catch a net stop event in windows and execute a shutdown hook?

Hello,
This is basically an extension of the quesiton asked in http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21393571.html. Basically I need to capture a stop event, however, the java app runs as a service under windows... I need to know how to catch the event, and perform a task before the actual java app stops. Can someone tell me how to do this properly?

Worth 500 points.

Thanks,
Rick
0
richardsimnett
Asked:
richardsimnett
1 Solution
 
objectsCommented:
What are you using to run your app as a service?
0
 
CEHJCommented:
What are you using to run it as a service?
0
 
objectsCommented:
The code that is handling running it as a service should be notifying when to stop the service.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
richardsimnettAuthor Commented:
I am using the app referred to me in this question:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21343238.html

http://www.devx.com/Java/Article/21604

Basically, it generates and exe which then registers, and executes the service when called.

Thanks,
Rick
0
 
objectsCommented:
You need to check what hooks that product provides for handling shutdown.
And if it doesn't you'll need to implement them yourself (if you have the C source).
0
 
aozarovCommented:
Check if the utility that runs/wrap your application as a service can provide you with callbacks when stop/start the service.
When looking at: http://www.kcmultimedia.com/javaserv/
From the list you provided in your first link it seems that you can get such callback:
"Code that demonstrates passing native SERVICE_STOPPED events from NT's Service Control Manager to a pure java listener class that can be built into your Java application. (No JNI calls are needed in the Java application.) "
0
 
richardsimnettAuthor Commented:
Ok well it appears I will have to switch the wrapper I was using for this. I wrote the author of the wrapper with no response.

Thanks for your help,
Rick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now