Windows Service Validation Check to Inhibit Service Start

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
sereini
Posts: 1
Joined: Sun May 24, 2020 7:32 am

Windows Service Validation Check to Inhibit Service Start

Post by sereini »

Hello,

I've been playing a bit with this and overall get how it works and have created/installed a basic service without issue:

https://www.sapien.com/blog/2017/07/12/ ... owershell/

I'm sure I'm just missing something but I'm trying to prevent the service from starting should something like a file/directory/reg key not be present. As as an example, one thing I've tried is this:

if (-Not (Test-Path "C:\ValidationFolder")) {Exit}

But I've also tried triggering the function Stop-MyService, creating my own functions, inserting code like the above within, etc.

I'm running PrimalScript 2019 v7.4.125.0

Thx!

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Windows Service Validation Check to Inhibit Service Start

Post by jvierra »

Just make you checks in "Service-MyService" and don't set the bServiceRunning flag so the service will nver enter the run loop.
Why is that an issue?

Locked