我有一个简单的 Windows 服务,它调用批处理文件来在启动时设置一些进程。大多数批处理文件已正确触发,但由于 Windows 服务无法启动,InstallUtil /i 无法运行。(InstallUtil /u 事先可以工作,但我觉得很奇怪)这是 Windows 服务和批处理文件的一些代码:
namespace RecipopStartupService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
ProcessBatchFile();
}
public void ProcessBatchFile()
{
Process process = new Process();
process.StartInfo.WorkingDirectory = "C:\\Webs\\AWS\\";
process.StartInfo.FileName = "C:\\Webs\\AWS\\setup.bat";
process.StartInfo.Arguments = "";
process.StartInfo.Verb = "runas";
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = false;
process.Start();
System.IO.StreamReader myOutput = process.StandardOutput;
process.WaitForExit(200000);
if (process.HasExited)
{
string results = myOutput.ReadToEnd();
}
}
protected override void OnStop()
{
}
}
}
批处理文件:
"C:\Program Files (x86)\Subversion\bin\SVN.exe" cleanup "C:\Webs\AWS\webs"
"C:\Program Files (x86)\Subversion\bin\SVN.exe" cleanup "C:\Webs\AWS\apps"
"C:\Program Files (x86)\Subversion\bin\SVN.exe" update "C:\Webs\AWS\webs"
REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Uninstalling MyService...
echo ---------------------------------------------------
InstallUtil /u "C:\Webs\AWS\apps\MyService.exe"
echo ---------------------------------------------------
echo Done.
"C:\Program Files (x86)\Subversion\bin\SVN.exe" update "C:\Webs\AWS\apps"
REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i "C:\Webs\AWS\apps\MyService.exe"
echo ---------------------------------------------------
echo Done.
NET START MyService
我已经注释掉了各个部分以确定是什么阻止了服务的启动。正如我之前所说,它是 InstallUtil /i 部分。
如果有人可以建议,那就太好了。
谢谢,科林