The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q&A: How do I Run my Script as a Windows Service — but only during Working Hours?

How do I run my Script As a Windows Service but only during Working Hours?
  I recently bought a license for AlwaysUp. I used it to install several scripts as Windows Services.

Most of my scripts run one time per day, and those are fine. But I have others that must run every 30 minutes — between 8:00 AM and 7:00 PM, Monday to Friday. How do I get my scripts to work like that in AlwaysUp?

— Jasaf

Hi Jasaf.

There are a couple of steps you should take run your scripts exactly when you want to.

1. Configure AlwaysUp to run your script every 30 minutes

By default, AlwaysUp runs your script 24/7, launching it at boot and quickly restarting it whenever it stops. But that’s clearly not what you want.

To run your script every 30 minutes, on the hour and half-hour:

  1. Edit your script in AlwaysUp

  2. Switch to the Restart tab. These settings determine what AlwaysUp does after your script exits.

  3. Since you don’t want to restart your script immediately after it completes, select the Not immediately option.

  4. Choose On the next hour and half-hour.

  5. Check Minimize event logging as the application stops & restarts. That option tells AlwaysUp that frequent stops and starts are normal and shouldn’t cause panic. 🙂

  6. Save your changes.

    Set your script to run every 30 minutes

At this point, you should test your AlwaysUp entry and confirm that it behaves correctly. Once started, the script should run at the top and the bottom of the hour.

For example, we set up a batch file service as above. After an initial run, the state switched to “Waiting”. And clicking the clock icon showed AlwaysUp holding off until 3:30 for the next run (as expected):

AlwaysUp is waiting to run the script

2. Use Service Scheduler to control when your AlwaysUp service runs

So your script is now set to run every half-hour. Great! However, AlwaysUp will run it all day, every day — weekends included.

To make sure that your script runs only Monday through Friday between 8 AM and 7 PM:

  1. Download our free Service Scheduler utility. (You can setup the Windows Task Scheduler instead, but Service Scheduler is much easier to use.)

  2. Start Service Scheduler.

  3. Select Service Task > New from the menu.

  4. Configure the Add Service Task window to start your AlwaysUp-created service every weekday at 8 AM. The window should look like this:

    AlwaysUp is waiting to run the script

    Note that the name of the service will be whatever you called your script in AlwaysUp, plus the “(managed by AlwaysUpService)” suffix. For example, our AlwaysUp entry is named “Process Folder Script” so the corresponding service is called “Process Folder Script (managed by AlwaysUpService)”. And that’s what we selected in the screenshot above.

  5. Click Save to create the new service task.

  6. Finally, create another service task that stops the same service every weekday at 7 PM:

    AlwaysUp is waiting to run the script
  7. You should end up with a couple of tasks in Service Scheduler:

    AlwaysUp is waiting to run the script

And that’s it. Going forward, AlwaysUp will run your script every 30 minutes, but only on weekdays between 8 AM and 7 PM.

Enjoy!

Posted in AlwaysUp | Tagged , , , | Leave a comment

AlwaysUp 14: Improved Performance, Support for Emby Server, Java WAR Files

AlwaysUp 14: Better Performance, Support for Java WAR Files, Emby Server

AlwaysUp version 14 is available for download!

This new release focuses on making AlwaysUp the best tool for running multiple applications as Windows Services. Here are some of the highlights.

Significant performance improvements when running many applications

Our development team rolled up their sleeves to review the code base and tune key internal components to improve efficiency. Expensive operations — like scanning the desktop for application crash windows — were optimized by caching frequent lookups and selecting lightweight Win32 API functions when possible.

The details are very technical so we won’t get into them here, but it was a major exercise that resulted in a huge performance boost.

And our in-house analysis indicates that customers running several programs with AlwaysUp will reap the most benefits. Specifically, tests on a Windows Server 2022 computer show that AlwaysUp 14 reduces CPU load by:

  • 1 to 5% when managing a single application as a Windows Service

  • 10 to 20% when 5 programs are installed as services

  • Up to 45% when AlwaysUp is running more than 25 applications.

