The Core Technologies Blog
Our Software // Windows Services // 24×7 Operation
Hello, I’m testing your Service Protector program and I was wondering if it starts automatically when my server reboots? I didn’t notice an option for that. I have my server restart every night, will this be an issue with the trial version?
Hi James. Yes, Service Protector will automatically start to protect your service whenever your server reboots. Restarting your server every night will not pose a problem.
You can’t find an option to automatically restart because there isn’t one! That functionality is built in. And the desktop application you run to setup your windows service will not start because it doesn’t need to. Confused? Let me explain…
You see, Service Protector has a couple of parts:
The desktop application you run to configure your windows services
When you install Service Protector, a convenient shortcut will be created on your desktop:
Double-clicking that shortcut will launch Service Protector:
But this application is merely a management utility, a “waiter/waitress” in the restaurant.
You use this management utility to:
- choose the windows service you wish to keep running 24/7
- specify the options for monitoring the service
- view daily and weekly performance reports, and more
This GUI utility does not monitor your services (or do any cooking, if we keep the restaurant analogy going). Therefore it does not need to start when your computer boots. You run it on demand, whenever you need to interact with Service Protector.
An invisible/background component that babysits each of your windows services
Whenever you setup a service to be monitored (like the Print Spooler in the screenshot above), a background program is deployed to do the work. That program is completely invisible and the only way to see it is by using the Windows Task Manager (or a relative, like the excellent Process Explorer).
Look for ServiceProtectorAgent.exe. Here it is watching the Print Spooler on Windows Server 2016:
Note that this component is itself a windows service! If your service is named “Spooler”, you will find a new service called “ServiceProtector: Spooler” on your machine:
The service’s startup type will be “Automatic”, to ensure that the Agent starts as soon as your machine boots. You never have to start it yourself.
So to complete the analogy, this background component is the restaurant chef — busy in the kitchen cooking the meals submitted by the waiter/waitress.
Hopefully it makes sense now! Please let us know if not. But the bottom line is that we’ve got you covered.
We have installed AlwaysUp version 18.104.22.168 (Sep. 2 2016) on Windows Server 2012 R2 Standard. We have multiple jobs that run a 64-bit .NET Console Application as a windows service, but we keep getting a SystemOutMemoryException error. What we found watching the Task Manager is that the EXE always runs as 32-bit. How do we get AlwaysUp to run the console app as 64-bit?
Hi Clayton. There are a couple of ways to force your .NET application to run in 64-bit mode:
Build a 64-Bit .NET Version
If you use Microsoft’s Visual Studio, the build configuration is likely be set to Any CPU (the default):
This will produce an executable that will run in either 32-bit or 64-bit mode, depending on the version of .NET available.
To run your executable in 64-bit only, change the configuration to x64 and rebuild.
If your project doesn’t have a x64 configuration, create one like this:
Select Build > Configuration Manager…
In the Configuration Manager,
click the Active solution platform entry and select <New> from the menu that appears:
In the New Solution Platform window, choose x64 in the top box. We recommend copying settings from Any CPU and creating new project platforms (the default):
Click the OK button to record your changes. Close the Configuration Manager
You should now have x64 as a build option. Set it and recompile to produce a 64-bit only executable:
Use CorFlags to Force .NET 64-Bit
If your application is built with “Any CPU” but you can’t rebuild it in Visual Studio, Microsoft’s free CorFlags utility will come to the rescue.
Corflags.exe is distributed with the Windows 10 SDK. Be sure to select the “.NET Development Tools” component when installing.
We actually found the CorFlags exe file in a couple of places on our hard drive:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\Corflags.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\Corflags.exe
You may find CorFlags in older .NET SDK installations as well — it has been around since the release of .NET 2.0 (2005).
Once you have located CorFlags:
Make a copy of the executable you want to run in 64-bit. The application we used for testing is called SystemInfoDotNet.exe, so we copied it to SystemInfoDotNet64.exe.
Open a command prompt with admin rights.
CD to the folder containing the copied application.
Run CorFlags on the copied application file. Specify the /32BIT- option to strip away the ability to run in 32-bit mode:
The copied executable will always run in 64-bit mode.
For example, our SystemInfoDotNet utility — which displays basic process and system information — normally runs in 32-bit mode:
But after running CorFlags on SystemInfoDotNet64, it magically runs in 64-bit mode:
Best of luck with your .NET application Clayton!
Occasionally the application we’re running as a service stops responding, resulting in AlwaysUp restarting it. We would like to run a script prior to the restart to try to generate a crash-dump file so we can find out where the problem is. Is that possible?
— Kelly @ Sabre
Hi Kelly. Sorry to hear of the trouble! Please follow these steps to automatically generate a crash dump whenever your application terminates:
Download & install Microsoft’s free ProcDump utility
ProcDump — yet another excellent utility from the Sysinternals team — easily creates a dump file from any running process. It is our tool of choice when exploring application crashes.
Download the ProcDump .Zip package and extract all files to a convenient location. We have placed the files in “C:\Apps\ProcDump” for this article.
Be sure to run ProcDump at least once and accept the Sysinternals EULA. We don’t want the utility to hang when we run it unattended as a background service!
Compose the command line to capture a crash dump when your application stops
ProcDump features an impressive set of command line options. Please review and identify the flags that work best for your situation.
For example, we use this command to dump the notepad.exe application whenever it stops running:
c:\Apps\ProcDump\procdump.exe -t notepad
Please ensure that this command works as expected. Start your application, run the command and then terminate your application. Is a dump file created? Troubleshot and fix if not.
Setup your ProcDump command as a Windows Service in AlwaysUp
Your application is running 24×7. To configure ProcDump to operate on the same schedule and capture the dump file at any time:
Start AlwaysUp and select Application > Add… to bring up the Add Application window.
On the General tab:
In the Name field, enter a suitable name for this new service. We have used “ProcDump Notepad”.
In the Application field, enter the full path to ProcDump.exe.
In the Arguments field, provide the command line options you developed in step 2. Be sure to add the -w flag, which will cause ProcDump to wait for your app to launch if necessary.
And in the Start in directory field, enter the folder where you want the dump files to be written. (Leaving this blank will cause dump files to be created in the ProcDump folder.)
On the Logon tab, specify your windows account. ProcDump should run in this account since you know it works there (and that the EULA has been accepted).
Click the Save >> button to record the ProcDump service.
And finally, start your new service (from the Application menu).
Here is what the finished setup looks like for us, with Notepad running as a service and ProcDump monitoring it (also as a service):
Now that everything is in place, you should confirm that a crash dump will be created whenever your application stops.
Open the Task Manager and kill your application. Does a new dump file appear in the expected location? If not, please review all the steps and ensure that nothing was missed.
Best of luck debugging your program!
Wanted to know if there’s a way for Service Protector to not monitor a service during a patching period of time? Or any scheduled period of time without sending a million alerts?
— Mark @ Red Roof Inns
Hi Mark. Apologies for the barrage of unnecessary emails! Unfortunately Service Protector doesn’t know that it is OK for your service to be down while you are patching. It is diligently doing its job.
To avoid the false alarms, we recommend shutting down Service Protector at the start of your maintenance window and reactivating it once patching has concluded. These operations can be performed from the Service Protector GUI or with the standard Windows NET command.
You see, Service Protector creates a Windows Service for each service it monitors. If your service is named “MyService”, then Service Protector creates a service called “ServiceProtector: MyService” to watch your target service. Here is what it looks like for the “Print Spooler” service on our Windows Server 2016 machine:
Note that the service name may not be the same as the friendly “display name” you see in Service Protector (and Services.msc). For example, the service name of the “Print Spooler” service is actually “Spooler”:
This post shows how to find the service name.
How to Stop Protection at the Start of Maintenance
Stopping From the GUI
Select Stop <ServiceName> from the Protector menu. This will shut down Service Protector but will leave your target service running:
Stopping From the Command Line
This command will stop the instance of Service Protector monitoring a service named “MyService”:
NET STOP “ServiceProtector: MyService”
Here is what the process looks like for the Spooler service:
Simply run the NET STOP command before patching starts.
How to Restart Protection at the End of Maintenance
Starting From the GUI
Select Start <ServiceName> from the Protector menu. This will fire up Service Protector — and your target service if it’s idle:
Starting From the Command Line
A slightly different version of the NET command will restart the instance of Service Protector monitoring a service named “MyService”:
NET START “ServiceProtector: MyService”
Restarting protection for the Spooler service looks like this:
Run the NET START command once your system is back to normal.
How to Stop and Restart Service Protection Automatically
For patching that occurs at a defined time, we recommend using the Windows Task Scheduler to automate the process. Create a pair of scheduled tasks — one to stop protection and the other to restart it.
For example, if maintenance occurs every Saturdays from 1 AM to 3 AM, your first scheduled task could run NET STOP at 12:59 AM. The second task could be configured to run NET START at 3:01 AM.
Sorry to hear that you are having a problem running your application with AlwaysUp! Windows services can be tricky beasts but our team of experts has spent many years wrestling them into submission. Rest assured that we will do our best to get you up and running ASAP.
As with most technical problems, the devils are in the details. Please answer these five questions to help us diagnose the problem:
What application are you installing as a Windows Service?
AlwaysUp runs thousands of programs, batch files and scripts, but each one brings its own unique challenges. Which one are you trying to run as a service? Is it publicly available? And what does it do?
What version of AlwaysUp are you running?
Each version of AlwaysUp is different. Knowing which build of the software you have installed enables us to offer you the best advice and the most helpful solutions.
To find the version number, start AlwaysUp and select About AlwaysUp… from the Help menu. The 4-digit version number is displayed in the window that appears.
Here you can see that we have 10.4.2.47 installed:
What version of Windows are you running?
The version of Windows installed on your PC can definitely impact your software’s ability to run as a background service. For example, Windows 10 might prevent you from interacting with your application, while older, less secure editions of Windows often behave very differently than their modern counterparts.
Run the helpful winver command to confirm the operating system you are running. A window like this should pop up to report the details:
This article from Microsoft support describes a few other ways to find your Windows version.
How have you configured your application in AlwaysUp?
AlwaysUp offers over practical 40 settings to run your program securely as a Windows Service. Some applications run perfectly with only the basic settings applied while others need fine tuning to operate smoothly. We recommend that you send us what you have so far, for review.
To export your application’s settings to a XML file:
Highlight your application in AlwaysUp
Select Export… from the Application menu (shown here for Google Backup and Sync):
Save the XML file in a friendly location.
We’ll take a look and let you know if we see anything fishy!
Are any errors reported in the AlwaysUp Activity Logs?
AlwaysUp writes errors and warnings to the Windows Event Logs — the recommended destination for notifications and alerts from Windows Services. While you can use the Windows Event Viewer to browse recent log entries, it is much easier to see that activity from AlwaysUp:
Highlight your application in AlwaysUp
Select Report Activity > Past Week… from the Application menu:
In a few seconds, your web browser will pop up with a page showing when your application/service was started, stopped, etc.:
Please save the web page (Ctrl+S) or take a screenshot of the browser window and send it to us for review.
Send us these details and we’ll get back to you very soon
These five items should give us an excellent understanding of what is going wrong. Please email your specifics to support@CoreTechnologies.com and we will review and respond promptly — usually within a few hours.
My company uses AlwaysUp CLT to run our script every 5 minutes as a windows service. The script starts running when the PC boots and repeats every 5 minutes throughout the day. It usually takes a few seconds to do its work on each run.
However we have a nagging problem. After some hundred or more cycles, the script occasionally gets stuck and never finishes! When this happens, my customers get upset because their kiosks aren’t updated.
How can I get AlwaysUp to kill the script and restart it whenever it hangs?
— Dan @ LaptopsAnytime
Hi Dan. I’m not sure what your script does, but it is very unlikely that AlwaysUp will be able to tell that the script isn’t working properly. However we can use AlwaysUp’s powerful Sanity Check feature to terminate (and restart) your script when it runs for too long.
To setup the sanity check with the AlwaysUp GUI (we’ll cover the CLT later):
Create a new batch file with a single command: exit 1
Save the batch file to a convenient location on your file system. We have saved ours to “C:\Scripts\hung-sanity-check.bat”. Note the full path to the new file as we’ll need it in a later step.
Start AlwaysUp. Highlight your application and select Application > Edit… to summon the “Edit/View Application” window.
Switch to the Monitor tab. Check the Whenever it fails a sanity check box and click the … button:
In the “Configure Sanity Check” window that comes up:
In the Run section, enter the full path to the batch file you created in the first step.
Using the Every controls, specify a time that you consider “too long” for your script to run. Since your script usually takes a few seconds to run, we recommend entering 2 minutes. That should give an unusually long run some extra time to complete, while ensuring that your customers never experience an outage lasting longer than a couple of minutes.
Also, specify 2 minutes in the Wait for setting and check the Also wait whenever the application is restarted box. These ensure that your script will have time to complete before performing the first sanity check:
Click the OK button and save your settings in AlwaysUp.
With the sanity check monitor in place, your script should never hang for longer than two minutes.
Command line switches for AlwaysUp CLT
To achieve the setup described above with AlwaysUp CLT, specify the following parameters to InstallService:
For example, our InstallService command line looked like this:
InstallService.exe “MyMainScript” “c:\Scripts\MyMainScript.bat” -k -m -t “C:\Scripts\hung-sanity-check.bat” -a 120 -xd 2 -xr -rn -f 3 0 -fd 5 1
For a full description of these and other command line flags, please see the “Customized Sanity Checks” section (page 12) in the AlwaysUp CLT User Manual.
You may also consider setting up email alerts — to inform you when your script had to be forcibly restarted. A timely notification may help you to diagnose and ultimately fix the underlying problem with your temperamental script. Until then, rest assured that AlwaysUp has you covered!
Windows 10 and Windows Server 2016 contain a curious problem affecting interactive windows services. When you switch to Session 0, you cannot use the keyboard and mouse. This frustrating flaw makes it impossible to interact with any window displayed in Session 0. You can’t even click the “Return Now” button to go back to your regular desktop!
Hopefully Microsoft will fix this bug soon. But if you are using RDP to connect to the server running AlwaysUp, you can use the free and reliable VNC software instead, to resume normal operation in Session 0.
What is VNC?
VNC (which stands for Virtual Network Computing) is a cross-platform technology facilitating remote desktop sharing and control. It is very similar to Microsoft’s RDP. With VNC, you install a software component on the machine you wish to view/control (“the server”) and run another component installed on your local computer (“the client”) to access the server’s desktop.
Which version of VNC should I use?
Several implementations of VNC are available for Windows. We have used (and can recommend) RealVNC, UltraVNC and TightVNC, but this article will focus on TightVNC because it is:
- actively maintained
- free for both personal and commercial use
- fully supported on Server operating systems
- already installed and in daily use on our Windows Server 2016 QA/test server!
Note however that TightVNC does not currently encrypt desktop traffic. Look to UltraVNC or RealVNC Professional Edition if that is an important consideration.
How to Use TightVNC to Access Session 0 Remotely
Download TightVNC for Windows
Grab the latest 64-bit or 32-bit installer from the TightVNC download page. It will only be a couple of megabytes large.
We will run the installer on both the server and client machines.
Install TightVNC on the Remote Server
Run the installer on your server (the computer running AlwaysUp):
Accept the terms and click Next. When you get to the Choose Setup Type screen, click the Custom button:
On the Custom Setup Type screen, configure the tree so that TightVNC Server will be installed. We decided to omit the TightVNC Viewer since we have no need for that component on the server:
Click Next to continue.
We recommend sticking with the defaults on the Select Additional Tasks screen. It is best to run VNC as a windows/system service so that it starts promptly after a reboot, without anyone having to log in first:
The rest of the installation process should be straightforward so please proceed with your good judgment. Be sure to set strong passwords when you get to the Set Passwords step!
After installing, TightVNC Server will be running in the background as a windows service (and will start automatically when your server boots). Check it out in Services.msc:
Install TightVNC on the Client
Launch the installer to your client computer — most likely your PC with the physical keyboard and mouse attached.
When you get to the Choose Setup Type screen, once again click the Custom button:
On the Custom Setup Type screen, configure the tree so that only TightVNC Viewer will be installed:
Click Next to continue.
Again, the defaults on the Select Additional Tasks screen are probably fine:
Follow the remaining prompts to complete the installation.
TightVNC Viewer will be available in the C:\Program Files\TightVNC folder. You may want to place a shortcut to the viewer application (tvnviewer.exe) on your desktop for convenience.
Run the Viewer to Connect to the Server & Switch to Session 0
Start the Viewer application (C:\Program Files\TightVNC\tvnviewer.exe) on your client PC. Type in the host name (or IP address) of the server and click the Connect button:
Next, enter the password you specified for the server (in step 2e) and click OK:
A window showing your server’s desktop will appear. Click the Ctrl+Alt+Del button on the toolbar to sign in to Windows:
Once you are in, switch to Session 0 — either from the Tools menu in AlwaysUp, or via our free Switch to Session 0 utility. You will be able to use your keyboard and mouse!
Here is our Windows Server 2016 machine with both winver.exe and Notepad running in Session 0:
Caveat: Not a solution for one computer
Using the VNC remote access software won’t work if you only have a single computer setup. VNC cannot view itself — not without incurring the wrath of infinity. For the single computer scenario, you have to wait for the folks in Redmond to wave their magic wand and fix the bug…
Why do I see the “Interactive Services Detection” window?
The Interactive Services Detection (ISD) window appears whenever a Windows Service running on your computer is showing a window or prompt in Session 0 — a “background desktop” created when your computer boots. The ISD window allows you to switch to Session 0 where you can see the window and take action.
The next section explains the situation in greater detail; read on to find out more. You can also skip directly to the 3 solutions if you are short on time and just want to get rid of the dreaded ISD window.
Window services run in Session 0. On legacy versions of Windows (NT, XP and 2003), the first person to log into the PC was placed in Session 0 — where all the windows, alerts, tray icons and other user interface elements created by services were visible. Thus a service could easily interact with that first user.
But Microsoft changed the playing field in Windows Vista (circa 2007). Citing security concerns, Session 0 was isolated and logging in to Session 0 was strictly forbidden. Suddenly it was impossible for a Windows Service running in Session 0 to interact with users, who were strictly working in Session 1, 2, etc. This behavior holds true for Windows 7, 8, 10 and Server 2008, 2012 and 2016.
However isolating Session 0 introduced a problem. Services that show a window — requiring someone to click a button or enter a password to proceed — were suddenly rendered “invisible”. How do you know that a windows service application needs your input when you can’t see it?
The Interactive Services Detection windows service was introduced to address the invisibility problem. Whenever a window is showing in Session 0, the service will summon the ISD window to warn you and allow you to switch to Session 0.
Working with the Interactive Services Detection window
The ISD starts out by flashing on the taskbar:
It you activate the window and click Show program details, the bottom of the window expands to reveal information on the program trying to get your attention. Here we see that it is the standard Notepad application running in Session 0 (launched as a windows service by AlwaysUp):
Clicking View the message will transport you to the austere Session 0 desktop where you will see the window that may be trying to get your attention:
Clicking Ask me later will dismiss the ISD window but only for 5-10 minutes. Read on and learn three ways to dispatch the window permanently!
Solution #1: Tell AlwaysUp to hide your application’s windows
If you never need to see your program’s windows, then you should have AlwaysUp suppress the windows and avoid triggering the ISD system. Simply edit your application in AlwaysUp and check the When a user logs on, don’t show the application’s windows and tray icon (if any) box on the Logon tab:
Tip: This is the best option for legacy applications, scripts and batch files which occasionally throw up command/status windows. You can always capture console output to a log file if necessary (via controls on the Extras tab).
Solution #2: Disable the Interactive Services Detection Service
If you never want to see Session 0, then your best option is to do away with interactive services detection altogether. To prevent the service from starting:
Open the Services Control Panel Application (services.msc)
Find the Interactive Services Detection service; double-click it to open its properties
Set the Startup type value to Disabled
Click OK to save your changes.
Tip: AlwaysUp will NOT be able to switch to session 0 when the ISD is disabled. Our free Switch to Session 0 utility will not work either.
Solution #3: Set the Interactive Services Detection Service to start manually
If you occasionally inspect Session 0, disabling it will be inconvenient. Instead, set the ISD service to start manually and launch it whenever you want to see Session 0:
Open the Services Control Panel Application (services.msc)
Find the Interactive Services Detection service; double-click it to open its properties
Set the Startup type value to Manual
Click OK to save your changes.
Tip: You will be able to switch to Session 0 from AlwaysUp as normal. AlwaysUp will start the ISD service whenever you switch and will stop the service when you return to your normal desktop.
Hopefully one of these three methods works well for your situation. If not, please get in touch and we’ll do our best to help!
I have a 10 installations of AlwaysUp in my company that are running Dropbox as a service. Is there a way I can surface the Dropbox icon in the taskbar whilst it is running underneath AlwaysUp? I need to make some preference changes and of course when configuring Dropbox to run underneath AlwaysUp we can’t see the task tray icon!
— Matt @ Triaster Ltd
Hi Matt. When Dropbox is running as a windows service with AlwaysUp, you won’t see its familiar task tray icon () on your desktop. This is because Dropbox is operating in the background, on the isolated Session 0. And because Session 0 does not contain a task bar, you won’t see the tray icon even if if you switch to Session 0.
Fortunately you have a couple of options to reveal the tray icon and gain access to the Preferences window:
1. Stop Dropbox in AlwaysUp and start it normally
The first option is to simply stop Dropbox under AlwaysUp and fire it up as you would normally on your desktop (by double-clicking on its desktop icon).
Once you are done making changes to your settings, exit Dropbox from the tray icon and start it as a service under AlwaysUp again (Application > Start “Dropbox”).
2. Restart Dropbox on your desktop from AlwaysUp
For the second option, you can stop Dropbox running in the background (Session 0) and restart it on your desktop/session — all from AlwaysUp. To do this,
highlight the entry in AlwaysUp and select Application > Restart “Dropbox” in this session:
In a few seconds, Dropbox will magically appear on your desktop. Click on the tray icon and then click the gear image in the upper right to summon the Preferences window:
When you are done making changes, switch back to AlwaysUp and choose Application > Restart “Dropbox” from the menu. This will stop Dropbox on your desktop and return it to Session 0 (the home for all windows services).
Not only for Dropbox…
Note that both options above will work for almost any program that displays a tray icon or window! We recommend the same procedures when managing common GUI applications as services, including OneDrive, VirtualBox, Box Sync and Outlook 2010.
If you have a question about Windows Services, 24×7 operation, or any of our products, please don’t hesitate to get in touch. We’ll do our best to provide a timely and informative answer!