Place code here to close connections and release resources. You can see some management code in here that will allow your main service loop to exit gracefully. This function is called when your service is asked to stop by the operating system or when using the Stop-Service command. # Place code to be executed on service stop here Start-Sleep -Seconds 1 # wait for your main loop to exit While($global:bServiceRunning -and $Countdown -gt 0) $CountDown = 30 # Maximum wait for loop to exit $global:bRunService = $false # Signal main loop to exit This function will run continuously as your service runs, following a process–sleep–process cycle. This is your service’s main loop, where the main functionality of your service takes place. Start-Sleep –Seconds 10 # a lower number will make your service active more often and use more CPU cycles Start-Sleep -Seconds 20 # if the service is paused we sleep longer between checks. # Adjust sleep timing to determine how often your service becomes active. If($global:bServicePaused -eq $false) #Only act if service is not paused Invoke-MyService function Invoke-MyService You should place all initialization code for your service here, such as opening connections or initializing global variables. This function is called when your service starts. The functions are as follows: Start-MyService function Start-MyService It’s important to note that you should not rename or omit any of the predefined functions when using this template because they are used when packaging with the SAPIEN Script Packager. This script template is also included in PrimalScript. You can use this template as part of a project or as a stand-alone script. The Windows Service Project utilizes the same predefined functions used by the single file Windows Service Script template. The Windows Service Project template allows you to create a Windows service script in a project: Services can start automatically when the system boots or they can start on demand-as requested by applications that rely on them. Windows Services are programs that run in the background, with no user interaction. This article is the next installment in our PowerShell Studio Project series and covers the basics of working with Windows Service Projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |