我使用Procrun创建了一个Java应用程序(.jar)作为Windows服务。当我使用批处理(.bat)文件时,此服务得到安装并成功运行。但我有这种需要使用Windows PowerShell创建相同的服务。无法启动在PowerShell中使用Procrun创建的Windows服务
当我使用PowerShell,服务得到安装,但无法启动我在Windows事件查看器检查服务并显示为“不正确的函数”谁能告诉我这可能是这样做的原因。
这是我在PowerShell脚本用来安装Windows服务
[email protected]'
--Description="$Description"
--DisplayName="$DisplayName"
--Install="$DAEMON"
--Startup=auto
--Type=
--DependsOn=
--Environment=
--User=
--Password=
--ServiceUser=
--ServicePassword=
--LibraryPath=
--JavaHome
--Jvm=auto
--JvmOptions=-Xmx1024M
--Classpath=server.jar
--JvmMs=
--JvmMx=
--JvmSs=
--StartMode=jvm
--StartImage=
--StartPath=
--StartClass=at.mrdevelopment.esl.server.Server
--StartMethod=main
--StartParams=
--StopMode=jvm
--StopImage=
--StopPath=
--StopClass=at.mrdevelopment.esl.server.ServerServiceStarter
--StopMethod=stop
--StopParams=
--StopTimeout=120
--LogPath=$LogPath
--LogPrefix=$InstanceName
--LogLevel=DEBUG
--LogJniMessages=
--StdOutput=auto
--StdError=auto
--PidFile=${InstanceName}.pid
'@
任何帮助的字符串,将不胜感激。
这是我使用的PowerShell脚本。
#region Parameters
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[ValidateNotNullOrEmpty()]
[string]$Action="//IS"
,
[ValidateNotNullOrEmpty()]
[string]$ServiceName="//ESL_SERVICE"
,
[ValidateNotNullOrEmpty()]
[string]$DisplayName="ESL_SERVICE"
,
[ValidateNotNullOrEmpty()]
[string]$Description="ESL Service"
,
[ValidateNotNullOrEmpty()]
[string]$InstanceName="server.jar"
,
[ValidateNotNullOrEmpty()]
[string]$LogPath='C:\Apachelogs'
,
[string]$Pause=60
)
#endregion
#region Main
[email protected]'
--Description="$Description"
--DisplayName="$DisplayName"
--Install="$DAEMON"
--Startup=auto
--Type=
--DependsOn=
--Environment=
--User=
--Password=
--ServiceUser=
--ServicePassword=
--LibraryPath=
--JavaHome
--Jvm=auto
--JvmOptions=-Xmx1024M
--Classpath=server.jar
--JvmMs=
--JvmMx=
--JvmSs=
--StartMode=jvm
--StartImage=
--StartPath=
--StartClass=at.mrdevelopment.esl.server.Server
--StartMethod=main
--StartParams=
--StopMode=jvm
--StopImage=
--StopPath=
--StopClass=at.mrdevelopment.esl.server.ServerServiceStarter
--StopMethod=stop
--StopParams=
--StopTimeout=120
--LogPath=$LogPath
--LogPrefix=$InstanceName
--LogLevel=DEBUG
--LogJniMessages=
--StdOutput=auto
--StdError=auto
--PidFile=${InstanceName}.pid
'@
$DAEMON_HOME = "C:\imagotag\server"
$DAEMON = "$DAEMON_HOME\prunsrv_64.exe"
$ESL_HOME = "C:\imagotag\server"
[email protected]{}
$CmdArgsDict.Add('//IS', "$Action$ServiceName $CmdInstall")
$CmdArgs = $CmdArgsDict[$action]
# Convert backslashes in the paths to java-friendly forward slashes
$CmdArgs = $CmdArgs -replace "\\","/"
# Variable interpolation: expand embedded variables references (need to call this twice)
$CmdArgs = $ExecutionContext.InvokeCommand.ExpandString($CmdArgs)
$CmdArgs = $ExecutionContext.InvokeCommand.ExpandString($CmdArgs)
# Split on newlines to convert to an array of lines
$CmdArgsString = $CmdArgs -split "`n"
# Convert array of lines into a string
$CmdArgsString = "$CmdArgsString"
#--- Execute the command
if ($PSCmdlet.ShouldProcess(
"`n$DAEMON`n$CmdArgs","Manage ESL Service"
))
{
"$DAEMON $CmdArgsString"
$p=Start-Process "$DAEMON" `
-ArgumentList "$CmdArgsString" `
-Wait `
-NoNewWindow `
-PassThru
$rc = $p.ExitCode
"`nExit Code: $rc"
}
#endregion
我的PowerShell脚本是TestPS.ps1我执行这样
.\TestPS.ps1 //IS
敬请原谅后,效果很好。我编辑了我的问题。 –
你可以发布你的PS代码和相同的要求 –
@RanadipDutta我用我使用的PS脚本更新了我的问题。我的要求是当我执行这个脚本时,我需要将Windows服务安装到机器上并手动启动服务。 –