0

I am creating a scheduled task from command line:

schtasks /Create /SC ONSTART /TN "Zookeeper server" /TR D:\Zookeeper\zookeeper-3.4.6\bin\zkServer.cmd /RU System /V1 /f

The issue is that the "Stop task if running for X days" options is always checked. I tried unchecking it, but it always comes back on right away. Since it's a server, I want it to be able to run for more than 3 days.

I saw a solution where you had to export the xml of the task, change the value manually (ExecutionTimeLimit), delete the task and create it from the xml template, but that doesn't work either.

I also thought that it was a mandatory option for a ONSTART trigger, so I tried to replace it with a one time only trigger, the same thing happens.

Is there a way to make sure my app is run on startup (without a user logged in)? Still allowing the user to stop and start it as he pleases.

I know about services, but I heard it was kind of hard to make a service from an app with java.

EDIT: I would prefer to fix that issue, but if that's not possible, a way to install Zookeeper Server as a service. I tried with nssm 2.23, but there is no way to install a service silently (it must be done without user interface).

Amaranth
  • 2,433
  • 6
  • 36
  • 58

2 Answers2

0

Why don't you run that command as a service rather than in the task scheduler? Task scheduler, as the name implies is to schedule tasks, not running them forever.

You can run the command as a service when the server starts and give the user the control if they want to stop it. There's more information about how to make it a service in this other question: Run batch file as a Windows service

Community
  • 1
  • 1
Augusto
  • 28,839
  • 5
  • 58
  • 88
  • I seem to have issues with using this. It adds two dependencies to my installer (the scheduled task is created inside a Inno Setup executable). I don't know if it'll work on every workstation. I wasn't even able to make it work on mine. I wasn't able to install RunAsService because it needs Microsoft .Net Framework 1.1 Package, and when I try to install that, I have an error 'An error occurred while Windows Installer was initializing. Setup will now close.' – Amaranth Aug 12 '14 at 20:37
0

I found a nice Windows service wrapper that allows me to install and manage a service all in command line. It works great with the Zookeeper server from what I tested today.

https://github.com/kohsuke/winsw/

Amaranth
  • 2,433
  • 6
  • 36
  • 58