Page 1 of 1

Packaging as Service: Findings

Posted: Fri Jul 28, 2017 3:53 am
by CermakPOI
Product, version and build: PowerShell Studio 2017 v5.4.142
32 or 64 bit version of product:64
Operating system: Win 10
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

How can i react within the script to the Service Stop event?



Write-Host, Write-Error and Write-Warning and so on are transformed to Eventlog entries in the Application Log where the source is the Service Name. This i convinient, but i found a glitch.

The error is that thrown Errors are directed to the eventlog as separate entries. For example each of this lines is a separate Eventlog Line!

Code: Select all

+ Main ($CommandLine)
At line:102 char:1
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Main
<emtpy Line>

Re: Packaging as Service: Findings

Posted: Fri Jul 28, 2017 4:25 am
by Alexander Riedel
At the moment you cannot react to a stop event. Such an event it not passed to the script at this time.
The way PowerShell outputs error messages to the hosting object makes it appear as separate lines.
Since we cannot control the error output of the PowerShell engine there is little we can do. But I'll make a note to check.
It is best to debug and harden your script before packaging it as a service. Make sure you capture exceptions and output the appropriate message yourself using Write-Host (Write-Output will output each line separately).

Re: Packaging as Service: Findings

Posted: Wed Aug 02, 2017 11:37 pm
by CermakPOI
When i try to sign the Script the signing assistent fails if it's one of the new Script Engine Types: Windows Service or Windows Application.

When i change to an "old" like Forms or Commandline it works ususual.

Sorry, i only have a german Screenshot.

Re: Packaging as Service: Findings

Posted: Thu Aug 03, 2017 12:53 am
by Alexander Riedel
No worries, I can read German, The cause for this is that the raw script engine is already signed. The installer tool we use automatically signs executables unless you turn it off and that step was missed. An update for this has already been published.