Solved

How do I set a Windows service to start automatically after a reboot even if the "Startup Type" is set to Manual?

Posted on 2013-12-30
22
1,058 Views
Last Modified: 2014-01-11
I use Shavlik for patching and have a few web servers (Windows Server 2008) configured to automatically deploy security patches and reboot. The only problem is that we configure service account tied into the Jboss service to "Manual". So, if after the reboot, the Jboss service will not start automatically. How would I configure a manual service to start automatically after a system reboot? Of course I can always change the service to start automatically, but because the programmers in my company set it to start manually, I cannot change that.
0
Comment
Question by:jaedenone
  • 11
  • 9
  • 2
22 Comments
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
the following command starts a service manually.

NET START servicename

just add this into your startup batch file.
0
 

Author Comment

by:jaedenone
Comment Utility
bbao,

I'm not a script guy. Can you explain in details how to accomplish this?
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
When would you expect the script to be automatically executed? After restarting the server without logging on, or after logging with a specific user?
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
There a lot of ways to trigger an action like this. In Active Directory, and if you have to apply the same change to a lot of machines, you will use Group Policies to deploy a startup script.

The smaller, manual solution is to create a Scheduled Task via the GUI, just executing the net start command as shown above, triggered on startup. That will do fine if you have to set that up on a few machines only. Using schtasks it can be done on several targets from remote.
0
 

Author Comment

by:jaedenone
Comment Utility
bbao,

I want it to start the service whenever it reboots, without any need to log in. By the way, these will only be set on a few servers, which are not joined to a domain.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Then the second approach of my comment is appropriate. Set up a Scheduled Task to start at boot. The setup can be done with the following batch file:
@echo off
for %%C in (server1, server2, server3) do (
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc /TR "C:\Windows\System32\sc.exe start TheServiceName" /delay 0005:00
)

Open in new window

This will create the task on 3 machines, triggered 5 minutes after boot.
0
 

Author Comment

by:jaedenone
Comment Utility
Qlemo,

I tried the batch script but it does not seem to work. Maybe you can write it step-by-step for me?

Let's use an example:

1. Let's execute this for a server name "ksolpc01"
2. Let's setup a manual Windows service (attached) as the service that I want to bring up after the system reboot.

Please write the script as is. Where do I save the script? Say I want to execute this to the server from a remote machine, where would I store the script? On the target machine? Does it matter where I store it (e.g. - Desktop)? Also, where you indicated the delay 0005:00, is that the time given for the server to fully reboot before it trigger the auto start of the manual service?
Capture.PNG
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Ok, as an examnple you want to start the Application Layer Gateway service at "ksolpc01".

Script name, location and execution doesn't matter, the script is thought to be run remotely, once or more often for any server to set up. The only requirement is that the script extension is either .cmd or .bat, and the target server is reachable from the execution location.

To make the changes obvious, I've used as much as possible of above script:
@echo off
for %%C in (ksolpc01) do (
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc /TR "C:\Windows\System32\sc.exe start ALG" /delay 0005:00
)

Open in new window

And yes, the 005:00 corresponds to "5 minutes after boot".
0
 

Author Comment

by:jaedenone
Comment Utility
I followed the script above, but it did not execute. I saved it as a .bat file and saved it locally on the actual server itself, and ran it from the actual server. If this is a scheduled task, it should be stored somewhere under Task Scheduler. Can you tell me where I can confirm if this scheduler is set?
0
 

Author Comment

by:jaedenone
Comment Utility
Will this script work if the service is not located in the C:\Windows\System32 directory? What if I want to do this for a Jboss or Tomcat service in the D:?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
For test, let's assume you are on PC1, and the batch file is c:\Scripts\startService.cmd .

Open a command prompt on PC1, then start the batch by typing in the full path and name.
You should see a success message, or some error. Errors might arise from authentication (log in) issues; I presumed your account exists and has admin privileges on the remote machine ksolpc01.

If you can't see an error, go to ksolpc01, start Scheduled Tasks, and you should see the task "StartSvc" created directly under "Task Library" (or similar - no English system here).
You can also do the check from PC1 in Scheduled Tasks by connecting to ksolpc01 by right-clicking on the "(local)" line left, and connect to the remote PC, if that is easier.

