安装.NET Windows服务
问题描述:
我试图安装第一个服务,我用这样写道:安装.NET Windows服务
installutil XMPPMonitor.exe
我得到以下信息:
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the E:\Documents\Projects\XMPPMonitor\XMPPMonitor\bin\Debug\XMPPMonitor.exe assembly's progress.
The file is located at E:\Documents\Projects\XMPPMonitor\XMPPMonitor\bin\Debug\XMPPMonitor.InstallLog.
The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the E:\Documents\Projects\XMPPMonitor\XMPPMonitor\bin\Debug\XMPPMonitor.exe assembly's progress.
The file is located at E:\Documents\Projects\XMPPMonitor\XMPPMonitor\bin\Debug\XMPPMonitor.InstallLog.
The Commit phase completed successfully.
The transacted install has completed.
但我不会设置列出的服务当我运行services.msc。我错过了什么吗?
答
我们可以看到代码吗?
你对Description属性有什么建议?您是否在服务MMC中单击了F5(刷新)?
public class WindowsServiceInstallerEx : ServiceInstaller
{
[ComponentModel.Description("A lengthy description of the service that will display in the Description column of the Services MMC applet.")]
public string ServiceDescription
{
get { return serviceDescription; }
set { serviceDescription = value; }
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install (stateSaver);
Microsoft.Win32.RegistryKey serviceKey = null;
try
{
string strKey = string.Format(@"System\CurrentControlSet\Services\{0}", this.ServiceName);
serviceKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strKey, true);
serviceKey.SetValue("Description", this.ServiceDescription);
}
finally
{
if (serviceKey != null)
serviceKey.Close();
}
}
private string serviceDescription;
}
答
您可能需要刷新services.msc窗口,有时它不会更新它,如果它始终打开它。点击F5刷新窗口,看看它是否存在。
答
最近,我问了一个类似的问题:C#: Running and Debugging a Windows Service
显然的问题是,因为我没有一个安装附加到服务。
Here是我用来添加Service Installer等的教程。