Enabling/Disabling a Service w/a Program?

WheatleyWheatley Registered Users Posts: 1 ■□□□□□□□□□
Hi there, I'm a new person seeking out an answer for a problem I'm having.

There is a process/service that is always running (EasyRedirect), from Windows Boot to the end of the day. It really only needs to be running when I open up the application that uses it (Easy-Hide-IP).

I've looked all over the internet for a working .BAT file that would effectively enable the service only when the application is running, and disable it when the application closes.

The closest thing I've gotten to is:
[COLOR=#333333][FONT=Arial]@ECHO OFF[/FONT][/COLOR][COLOR=#333333][FONT=Arial]::enable EasyRedirect[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]net start EasyRedirect[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]::run Easy-Hide-IP[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]call "C:\Program Files (x86)\Easy-Hide-IP\easy-hide-ip.exe"[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]::disable EasyRedirect[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]net stop Easy Redirect[/FONT][/COLOR]
[COLOR=#333333][FONT=Arial]Saved as "Easy-Hide-IP.bat"[/FONT][/COLOR]

When I try to run it, the box comes up, but says Access Denied.

When I run it as an Administrator, it says that it's starting, but the box closes and nothing happens; EasyRedirect continues to run. The only way I can stop it is going into Services and setting it as Disabled and clicking Apply before it has a chance to start up again. Setting it to anything else, and stopping it, does nothing as it starts right back up again.

Any idea as to how to solve this issue?

Thank you!

Comments

  • SlowhandSlowhand Mod Posts: 5,161 Mod
    What you're going to want to use as an easy fix is PowerShell. You can use the Start-Service and Stop-Service cmdlets to manipulate the EasyRedirect service:

    Start-Service -ServiceName EasyRedirect
    Stop-Service -ServiceName EasyRedirect

    It would be easy enough to create a script that starts the Easy-Hide-IP program after starting the EasyRedirect service. As for automatically shutting off the service when you shut down the program, that's another matter. Although, I suppose you could have your batch file run the PowerShell script to start the service, then launch the program, and then shut down the service. As long as your program was launched by the batch file and is open, the batch file will sit and wait to finish executing until that application is shut down.

    Free Microsoft Training: Microsoft Learn
    Free PowerShell Resources: Top PowerShell Blogs
    Free DevOps/Azure Resources: Visual Studio Dev Essentials

    Let it never be said that I didn't do the very least I could do.
Sign In or Register to comment.