---------

It doesn't matter where a service's binaries are located. That paths are stored in the registry. As long as you can see the service as such in the Service management console, all is fine. What you see as path in the batch is the for the controlling software, sc.exe, which can be used to create, start, stop, query, ... services.
0
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 

Author Comment

by:jaedenone
Comment Utility
Here is the path to the manual Jboss service that I want to automatically start after a reboot.

Service Name: ATM Jboss 4.2.3
Path to executable: D:\ServerApps\ATM\wrapper\wrapper.exe -s D:\ServerApps\ATM\wrapper\wrapper.conf

How can this script be written as a batch?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
You only need the service name, "ATM Jboss 4.2.3". But since it contains spaces, we have to enclose it in double quotes for commands, and that makes it difficult as we already have to enclose the complete command in double quotes. The resulting command looks strange and incorrect, but should work (it does for me):
@echo off
for %%C in (ksolpc01) do (
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc /TR "C:\Windows\System32\sc.exe start """ATM Jboss 4.2.3"" /delay 0005:00
)

Open in new window

0
 

Author Comment

by:jaedenone
Comment Utility
Looks like it works! Thank you for that. Almost close to giving you max points, but just one more question (see attached screenshot). There are two services "Apache Tomcat NP" and "Apache Tomcat SCHDL" on ksolpc01 that I'd like to also set to restart after reboot. How would I modify the script (#2) on the screenshot to start both scripts after restart? Your help is much appreciated.
Untitled.png
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Best way IMO is to set up one task per service. It would go with one task, but that's unnecessarily complex.
@echo off
for %%C in (ksolpc01) do (
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc-Jboss /TR "C:\Windows\System32\sc.exe start """ATM Jboss 4.2.3"" /delay 0005:00
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc-NP /TR "C:\Windows\System32\sc.exe start """NP"" /delay 0005:00
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc-SCHDLR /TR "C:\Windows\System32\sc.exe start """SCHDLR"" /delay 0005:00
)

Open in new window

That presumes there is no particular order needed to start the services. If you need to make sure one service is running before starting another, change the delay accordingly, e.g. by adding one minute per service.
0
 

Author Comment

by:jaedenone
Comment Utility
Works like a charm!!! Your the best!
0
 

Author Comment

by:jaedenone
Comment Utility
I tried to apply the script in Windows Server 2003, but it did not work. How do I verify the startup services in task scheduler in Win 2003 after I run the script? Can you briefly write the script for me in Win 2003? Thank you so much!
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
» have a few web servers (Windows Server 2008)
and for those I've created the commands. W2003 is different. Luckily only the /delay parameter will not work, so will have to remove that for W2003.

The tasks created are located in Scheduled Tasks in Control Panel. W2003 doesn't have a MMC for that, display and management is done via Explorer. A direct path to them is C:\WINDOWS\Tasks .
0
 

Author Comment

by:jaedenone
Comment Utility
So will the script be something like this for W2K3?

@echo off
for %%C in (ksolpc01) do (
  schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc-SCHDLR /TR "C:\Windows\System32\sc.exe start """Jboss 4.2.3"" /0005:00
)

Another question is if I execute the .bat script, will it store that task in the C:\WINDOWS\Tasks? Or, will I have to create a scheduled task for it?

This script, if we remove the "/delay", is there no timer set for the service to start up after reboot?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
/0005:00 needs to be removed, too, not only /DELAY ;-). There is no such feature for W2003 to allow to wait a certain time after reboot.

The batch file creates the task, and you can see that in the C:\Windows\Task folder.
0
 

Author Comment

by:jaedenone
Comment Utility
Great! It works for W2k3.

One final question, then I won't bother you again. I just want to understand how that /0005:00 timer work for W2k8. Does that time start counting once the server is fully rebooted, and you get the "Ctrl+Alt+Del" prompt, or does it start counting as soon as you reboot and see the BIOS loading screen? Also, what will happen if you log in before the timer kicks in, and you go view the service, but it does not show started? If you refresh, will it then show started?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
I don't know the exact timing, but technically the delay can start only from the time you see Windows booting, or later. I guess it starts before you see the login.

The service applet needs to be refreshed manually to see changes at any time.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now