【发布时间】:2014-12-17 19:37:39
【问题描述】:
我有无限循环 PowerShell(测试目的)脚本,我想在 Windows Server 2008 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
这里有任何帮助!!!
【问题讨论】:
-
请看:
get-help New-Service。同时指定powershell.exe的完整路径 -
您不能将任何可执行文件作为服务运行。它必须响应服务控制管理器的请求。通常,在 C# 中,这将涉及从
System.ServiceProcess.ServiceBase继承。你在 test.ps1 中做类似的事情吗? -
@mikez ,不,我没有做任何类似 C# 的事情。它只是一个具有无限循环并将数字写入文件的 PS1 脚本
-
尝试创建使用本地 ID 运行的服务。还要检查执行策略。
标签: windows powershell windows-services powershell-2.0 windows-server-2008-r2