0

I have a PowerShell script contained within a EXE which is installed as a Windows Service. When I try to use SCM to Start the service, it begins the process of starting the service but doesn't complete and SCM reports the service is not running. However, the EXE is started and is running properly in the background.

I do the following to install the service

try{New-Service -Name "Prob Service" -BinaryPathName "C:\AWCOProbe\Probe.exe" -DisplayName "Probe Service" -StartupType Automatic -Description "Probe"; WriteLogI "Installing Service"}catch{WriteLogI "Unable to Install Service"; $installerror = 1}

The Probe.exe is just running a simple loop with no foreground window. The log file it updates is showing that the app is running in the background OK.

How can I get SCM to be able to start and stop the service properly?

SCM will hang around on this screen for a while and Task manager shows Probe.exe:

scm hanging

Then SCM will show this error and Taskmanager no longer shows Probe.exe but it is running under Windows Powershell:

error and task manager

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 2
    Was the exe actually built as a Service? - you cannot use any old exe as a service out of the box, if you try to you will get the "did not respond" error as the SCM can't find ServiceMain(). See http://stackoverflow.com/questions/3582108/create-windows-service-from-executable – Alex K. Apr 25 '17 at 10:35
  • 1
    The EXE file you have is just a 'wrapper' for the the script that is inside it. The ps1 file is extracted and runs via PowerShell in the normal way, just in the background. I'd be amazed if it ever functions correctly as a Service. You should use Scheduled Task to run the script instead. – henrycarteruk Apr 25 '17 at 10:35
  • Thanks @AlexK seems to be correct - I shall adjust my expectations! – Daniel Ziegler Apr 25 '17 at 12:12

0 Answers0