Automatic conditional start/stop Windows service?
My computer runs a CCTV monitoring software, when it is monitoring all 5 cameras, it uses around 30% CPU.
When I play CPU intensive games, that 30% makes the difference between smooth and not so smooth.
I tried making a schedule in the CCTV monitoring program to cut down to 2 cameras during the hours that I am home, but it still uses too much processing power.
Right now, I use "net stop servicename" in CMD before and after playing a game. I don't mind the service being off for the odd hour or so that I play. I might miss someone coming to my door or whatever, but nothing major.
However, I still want it to run when I am not playing games, so I have to remember to restart the service, which has already happened that I forgot.
I can write a batch script that would run in a loop 24/7, but I wonder if there isn't a more graceful way to automate the process.
Note - I tried setting the service in low priority mode, but it still took away enough processing power to make a difference.
///////////////////////////////////////////////////////
UPDATE --------- SOLUTION FOUND
//////////////////////////////////////////////////////
Ok, so for the sake of future people googling for answers, here is my solution.
I used Eventghost (google it) to detect the start/stop of my game (The log will show "create" and "terminated" events with the .exe name)
Without any special configuration, Eventghost already logs the activation and deactivation of any program.
You can tell Eventghost to do something when it detects a specific log event.
Now, in most situations, you can just tell Eventghost to run a command line, however, in my case, I needed Eventghost to run the command with administrative priviledges.
So I followed this guide
http://www.sevenforums.com/tutorials/11 ... reate.html
In my case, I wanted to stop the service named "blueiris" when the game started, and restart the service when I quit the game.
Step 3: I named the event as "gamestart"
Step 8: I replaced their example [ /c start "CCleaner" "C:\Program Files\CCleaner\CCleaner64.exe" ] with: /c start "gamestart" "%windir%\system32\net.exe stop blueiris]
I repeated step 1-12 to create a second event named "gamestop" and used the command line: /c start "gamestart" "%windir%\system32\net.exe start blueiris
I stopped the guide at step 12 because I didn't need to create a desktop shortcut.
Instead, I went in eventghost and told it to run a command based on whether it dedected the game lauching, or the game stopping.
So, when eventghost detects the game launching, it will run the command: schtasks /run /tn "gamestart"
When the game starts, it will run the command: schtasks /run /tn "gamestop"
It's complicated, but now that I learned to do this, I can see many other applications to this technique.
Anyway, I was already using Eventghost for years to send commands from my IR USB remote directly to KODI.
When I play CPU intensive games, that 30% makes the difference between smooth and not so smooth.
I tried making a schedule in the CCTV monitoring program to cut down to 2 cameras during the hours that I am home, but it still uses too much processing power.
Right now, I use "net stop servicename" in CMD before and after playing a game. I don't mind the service being off for the odd hour or so that I play. I might miss someone coming to my door or whatever, but nothing major.
However, I still want it to run when I am not playing games, so I have to remember to restart the service, which has already happened that I forgot.
I can write a batch script that would run in a loop 24/7, but I wonder if there isn't a more graceful way to automate the process.
Note - I tried setting the service in low priority mode, but it still took away enough processing power to make a difference.
///////////////////////////////////////////////////////
UPDATE --------- SOLUTION FOUND
//////////////////////////////////////////////////////
Ok, so for the sake of future people googling for answers, here is my solution.
I used Eventghost (google it) to detect the start/stop of my game (The log will show "create" and "terminated" events with the .exe name)
Without any special configuration, Eventghost already logs the activation and deactivation of any program.
You can tell Eventghost to do something when it detects a specific log event.
Now, in most situations, you can just tell Eventghost to run a command line, however, in my case, I needed Eventghost to run the command with administrative priviledges.
So I followed this guide
http://www.sevenforums.com/tutorials/11 ... reate.html
In my case, I wanted to stop the service named "blueiris" when the game started, and restart the service when I quit the game.
Step 3: I named the event as "gamestart"
Step 8: I replaced their example [ /c start "CCleaner" "C:\Program Files\CCleaner\CCleaner64.exe" ] with: /c start "gamestart" "%windir%\system32\net.exe stop blueiris]
I repeated step 1-12 to create a second event named "gamestop" and used the command line: /c start "gamestart" "%windir%\system32\net.exe start blueiris
I stopped the guide at step 12 because I didn't need to create a desktop shortcut.
Instead, I went in eventghost and told it to run a command based on whether it dedected the game lauching, or the game stopping.
So, when eventghost detects the game launching, it will run the command: schtasks /run /tn "gamestart"
When the game starts, it will run the command: schtasks /run /tn "gamestop"
It's complicated, but now that I learned to do this, I can see many other applications to this technique.
Anyway, I was already using Eventghost for years to send commands from my IR USB remote directly to KODI.