views:

554

answers:

4

I have a batch file that starts a Java process in a Windows 2003 server. As per the security policy, the users of that machine are logged off forcefully, if the user is inactive for a certain period of time. The problem is that when the user is logged out, the process also dies.

I scheduled a new task (Control Panel -> Scheduled Tasks) and selected the option of 'When my computer starts' and gave the user account details there. But it doesn't seem to have any effect, the user is still logged out and the process dies. Is a reboot necessary to make this change effective? And after the reboot, will I achieve what I'm expecting (keeping the process alive)?

Alternatively, will running this process as a Windows Service solve the problem? If so, can you please let me know how I can make a Java program or a batch file to run as a Windows Service? I would prefer not to use any other third party tools or libraries.

Thanks

+10  A: 

If you want it to run under Scheduled tasks you have to make sure you don't have "only run when user logged in" checked, which usually means you need to supply a password.

A windows service would be the normal way to do this: the Java service wrapper is 3rd party but loads of people use it.

If you really wanted to not use a 3rd party method you could use svrany.exe (http://support.microsoft.com/kb/137890) on WIndows NT or later, but it is not designed specifically for Java.

Nick Fortescue
Thanks for the response. Yes, I don't have that particular option set and I have supplied the password details.I learnt about the Java Service Wrapper in another thread. I'm planning to use it as a last resort.
Mani
I love the Java service wrapper. Have been using it for a couple years and it works well.
sjbotha
+2  A: 

Wrapping the process with srvany.exe and launching as a service would work as well.

http://support.microsoft.com/kb/137890

Jesse Weigert
+1  A: 

I'm using Java Service Wrapper to start the java process as windows service. I guess it works similary to the srvany.exe mentioned in the previous posting.

A: 

I don't know it this is relevant but we are using a flag to the jvm so it does not shutdown on logoffs

"java -Xrs"

Link to suns description of -Xrs

Konstantin