C# 遵循MSDN教程-未安装Windows服务

C# 遵循MSDN教程-未安装Windows服务,c#,.net,service,windows-services,C#,.net,Service,Windows Services,所以在这里,我再次经历了另一次MSDN失败。和往常一样,我决定学习如何用C#编写Windows服务,由于许多教程提供的代码不完整或编写得很差,我决定使用MSDN 我已经完成了每个步骤,我的服务将不会安装 我下面的页面是: 我的代码是: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using Syst

所以在这里,我再次经历了另一次MSDN失败。和往常一样,我决定学习如何用C#编写Windows服务,由于许多教程提供的代码不完整或编写得很差,我决定使用MSDN

我已经完成了每个步骤,我的服务将不会安装

我下面的页面是:

我的代码是:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace WindowsService1
{
    public partial class WindowsService1 : ServiceBase
    {
        public WindowsService1()
        {
            InitializeComponent();

            if (!System.Diagnostics.EventLog.SourceExists("MySource"))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    "MySource", "MyNewLog");
            }
            eventLog1.Source = "MySource";
            eventLog1.Log = "MyNewLog";
        }

        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
        }

        protected override void OnStop()
        {
            eventLog1.WriteEntry("In onStop.");

        }

        protected override void OnContinue()
        {
            eventLog1.WriteEntry("In OnContinue.");
        }
    }
}
我进入了开发者命令提示符,cd到了包含my.exe(调试文件夹)的目录,我:

installutil.exe WindowsService1.exe
并尝试了
installutil.exe WindowsService1.exe
,但安装始终失败,文本如下:

C:\ProgramFiles(x86)\Microsoft Visual Studio 11.0>cd C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug

C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>installutil WindowsService1.exe Microsoft(R).NET Framework安装实用程序 版本4.0.30319.32559版权所有(C)Microsoft Corporation。全部的 版权所有

正在运行事务处理安装

开始安装的安装阶段。见 C:\Users\Tommy\Documents\Visual Studio的日志文件 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe 阿塞姆布雷的进步。该文件位于 C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog。 正在安装程序集“C:\Users\Tommy\Documents\Visual Studio” 2013\项目\窗口 sService1\WindowsService1\bin\Debug\WindowsService1.exe'。影响 参数为:logtoconsole=logfile= C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService 1\WindowsService1\bin\Debug\WindowsService1.InstallLog assemblypath =C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsSe service1\WindowsService1\bin\Debug\WindowsService1.exe安装 服务1。。。正在日志中创建EventLog源服务1 应用程序

安装阶段发生异常。 System.InvalidOperationException:无法打开服务控制管理器 在计算r'.'时。此操作可能需要其他权限。这个 使用引发内部异常System.ComponentModel.Win32Exception 以下错误消息:访问被拒绝

安装的回滚阶段正在开始。看内容 C:\Users\Tommy\Documents\Visual Studio的日志文件的 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe 阿塞姆布雷的进步。该文件位于 C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog。 正在回滚程序集“C:\Users\Tommy\Documents\Visual Studio” 2013\项目\风 owsService1\WindowsService1\bin\Debug\WindowsService1.exe'。影响 参数为:logtoconsole=logfile= C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService 1\WindowsService1\bin\Debug\WindowsService1.InstallLog assemblypath =C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsSe service1\WindowsService1\bin\Debug\WindowsService1.exe还原事件 记录到源服务1的以前状态

回滚阶段已成功完成

已完成事务处理的安装。安装失败,并且 已执行回滚

C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>installutil WindowsService1 Microsoft(R).NET Framework安装实用程序 版本4.0.30319.32559版权所有(C)Microsoft Corporation。全部的 版权所有

初始化安装时发生异常: System.IO.FileNotFoundException:无法加载文件或程序集 'file:///C:\使用rs\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\b 在\Debug\WindowsService1'或其依赖项之一中。系统 找不到指定的文件

C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>installutil WindowsService1.exe Microsoft(R).NET Framework安装实用程序 版本4.0.30319.32559版权所有(C)Microsoft Corporation。全部的 版权所有

正在运行事务处理安装

开始安装的安装阶段。见 C:\Users\Tommy\Documents\Visual Studio的日志文件 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe 阿塞姆布雷的进步。该文件位于 C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog。 正在安装程序集“C:\Users\Tommy\Documents\Visual Studio” 2013\项目\窗口 sService1\WindowsService1\bin\Debug\WindowsService1.exe'。影响 参数为:logtoconsole=logfile= C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService 1\WindowsService1\bin\Debug\WindowsService1.InstallLog assemblypath =C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsSe service1\WindowsService1\bin\Debug\WindowsService1.exe安装 服务1。。。正在日志中创建EventLog源服务1 应用程序

安装阶段发生异常。 System.InvalidOperationException:无法打开服务控制管理器 在计算r'.'时。此操作可能需要其他权限。这个 使用引发内部异常System.ComponentModel.Win32Exception 以下错误消息:访问被拒绝

安装的回滚阶段正在开始。看内容 C:\Users\Tommy\Documents\Visual Studio的日志文件的 2013\Projects\WindowsService1\WindowsService1\bin
An exception occurred during the Install phase. System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges.