To help you better we need some information from you.
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: PowerShell Studio 2018 v5.5.149
32 or 64 bit version of product: 64
Operating system: server 2016
32 or 64 bit OS: 64
*** Please add details and screenshots as needed below. ***
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
I was looking at this blog post:
https://www.sapien.com/blog/2018/02/27/ ... ript-2018/
Looked for more information for powershell studio and saw this:
viewtopic.php?f=12&t=12396#p66851
where he references the first article and says this:
If you use the functions mentioned in the following article, you can respond to calls to close the service.
Do I need to import anything or if I just name the functions the same as in the article and set the deploy settings to a service it will just work?
New PowerShell Service Template
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.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: New PowerShell Service Template
Yes, naming the functions accordingly and packaging it as a service should work fine.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: New PowerShell Service Template
is there any way you could open one of those templates, save it as a .ps1 and send it to me so I don't have to type all the comment code in there?
Re: New PowerShell Service Template
Trying it with this really simple set of code does not seem to work, I do not see any events in the application log:
Code: Select all
function Start-MyService
{
$global:bRunService = $true
$global:bServiceRunning = $false
$global:testvar = 0
}
function Invoke-MyService
{
$global:bServiceRunning = $true
while ($global:bRunService)
{
try
{
$global:testvar = $global:testvar + 1
Write-Host "Testvar is $global:testvar"
}
catch
{
Write-Host $_.Exception.Message
}
Start-Sleep -Seconds 1
}
$global:bServiceRunning = $false
}
function Stop-MyService
{
$global:bRunService = $false
$countdown = 30
while ($global:bServiceRunning -and $countdown -gt 0)
{
Start-Sleep -Seconds 1
$countdown = $countdown - 1
}
}
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: New PowerShell Service Template
Looks fine. Please describe exactly what you have done with it to run it as a service.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: New PowerShell Service Template
Type out Code
Deploy -> Packager -> Settings
Script Engine:
SAPIEN PowerShell V3 Host (Windows Service)
STA Mode unchecked
Output Settings:
Generate .config file checked
Manifest is embed a default manifest
run mode is current user
Execution Restrictions, version information, build options not touched.
Deploy -> Packager -> Build
put resulting executable in a folder
open command prompt and browse to folder
testservice /i
net start testservice
go look in application event log, see nothing.
Deploy -> Packager -> Settings
Script Engine:
SAPIEN PowerShell V3 Host (Windows Service)
STA Mode unchecked
Output Settings:
Generate .config file checked
Manifest is embed a default manifest
run mode is current user
Execution Restrictions, version information, build options not touched.
Deploy -> Packager -> Build
put resulting executable in a folder
open command prompt and browse to folder
testservice /i
net start testservice
go look in application event log, see nothing.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: New PowerShell Service Template
Have you verified in the services pane that your service is there and running?
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: New PowerShell Service Template
services indicates that it is running, get-process says that it is running, and I also see it in the task manager. The event log shows that it was successfully started. I also tried having it append a text file instead of attempting to write to the event log, but the file never is appended.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: New PowerShell Service Template
I have taken your script and packaged it as a service (V3, 64 bit), all is in the attached zip file.
Verify that this runs as desired on your system. Note that the service name is 'PowerShell Test Service'- Attachments
-
- TestService.zip
- (623.01 KiB) Downloaded 115 times
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: New PowerShell Service Template
That does run as desired, yes.
If I build the included code in the zip, it fails to operate properly.
If I build the included code in the zip, it fails to operate properly.