We also benchmarked a few extreme scenarios to see how the new code performs. In one such test, we were happy to see that CPU load remained relatively low even after we overloaded our computer with more than 100 services:

AlwaysUp running many applications

Please don’t try that at home!

The Application Advisor helps you install Emby Server and Java WAR files

Do you want to start the popular Emby Media Server as soon as your computer boots?

Or are you deploying a Java WAR package to run 24/7 inside your organization?

If so, you’ll be happy to know that both Emby and Java WAR applications can be added to AlwaysUp in a few clicks!

Indeed, with the easy to use Application Advisor, you won’t need to mess with command line parameters or obscure options. That’s because the Advisor understands how applications and services work. As such, it will handle all complexity and quickly produce a Windows Service with the best/recommended settings.

For example, to setup Emby, all you need to enter is the password for your Windows account. The Application Advisor does everything else:

Adding Emby Media Server with the Application Advisor

AlwaysUp is fully compatible with Windows 10 & 11 22H2

AlwaysUp is compatible with Windows 11 22H2

As usual, Microsoft continues to issue twice-yearly updates to its Windows operating systems.

Windows 10 22H2 began rolling out to customers on October 18. However, as a member of the Windows Insider program, we’ve been playing with that version since August.

Similarly, Windows 11 22H2 started rolling out in September. And like Windows 10 22H2, we’ve been evaluating it for over a month now.

Our assessment? AlwaysUp continues to work flawlessly with both operating systems. In some sense, that is to be expected as Microsoft has left the Windows Services layer untouched.

Other fixes & improvements

  • We’ve added support for services that don’t return a valid description (e.g. McpManagementService) on Windows 10 and Windows 11.

  • AlwaysUp now tolerates Active Directory slowness when creating a new Windows Service. In previous versions, service creation might time out when validating the Windows account with the Active Directory server.

  • In rare circumstances, handling Windows event logs with millions of records would result in hangs and slowdowns. Our team reworked the code to efficiency read records from massive event logs.

  • AlwaysUp 14 preserves the desktop’s visual styles/themes when launching the application in the current session. No more “strange looking” window borders!

As usual, please review the release notes for the full list of features, fixes and improvements included in AlwaysUp version 14.

Upgrading to AlwaysUp 14

If you purchased AlwaysUp version 13 (after October 2021), you can upgrade to version 14 for free. Simply download and install “over the top” to preserve your existing applications and all settings. Your registration code will continue to work as well.

If you bought AlwaysUp version 12 or earlier (before October 2021), you will need to upgrade to use version 14. Consequently, please purchase upgrades here — at a 50% discount.

See the complete upgrade policy for additional details.

Thank you for reading!

Posted in AlwaysUp | Tagged , , , , , , , , , , | Leave a comment

Q&A: Can I Sync Multiple Dropbox Accounts with AlwaysUp?

Can I Sync Multiple Dropbox Accounts with AlwaysUp?
  I’m using AlwaysUp to install Dropbox as a service. Is it possible to run more than one Dropbox instance simultaneously, each from a different user profile?

I realize in general this is a “Not A Good Thing to do”, but my desire is to mirror several users’ files to a central computer to simplify backup, so the Dropbox folders wouldn’t be shared or modified externally, just locally synced.

— Brian

Hi Brian. That’s a great question! Let’s roll up our sleeves and find out how Dropbox works with AlwaysUp.

AlwaysUp supports many instances of any program — including Dropbox

AlwaysUp doesn’t place any restrictions on the number of accounts/instances of an application you can run.

For example, you can install several copies of Notepad as a service with AlwaysUp and encounter zero problems when running. You’ll just have a lot of Notepad processes. 🙂

AlwaysUp running multiple copies of Notepad

As a result, all problems you encounter come from the application you are running as a service — not from AlwaysUp.

So the question we really need to answer is: “Under what conditions can I use Dropbox with multiple accounts?”

We’ll perform a few tests to find out. But first, let’s review the concept of a “session”, which will be important as we investigate Dropbox.

A quick review of Sessions and Session 0

When you log into Windows, you are assigned a session. You can think of a session as the interactive desktop hosting all the applications you start and use.

