InstallUtil 在安装服务时卡住
InstallUtil gets stuck while installing service
我正在尝试使用 installUtil.exe 在管理员模式下使用以下命令安装我自己的 windows 服务。
InstallUtil C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe
我得到以下命令输出,安装卡在了那里。
----------------------------------- Installing Service.
Microsoft (R) .NET Framework Installation utility Version 4.7.2046.0
Copyright (C) Microsoft Corporation. All rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe assembly's progress.
The file is located at C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.InstallLog.
Installing assembly 'C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.InstallLog
assemblypath = C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe
当作为已安装的服务发布net start
时,该服务既不显示在服务查看器中,也不显示在 CLI 中。
以下是安装程序和服务 class 代码。
using System.ComponentModel;
using System.ServiceProcess;
namespace SubwaySync
{
[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public Installer()
{
// Instantiate installers for process and services.
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
// The services run under the system account.
processInstaller.Account = ServiceAccount.LocalSystem;
// The services are started manually.
serviceInstaller.StartType = ServiceStartMode.Automatic;
// ServiceName must equal those on ServiceBase derived classes.
serviceInstaller.ServiceName = "SyncSQL";
// Add installers to collection.
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
InitializeComponent();
}
}
public partial class SubwaySync : ServiceBase
{
EventLog e = new EventLog();
private System.Timers.Timer _timer;
public SubwaySync()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("DoDyLogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoDyLogSourse", "DoDyLog");
e.Source = "DoDyLogSourse";
// the event log source by which
//the application is registered on the computer
e.Log = "DoDyLog";
Thread.Sleep(60001);
}
protected override void OnStart(string[] args)
{
_timer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds); // 10 minutes expressed as milliseconds
_timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
_timer.AutoReset = true;
_timer.Start();
}
protected override void OnStop()
{
_timer.Stop();
_timer.Dispose();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
// Do your work here...
}
}
}
Thread.Sleep(60001);
服务中的这条线路 class (SubwaySync) 造成了延误。
我正在尝试使用 installUtil.exe 在管理员模式下使用以下命令安装我自己的 windows 服务。
InstallUtil C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe
我得到以下命令输出,安装卡在了那里。
----------------------------------- Installing Service.
Microsoft (R) .NET Framework Installation utility Version 4.7.2046.0
Copyright (C) Microsoft Corporation. All rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe assembly's progress.
The file is located at C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.InstallLog.
Installing assembly 'C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.InstallLog
assemblypath = C:\Users\Admin\Desktop\Subway_sync\SubwaySync\SubwaySync\bin\Debug\SyncSQL.exe
当作为已安装的服务发布net start
时,该服务既不显示在服务查看器中,也不显示在 CLI 中。
以下是安装程序和服务 class 代码。
using System.ComponentModel;
using System.ServiceProcess;
namespace SubwaySync
{
[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public Installer()
{
// Instantiate installers for process and services.
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
// The services run under the system account.
processInstaller.Account = ServiceAccount.LocalSystem;
// The services are started manually.
serviceInstaller.StartType = ServiceStartMode.Automatic;
// ServiceName must equal those on ServiceBase derived classes.
serviceInstaller.ServiceName = "SyncSQL";
// Add installers to collection.
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
InitializeComponent();
}
}
public partial class SubwaySync : ServiceBase
{
EventLog e = new EventLog();
private System.Timers.Timer _timer;
public SubwaySync()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("DoDyLogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoDyLogSourse", "DoDyLog");
e.Source = "DoDyLogSourse";
// the event log source by which
//the application is registered on the computer
e.Log = "DoDyLog";
Thread.Sleep(60001);
}
protected override void OnStart(string[] args)
{
_timer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds); // 10 minutes expressed as milliseconds
_timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
_timer.AutoReset = true;
_timer.Start();
}
protected override void OnStop()
{
_timer.Stop();
_timer.Dispose();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
// Do your work here...
}
}
}
Thread.Sleep(60001);
服务中的这条线路 class (SubwaySync) 造成了延误。