Reputation: 176
I have a file system monitoring PowerShell script using System.IO.FileSystemWatcher
events.
The script works great, but it requires an open PowerShell window.
Thus, I need to run it as a Windows Service at Windows startup (without logon). Is there a way to do this?
Upvotes: 1
Views: 1661
Reputation: 16626
To execute your script at windows startup (without logon) you could create a windows service for it (using srvany.exe). Steps:
Create the service using sc and srvany.exe
sc create PSService binPath= "C:\Program Files\Windows Resource Kits\Tools\srvany.exe" DisplayName= "PSService"
Parametrize your service
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PSService]
"Type"=dword:00000010
"Start"=dword:00000003
"ErrorControl"=dword:00000001
"DisplayName"="PSService"
"ObjectName"="LocalSystem"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PSService\Parameters]
"Application"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -noExit -ExecutionPolicy RemoteSigned -File C:\\PSService\\psservice.ps1"
Some remarks:
Upvotes: 2