Packaging as Service: Findings

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 6 years and 7 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.
User avatar
CermakPOI
Posts: 41
Last visit: Wed Jan 31, 2024 2:57 am

Packaging as Service: Findings

Post 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>
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Packaging as Service: Findings

Post 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).
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
CermakPOI
Posts: 41
Last visit: Wed Jan 31, 2024 2:57 am

Re: Packaging as Service: Findings

Post 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.
Attachments
03-08-2017 08-33-25.png
03-08-2017 08-33-25.png (5.76 KiB) Viewed 1805 times
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Packaging as Service: Findings

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 6 years and 7 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.