Lazymans Windows-respawn of services

So in short; I have a ‘service’ (ie, a process that needs to run in a specific user context and is not a Windows Service(TM) ). How’s that done? Well, the imperfect and stupid way is described below.

The ingredients for Windows 7/8/10 “Pro”

  • User Accounts
  • SysInternals toolkit
  • Batch-scripts
  • Patience
  • Windows Task Scheduler

Determine how many accounts you will need. This will help you do this over and over again…
I would recommend that you have one account per “service” or such. I the example we will do this for one “service”, running under one account.

Download sysinternals toolkit. We will need it… (yes, grab all the stuffs, it’s useful for ya in the future anyways. Source can be found with a search-engine – hint – it’s now owned by Microsoft. Place the binaries in a good location, like… something:\tools or a PATH that is already defined in your user context.

Batch-scripts, or something else that can do what you’ve typed.
I recommend that you look up a few settings for the command “start”, for instance setting the affinity and the priority for the command to be executed (example; start /affinity 4 /AboveNormal /B server\Wreckfest.exe -s server_config=serverconfig.cfg )

So, scripts you need to create;


Start-script
Recommended parts above. This is what we can call to under the correct user context start the said “process”.


Stop-OR-KILL-script
For this, we need the lovely sysinternals toolchest. the executable we are gonna make sweet love too is pskill64.exe (I assume you’re on 64bit..). Script will need to contain:
pskill64.exe <Process ID | name>.

So how does that work? Well – for instance in the start example, the process will have the name of “Wreckfest.exe”, so “pskill64.exe Wreckfest.exe” will kill all processes named just that.
WAIT! That does not compute!

True, it’s a dirty and odd way to just go processname – but if your application or rather the binary you start is renamed – so can the pskill-command be shifted to actually terminate that specific process. So, make copies, rename binaries and make this work for you. Onwards!

Great. Now we can with a script start, and also KILL a process. Now we need the patience, and thats with the windows task scheduler.

WAIT! This is like I said the patience part – make sure that the task scheduler is set under the correct user context, ie running as the correct user. Windows is blindly stupid in how things are executed and also how normal console output is handled. This means, that if you have an application that’s so stupid that it respawns the command (like normal windows behaviour) – this means that to be able to interact with it later, you need to logon into that user context, start it, and then you can disconnect, and redo the step..
But in short, logon as the actual user that will run all this, and go ahead.

Pop open that lovely start menu.
type in task scheduler, and alas

Pop it open – and create a new folder (for sanity’s sake..)

Now, jump into that, and create a basic task;

Name it if you want, indicate the action;

Now, select the trigger – here comes the patience..

In short – I would recommend the following simple scenario;
We kill something daily, we start something daily – Death before Birth mate…
In this example, lets start with Death, Daily, at 6 in the morning;

Yes – we wanna start a program –

Now, we need to tell this bastard where to do stuff

IT IS REALLY IMPORTANT THAT YOU ADD THE START IN PORTION – IT IS NOT OPTIONAL….

Finish it, and redo this – but do the start batch-file instead- START IT AFTER THE KILL!

Enjoy.. This is an old-timers confused way to interact with Microsoft’s operating system..

Leave a comment

Message after the beep

This site uses Akismet to reduce spam. Learn how your comment data is processed.