Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Security.SecurityException C# 2.0 windows service

I`m tring to install my windows service on Windows 7 x64

And getting this error

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.

this is my MyWindowsServiceInstaller code:

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);

i have set my application name to start up project

Here is bat file

@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

This service is not only my computer if i will solve this problem it would be solved for any other computers?

Thanks

like image 922
Irakli Lekishvili Avatar asked Nov 29 '25 04:11

Irakli Lekishvili


2 Answers

U can try installing in this way. Open cmd as administator and locate to .Net Framework path in your system

Eg: "C:\Windows\Microsoft.Net\Framework\v4.0.30319\"

Then with the help of installutil.exe you can install the service.

Eg: C:\Windows\Microsoft.Net\Framework\v4.0.30319\installutil.exe "Your service exe path"
like image 83
Satheesh Avatar answered Dec 01 '25 19:12

Satheesh


You may also overcome such issue by starting "Visual Studio Command Prompt" as "Run as administrator" option. Now install your assembly with installutil.exe command

x:\Windows\System32>installutil.exe YourService.exe

(Where YourService.exe is the compiled exe file of your service project)

Directions: To open the command prompt, click on "All Programs" -> "Microsoft Visual Studio (20xx)" -> "Visual Studio Tools (20xx)" -> "Visual Studio Command Prompt" (where 20xx is the respective version you are using like 2008, 2010 etc.).

like image 45
Muhammad Rizwan Avatar answered Dec 01 '25 18:12

Muhammad Rizwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!