In fact, a session is a foundational component of Windows. Here are a few key facts about sessions:

  • A session is a dynamic construct. Windows creates a new session when you log on; it destroys that session when you log off.

  • Each session is assigned a unique non-negative identifier (ID) and it’s common to identify a session by that number. For example, the session with ID 5 is called “Session 5”.

  • Every application running on your PC must reside in a session. And when a session closes (i.e. when you log off), Windows terminates all applications running in that session.

  • Session 0 (i.e. the session with ID 0) is the only session automatically created when the computer boots — before anyone logs on. As such, Session 0 is always available on your PC. However, because of security restrictions, you can no longer access Session 0.

  • Windows Services — and any applications that must run independently of a user — operate in Session 0.

  • AlwaysUp starts Dropbox in Session 0 when your computer boots

Sessions are important because each instance of Dropbox runs in a session.

Preparing to test Dropbox

For our tests, we worked with two users — Mike Jones and Hazel Smith. Each has their own Dropbox account online.

We created desktop accounts for Mike and Hazel on our Windows 11 PC and installed Dropbox version 157.4.4808 in each account. Afterwards, we logged in as each user and confirmed that the Dropbox desktop app was connected to their cloud account and synchronizing files as expected.

Finally, we installed Dropbox as a Windows Service with AlwaysUp to automatically sync Mike’s files even when he’s not logged on. In fact, here you can see Mike’s file synchronization running happily in Session 0:

Dropbox running with AlwaysUp

With that foundation in place, we ran a few experiments to answer three basic questions.


Question #1: Can Mike also start Dropbox on his desktop?

As mentioned, Mike has Dropbox working well. He has also set up Dropbox to run as a Windows Service with AlwaysUp. As a result, file synchronization will start as soon as the PC boots — before Mike logs in.

In this scenario, Mike logged into his computer. Windows created Session 2 for him. Mike opened AlwaysUp and confirmed that Dropbox was already running (in Session 0).

Next, Mike double-clicked the Dropbox icon to launch the program on his desktop. But it didn’t work. Dropbox did not start and no tray icon appeared.

Instead, Dropbox seemed to acknowledge what Mike was trying to do by opening his Dropbox folder in File Explorer:

Mike's Dropbox folder opened

But no new copy of Dropbox started on Mike’s desktop.

Dropbox prevented Mike from starting a second copy in Session 2 because he already had a copy of the program running in Session 0.

Answer: No

Since Mike is already running Dropbox with AlwaysUp, he cannot start another copy on his desktop. Based on this experience, it seems that that Dropbox will only run a single copy of itself for any given user — across all sessions.


Question #2: Can Hazel run Dropbox on her desktop?

So Mike’s Dropbox running in Session 0 prevents him from starting a second copy. But will it also block Hazel?

To find out, Hazel logged in to the PC and double-clicked the Dropbox icon to launch the program on her desktop.

After a few seconds, the familiar tray icon () appeared. Hazel proceeded to copy files to and from her Dropbox folder and all were synchronized. Dropbox worked completely normally.

Indeed, here you can see the Dropbox.exe processes running in Session 0 (for Mike) and Session 3 (for Hazel):

Mike's in Session 0, Hazel's in Session 3

Answer: Yes

Hazel can start Dropbox on her desktop, even though Mike’s copy is running in Session 0. Apparently running many copies of Dropbox is fine if they are for different users in different sessions.


Question #3: Can Hazel run her Dropbox in Session 0 with AlwaysUp too?

Recall that Mike’s Dropbox starts at boot with AlwaysUp. Will Hazel be able to start Dropbox in Session 0 too, to synchronize her files 24/7 like Mike?

To find out, we set up a second Dropbox entry in AlwaysUp. This time, we entered Hazel’s account on the Logon tab, to indicate that Dropbox should work on her behalf. You can see both Mike’s and Hazel’s entries here:

Both Mike and Hazel set up Dropbox in AlwaysUp

As pictured, Mike’s Dropbox was already running. We started Hazel’s entry and in a few seconds it transitioned to the “Running” state too:

Dropbox started for Hazel

