System.Security.SecurityException C#2.0 windows服务

Ira*_*ili 2 c# windows-services

我想在Windows 7 x64上安装我的Windows服务

并得到这个错误

An exception occurred during the Rollback phase of the System.Diagnostics.EventLogInstaller installer.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.
Run Code Online (Sandbox Code Playgroud)

这是我的MyWindowsServiceInstaller代码:

var processInstaller = new ServiceProcessInstaller();
            var serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.DisplayName = "My Service";
            serviceInstaller.StartType = ServiceStartMode.Manual;
            serviceInstaller.ServiceName = "My Service";
            this.Installers.Add(processInstaller);
            this.Installers.Add(serviceInstaller);
Run Code Online (Sandbox Code Playgroud)

我已将我的应用程序名称设置为启动项目

这是bat文件

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i ConsoleApplication5.exe
echo ---------------------------------------------------
echo Done.
pause
Run Code Online (Sandbox Code Playgroud)

这项服务不仅是我的电脑,如果我能解决这个问题,它将解决任何其他计算机?

谢谢

Sat*_*esh 8

您可以尝试以这种方式安装.打开cmd作为管理员并找到系统中的.Net Framework路径

Eg: "C:\Windows\Microsoft.Net\Framework\v4.0.30319\"
Run Code Online (Sandbox Code Playgroud)

然后在installutil.exe的帮助下,您可以安装该服务.

Eg: C:\Windows\Microsoft.Net\Framework\v4.0.30319\installutil.exe "Your service exe path"
Run Code Online (Sandbox Code Playgroud)