C# 不在服务列表中的Windows服务认为已成功安装
我已经使用Visual Studio 2012开发了一个Windows服务,我想在我的机器上安装它 服务代码:C# 不在服务列表中的Windows服务认为已成功安装,c#,.net,visual-studio-2012,windows-services,C#,.net,Visual Studio 2012,Windows Services,我已经使用Visual Studio 2012开发了一个Windows服务,我想在我的机器上安装它 服务代码: public partial class OpenTableImporter : ServiceBase { public OpenTableImporter() { InitializeComponent(); EventLog.Log = "OpenTableImporterTableLog";
public partial class OpenTableImporter : ServiceBase
{
public OpenTableImporter()
{
InitializeComponent();
EventLog.Log = "OpenTableImporterTableLog";
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("The service was started successfully.", EventLogEntryType.Information);
XMLReader xmlReader = new XMLReader();
}
protected override void OnStop()
{
EventLog.WriteEntry("The service was stopped successfully.", EventLogEntryType.Information);
}
这是主程序的代码:
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new OpenTableImporter()
};
ServiceBase.Run(ServicesToRun);
}
}
我已经:
- 将启动对象
更改为我的程序李>
- 向事件日志授予
读/写权限网络服务
- 试图将
类设为公共类,然后不设公共类程序.cs
- 以管理员身份运行Visual Studio,以管理员身份运行cmd
- 已添加该服务的安装程序李>
- 向事件日志授予
SC.EXE
SC.EXE create "MyService" binpath= "\"c:\program files\MyService\MyService.exe\" arg1 arg2" displayname= "My Service Name"
这将创建一个服务,并告诉服务控制管理器,要启动服务,它应该调用“c:\program files\MyService\MyService.exe”
,并在命令行上传递两个参数arg1
和arg2
。例如,对于这些场景,如果它有/debug
和/service
选项
如果您的可执行服务不需要任何特殊参数来运行服务,您可以忽略这些参数
注意:如果可执行文件的路径包含空格,则需要使用反斜杠双引号将其引用,即
\“
在路径的开头和结尾,就像我在示例中看到的那样。这很奇怪,在我读过的所有页面中,installutil
是唯一需要的命令,无论如何,我将开始尝试您的解决方案并更新您对不起,我发现了问题,没有问题,我在搜索OpenTableImporter
时安装了importerOpenTable
服务。顺便说一句,不是我干的downvote@MarcoDinatsoli,Installutil也会工作,它也会做同样的事情。但是,您没有提到您已经尝试过Installutil的任何地方!是的,我没有提到这一点,因为我认为这是安装该服务的唯一方法,我是sorryMarco,您可能需要以管理员身份启动DOS命令窗口(右键单击“命令提示符”并选择选项“以管理员身份运行”)在您在其中发出InstallUtil或SC命令之前。是什么让您认为它不在服务列表中?你刷新了那个列表吗?@KateGregory我不好意思这么说,但我刚刚发现了问题,服务名称是“importerOpenTable”,但我正在搜索“OpenTableImporter”。我花了7个小时,对每个人来说我都是个白痴。这就是为什么我问——名字混淆是“失踪”的首要原因services@KateGregory写一封信接受它please@KateGregory请稍等,我没有找到解决方案,似乎服务名称中没有错误:(请帮助)
SC.EXE create "MyService" binpath= "\"c:\program files\MyService\MyService.exe\" arg1 arg2" displayname= "My Service Name"