To validate that both Dropbox instances are working properly for Mike and Hazel, we copied files to the local folders and up to the cloud. The files were quickly synchronized in all cases — for both accounts.

Answer: Yes

Both Mike and Hazel can run Dropbox in Session 0 with AlwaysUp.


As the results above show, there are situations when you can run several copies of Dropbox and times when you cannot. Hopefully there is enough flexibility for you to design a system that works for you and your company.

A word of caution

Please realize that the Dropbox team may change how its program works at any time. For example, while a couple of instances work in Session 0 today, we don’t recall that scenario working in earlier versions of the software.

Fingers crossed!

Posted in AlwaysUp | Tagged , , , , | Leave a comment

Service Protector 8.5: New Sanity Check, Windows 10/11 22H2 Compatibility

Service Protector 8.5: New Sanity Check, Windows 10, 11 22H2 Compatibility

Service Protector 8.5 is now available for download. Here’s what we worked on in this new version:

Automatically restart your service when an important application isn’t running

Does your service depend on an important “helper” application? If so, Service Protector can periodically check if the helper application is running and restart your service if the application isn’t active.

For example, suppose you’re protecting a service that spins off a Java process to perform important image processing. You can now instruct Service Protector to restart your service if no java.exe process is running on your server. In that way, you’re protected if the supporting java process crashes or stops for any reason.

You can activate the new sanity check from the Monitor tab. Start by checking the Whenever it fails a periodic sanity check box:

Activate the sanity check feature

Click the Set button to open the Add Sanity Check window. From there, select Check that an application is running from the list:

Choose the check application running sanity check

In the next screen, enter the name of the executable to watch for. The name must end in .exe.

For example, to watch for a Java process, enter “java.exe”:

Check that java.exe is running

If you don’t know the name of the application’s executable file, run the application and find its entry on the Task Manager’s Details tab. The name will appear in the first column.

After entering the executable name, continue on to the next pages to specify how often Service Protector should check for the application. When done, save your changes.

And that’s it! With the sanity check in place, you can rest assured that your helper application’s “untimely demise” will trigger Service Protector to recycle your service.

The “Check file updated” sanity check now supports date variables

We’ve made several improvements to the sanity check that restarts the service whenever an important file hasn’t been updated in a while. Most notably, date variables can be used in the name of the file to monitor.

This feature is beneficial when checking a log file that “rolls over” each day. Previous releases of Service Protector — which only supported a fixed file name — could not handle a dynamic name.

For example, let’s take the case where your service writes to a new log file each day. The file name contains the date, in the format “myserver-DD-MM-YYYY.log”.

To monitor that log file with the sanity check, you would specify the file name as myserver-$DAY2$-$MONTH2%-$YEAR4$.log:

Using variables in the file update sanity check

And with that in place, when running your service on October 14 2022, Service Protector would check for a file named “myserver-14-10-2022.log”.

Service Protector is fully compatible with Windows 10 & 11 22H2

Service Protector is compatible with Windows 11 22H2

As usual, Microsoft continues to roll out twice-yearly updates to its Windows operating systems.

Windows 10 22H2 will be released to the public in a few days. However, as a member of the Windows Insider program, we’ve been playing with that new version since August.

Similarly, Windows 11 22H2 started rolling out to customers in September. And like Windows 10 22H2, we’ve been evaluating it for over a month now.

Our assessment? Service Protector continues to work flawlessly with both operating systems. In some sense, that is to be expected as Microsoft has left the Windows Services layer untouched.

Other fixes & improvements

  • Fixed a crash when testing a custom sanity check: Thanks to Jacques Dagousset for reporting the problem, which would occur in rare circumstances.

  • Reduced CPU load when scanning for crash dialogs: With recent changes, Service Protector is significantly more efficient when scanning for dialogs that indicate that your service has crashed.

  • Improved logging when running a sanity check: Extra messages provide insight when testing a sanity check (and when debugging subtle problems).

As usual, please review the release notes for the full list of features, fixes and improvements included in Service Protector version 8.5.

Upgrading to Service Protector 8.5

If you purchased Service Protector version 7 (after January 2021), you can upgrade to version 8.5 for free. Simply download and install over your existing installation to preserve your existing services and all settings. For instance, your registration code will continue to work.

