Product, version and build: PrimalScript 2020, Version 7.7.142
Operating system: Windows 10 Enterprise
PowerShell version: v5
32 or 64 bit OS: 64 Bit
Hi, I am all googled out and am seeking help/advice.
I have a PS script that will monitor a folder for new files, this works fine.
I wish to turn it into a Windows Service and am using the PrimalScript 2020 PowerShell Service template. I want to be able to use this anywhere so have opted for the script to bring in data on start from an xml file, this is where I am lost. Below is some of my script that shows the start parameter but the service when starting does not recognise it as I receive a app log entry "Line 2: Cannot process command because of one or more missing mandatory parameters: Start." The parameter is the path to the xml file. I suspect I am putting this in the wrong place but cannot find how it should look.
.......................
function Start-MyService
{
# [CmdletBinding()]
param(
[Parameter(ParameterSetName='Start', Mandatory=$true)]
[string]$Start
)
................
Can anybody shine some light on this for me?
Thanks in advance
Wayne
Creating a Windows Service that uses a parameter
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.
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.
- wayne_Avery
- Posts: 30
- Last visit: Tue Feb 01, 2022 2:25 pm
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Creating a Windows Service that uses a parameter
Yeah, it doesn't work that way. You cannot just redefine the functions with the parameters your like. They need to stay the way they are.
Typically for a Windows application that needs configuration, you put this as a file in a predefined folder.
E.g. C:\ProgramData\<Service name>\config.xml
and you load it from there on startup. Typically you place a default configuration file there when you install the service.
Please be aware that you cannot put that file in a user specific folder, as a service usually runs under the system account.
Typically for a Windows application that needs configuration, you put this as a file in a predefined folder.
E.g. C:\ProgramData\<Service name>\config.xml
and you load it from there on startup. Typically you place a default configuration file there when you install the service.
Please be aware that you cannot put that file in a user specific folder, as a service usually runs under the system account.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.