Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows services r服务,打开VisualStudio2008命令提示符,导航到可执行文件所在的调试或发布目录。在命令提示下,键入以下命令:InstallUtil ServiceExample.exe。这将在本地计算机上安装您的服务。要卸载它,请在命令提示符下键入以下命令:InstallUtil/u ServiceExample.exe_Windows Services - Fatal编程技术网

Windows services r服务,打开VisualStudio2008命令提示符,导航到可执行文件所在的调试或发布目录。在命令提示下,键入以下命令:InstallUtil ServiceExample.exe。这将在本地计算机上安装您的服务。要卸载它,请在命令提示符下键入以下命令:InstallUtil/u ServiceExample.exe

Windows services r服务,打开VisualStudio2008命令提示符,导航到可执行文件所在的调试或发布目录。在命令提示下,键入以下命令:InstallUtil ServiceExample.exe。这将在本地计算机上安装您的服务。要卸载它,请在命令提示符下键入以下命令:InstallUtil/u ServiceExample.exe,windows-services,Windows Services,只要您的服务未运行,您就可以对服务进行更改并重新构建,也就是说,您不必卸载服务即可对其进行更改。但是,只要可执行文件正在运行,您就无法使用修复和增强覆盖该文件 要查看正在运行的服务,请打开ServiceExample.cs文件并进行以下更改: using System.Diagnostics; public partial class ServiceExample : ServiceBase { public ServiceExample() { // Uncom

只要您的服务未运行,您就可以对服务进行更改并重新构建,也就是说,您不必卸载服务即可对其进行更改。但是,只要可执行文件正在运行,您就无法使用修复和增强覆盖该文件

要查看正在运行的服务,请打开ServiceExample.cs文件并进行以下更改:

using System.Diagnostics;
public partial class ServiceExample : ServiceBase
{
    public ServiceExample()
    {
        // Uncomment this line to debug the service.
        //Debugger.Break();

        InitializeComponent();

        // Ties the EventLog member of the ServiceBase base class to the
        // ServiceExample event log created when the service was installed.
        EventLog.Log = "ServiceExample";
    }

    protected override void OnStart(string[] args)
    {
        EventLog.WriteEntry("The service was started successfully.", EventLogEntryType.Information);
    }

    protected override void OnStop()
    {
        EventLog.WriteEntry("The service was stopped successfully.", EventLogEntryType.Information);
    }

    protected override void OnShutdown()
    {
        EventLog.WriteEntry("The service was shutdown successfully", EventLogEntryType.Information);
    }
}
使用这些更改运行服务后,可以在事件查看器中查看ServiceExample事件日志并查看其中记录的消息

希望这有帮助


编辑:如果您希望使用应用程序事件日志来记录事件,而不是自定义日志,只需不更改ProjectInstaller.cs文件即可。此外,省略ServiceExample构造函数中设置EventLog属性的行。运行服务时,您的日志消息将显示在应用程序事件日志中。

要让服务从命令行自行安装,而不必使用InstallUtil.exe,请参阅我在此处的帖子:如何从服务导出类/接口并从客户端(本地系统服务)调用?@sarat,看看我的回答:
System.UnauthorizedAccessException:对路径“C:\MyService.InstallState”的访问被拒绝。
结果表明,您必须以管理员身份运行cmd.exe。+1这对我也很有效,尤其是自定义日志的步骤9,我还让安装程序编写了第一个条目。对于类似问题的许多其他答案都表示可以使用WiX,但这种解决方案并不需要WiX。比MSDN更有用,并且只在安装期间需要管理员权限。哇!这是一个老帖子。最后,我学习了如何使用Heat.exe并提取使用WiX和启用com互操作的LIB所需的位。
using System.Diagnostics;
public partial class ServiceExample : ServiceBase
{
    public ServiceExample()
    {
        // Uncomment this line to debug the service.
        //Debugger.Break();

        InitializeComponent();

        // Ties the EventLog member of the ServiceBase base class to the
        // ServiceExample event log created when the service was installed.
        EventLog.Log = "ServiceExample";
    }

    protected override void OnStart(string[] args)
    {
        EventLog.WriteEntry("The service was started successfully.", EventLogEntryType.Information);
    }

    protected override void OnStop()
    {
        EventLog.WriteEntry("The service was stopped successfully.", EventLogEntryType.Information);
    }

    protected override void OnShutdown()
    {
        EventLog.WriteEntry("The service was shutdown successfully", EventLogEntryType.Information);
    }
}