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.
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
sereini
Posts: 1
Last visit: Wed May 27, 2020 12:21 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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?
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked