我有无限循环PowerShell (测试目的)脚本,我想在Windows Server2008 R2 (标准版)中将其作为服务运行。
我使用以下命令来创建Windows服务,
sc.exe create "My PS1Service" binPath= "powershell.exe -NoLogo -Path D:\TEST\test.ps1"
结果是[SC] CreateService SUCCESS
但是,当我尝试运行服务My PS1Service
时,它返回以下错误
Windows Could not srart the My PS1Service service on Local
Computer
Error 1053: The service did not respond to the start or control
request in a family
这里有帮助吗!
发布于 2018-01-03 11:46:11
由于文章的长度,我不想把它们粘贴在答案中。
查看这篇文章,这是我找到的关于powershell服务的最全面的信息来源:https://msdn.microsoft.com/en-us/magazine/mt703436.aspx
它链接到一个示例powershell服务:http://jf.larvoire.free.fr/progs/PSService.ps1
我最终没有成功地修改它,因为它将花费我更长的时间来阅读和理解它,而不是为我的用例使用不同的方法,但如果我将来需要在powershell中创建服务,我肯定会回到那个方法。
还有这个:https://www.sapien.com/blog/2017/07/12/write-a-windows-service-in-powershell/
发布于 2019-12-08 22:17:02
我一直在到处寻找一种像样的方式将PS1变成服务。我找到的最简单的方法是使用Winsw:https://github.com/kohsuke/winsw
就像一种护身符。
发布于 2019-09-17 05:35:42
我在非吸入式服务管理器(NSSM)方面也取得了成功。https://nssm.cc/
https://stackoverflow.com/questions/26506010
复制相似问题