If you bought Service Protector version 6 or earlier (before January 2021), you will need to upgrade to use version 8.5. Please buy upgrades here — at a 50% discount.

See the complete upgrade policy for more details.

Enjoy!

Posted in Service Protector | Tagged , , , , | Leave a comment

Q&A: Why did my Windows Service Start Unexpectedly?

Why did my Windows Service Start Unexpectedly?
  I’ve got a Windows Service that keeps starting by itself. Why is that happening? I’m pulling my hair out trying to figure out why…

— Colin P.

Hi Colin.

There may be several culprits here. Let’s go through a few.

1. Your service is required by another service

Does your Windows Service support any other services? Is another service “dependent” on yours?

If so, then starting that other service may start yours too.

This can be a bit confusing so let’s illustrate with an example.

Here we have a service called “Dropbox (managed by AlwaysUpService)” — created with our AlwaysUp product:

Dropbox AlwaysUp Windows Service

We made the Dropbox service dependent on the “Fax” service. Indeed, you can see the relationship on the Dependencies tab:

Dropbox service dependencies

It’s important to note that the dependency stipulates the following situation:

The Fax service must be running before the Dropbox service can start

To test the implications of that relationship, we:

  1. Stopped both the Dropbox and Fax services, and

  2. Started the Dropbox service.

Afterwards, we saw that the Fax service was running:

Fax service: Running

Apparently when we started the Dropbox service, Windows realized that the Fax service was needed and quietly started Fax as well.

So that’s one way for a service to start inadvertently.

With that example in mind, please check if another service depends on your service. If so, Windows may be starting your service because of that dependency relationship.

2. Your service is “trigger started” by Windows

Legacy versions of Windows presented a couple of options for when a service was started:

  1. Automatically — by Windows — when your computer booted;

  2. Manually — by a person or application — when needed.

Windows Vista (2007) introduced a third option: Trigger start. Now, services can be started in response to key operating system events.

And the set of triggering events is varied. For example, a trigger start service can be launched whenever:

  • Someone plugs in a USB drive;

  • Your computer joins a domain;

  • A network port is opened;

  • A custom event (or system state change) occurs.

Trigger start services reveal themselves in the Startup type column of the Services application. As you can see in this screenshot, there are quite a few on our Server 2022 machine:

Trigger start services

This article explains the difference between “Automatic (Trigger Start)” and “Manual (Trigger Start)”.

Is your service configured to trigger start? If so, it may be starting when its associated event fires.

You can use our free Service Trigger Editor utility to investigate the service and the events that trigger it. Removing the trigger may be an effective solution but please be sure to understand the consequences of doing so!

3. Someone is starting your service manually

I don’t know what your service does, but might someone else be starting it to get their work done? You want the service to be idle but perhaps a colleague needs it running!

Is someone else with access to your machine launching the service?

Best to check around and find out.

4. An application running on your PC is starting the service

Some folks say that applications are people, too. 🙂

Well, maybe not, but a program can certainly stop and start a Windows Service — just like a person can.

For example, an application that supports Bluetooth may fire up the Bluetooth Support Service if it’s not running. Indeed, the application likely calls the Windows API (the ControlService function) instead of using the NET or SC commands, but the effect will be the same.

So do you know of a program that needs your service to operate?

If so, you should consider uninstalling the application.

Our recommendation: Investigate with Windows Service Auditor

If you can’t figure out who (or what) is starting your Windows Service, it’s time to get your detective hat on.

Start with the Windows Event Viewer. Do you see the service starting and stopping? Can you tell who’s doing it? Pay attention to the times as they could shed light on the situation.

But if you’re still in the dark, we recommend bringing out the big gun: our free Windows Service Auditor.

Windows Service Auditor

Windows Service Auditor introduces extra logging, to shine a bright light on your Windows Service. For example, here it’s telling us that “Mike Jones” updated the “Windows Update” service today at 10:59 AM:

Windows Service Auditor Event

Hopefully you’ll solve the mystery soon.

Good luck!

Posted in Windows Services | Tagged , , , , , , | Leave a comment