I have developed a windows service in c#, The project works fine in DEBUG mode, also the project is built with out any errors. When I try to install the service using InstallUtil.exe, I get below error and the service is not installed. Could someone please help what is going wrong here.
Installation command
Open command prompt in admin mode
Navigate to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
Run below command
installutil.exe C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
Error
Creating EventLog source MyService in log Application...
An exception occurred during the Install phase.
System.Exception: Value cannot be null.
Parameter name: path1
Below is the complete installation log.
Microsoft (R) .NET Framework Installation utility Version 4.8.4161.0
Copyright (C) Microsoft Corporation. All rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\Users\Public\TestService\MyService\bin\Release\MyService.exe assembly's progress.
The file is located at C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog.
Installing assembly 'C:\Users\Public\TestService\MyService\bin\Release\MyService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
logfile = C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog
Installing service MyService...
Service MyService has been successfully installed.
Creating EventLog source MyService in log Application...
An exception occurred during the Install phase.
System.Exception: Value cannot be null.
Parameter name: path1
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\Users\Public\TestService\MyService\bin\Release\MyService.exe assembly's progress.
The file is located at C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog.
Rolling back assembly 'C:\Users\Public\TestService\MyService\bin\Release\MyService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Users\Public\TestService\MyService\bin\Release\MyService.exe
logfile = C:\Users\Public\TestService\MyService\bin\Release\MyService.InstallLog
Restoring event log to previous state for source MyService.
Service MyService is being removed from the system...
Service MyService was successfully removed from the system.
Attempt to stop service MyService.
The Rollback phase completed successfully.
The transacted install has completed.
The installation failed, and the rollback has been performed.
did you try to go into your path : C:\Users\Public\TestService\MyService\bin\Release (if you built in debug use the debug folder)
and here, use command : installutil MyService.exe
You said the projet work well in debug mode. can you install it in debug ?
Related
So I am trying to create a service using C# in Visual Studio 2017 and I keep getting an error when I try to install it.
Right now, I don't even have anything in my service, I just want to be able to install the service. I created a new Project in Visual Studio 2017 using the Windows Service (.NET Framework) template under Visual C# > Windows Desktop. I then added the installer via Right Click > Add Installer. For serviceProcessInstaller1, I set the account to LocalSystem. And...that's it!
Now, I try to install it. I open up command prompt (run as administrator) and I do
InstallUtil ServiceTest.exe
Things start off smoothly, but then I get a message:
"An exception occured during the Install phase.
System.UnauthorizedAccessException: Attempted to perform an
unauthorized operation."
What could be generating this message?
I've googled and tried the following things:
Ensure I run command prompt as administrator.
Assign Full Control to
the project folder to my admin account.
Configure permissions to Full
Control for admin account in the security log of regedit.
Log into my
computer as an administrator (rather than regular user) and run it
that way.
Despite these things, I keep getting the same error. What else could I be doing wrong? Would really appreciate some advice!
Note: I am trying to install this service locally on my computer.
Edit: Per request, here are the logs. I named my project "FailedService", by the way, since I can't get it to work!
InstallUtil.InstallLog
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe assembly's progress.
The file is located at C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.InstallLog.
An exception occurred during the Install phase.
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe assembly's progress.
The file is located at C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
FailedService.InstallLog
Installing assembly 'C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.InstallLog
assemblypath = C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe
Installing service Service1...
Creating EventLog source Service1 in log Application...
Rolling back assembly 'C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.InstallLog
assemblypath = C:\Users\first.m.last\source\repos\FailedService\FailedService\bin\Debug\FailedService.exe
Restoring event log to previous state for source Service1.
I was FINALLY able to resolve this issue. I was able to get to the bottom of it by using SysInternal's Process Monitor. I opened up the program and had it take logs for InstallUtil.exe. From there, I began to search for any logs that said "Access Denied". As I sorted through them, I noticed something interesting: it was trying to create a registry key, but it kept failing!
So I went into the registry and created a key named "ServiceTest". After that, I ran the InstallUtil command again, and it worked!
If anyone else is having trouble, the solution is to create a key named after your process name in the following location:
HKLM\System\CurrentControlSet\Services\EventLog\Application\
Enter the full path to installUtil & your service binary in an elevated prompt, that could do.
I have a created a windows service and i am installing it using installutil. In the project installer i am creating a custom event log. But when my service starts my all logs are going to the "Application" instead of my cuustom log. Below is the code which i have added to installer.
// Create Event Source and Event Log
EventLogInstaller logInstaller = new EventLogInstaller();
logInstaller.Source = "MyServices";
logInstaller.Log = "MyService Events";
Installers.Add(logInstaller);
Furthurmore the name of service is MyService.exe.
When I uninstall and re-install the service, i installation fail with the following install log;
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the D:\MyService\MyService\bin\Release\MyService.exe
assembly's progress. The file is located at
D:\MyService\MyService\bin\Release\MyService.InstallLog.
An exception occurred during the Install phase.
System.ArgumentException: Source MyServices already exists on the
local computer.
The Rollback phase of the installation is beginning. See the contents
of the log file for the
D:\MyService\MyService\bin\Release\MyService.exe assembly's progress.
The file is located at
D:\MyService\MyService\bin\Release\MyService.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
And this is how i write log entry;
EventLog.WriteEntry("MyServices", logMessage, logType);
Can someone please help me what wrong i am doing.
When you add a new Log Source you have to restart the server for the log source to be found properly.
You also need your installer to be aware of if the log source is already there.
So add a quick check for the log source before you add it and restart the server after installing the first time to get the log source to work.
So here I am again experiencing yet another MSDN fail. As usual, I've decided to learn how to write a Windows Service in C# and due to many tutorials offering incomplete or just poorly-written code, I've decided to use MSDN.
I've followed every step and my service will not install.
The page I'm following along with is: http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
and my code is:
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.");
}
}
}
I've gone into developer command prompt, cd'd to the directory containing my .exe (the debug folder), and I've:
installutil WindowsService1.exe and also tried installutil.exe WindowsService1.exe but the installation always fails, with the following text:
C:\Program Files (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 Installation utility
Version 4.0.30319.32559 Copyright (C) Microsoft Corporation. All
rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
asse mbly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
Installing assembly 'C:\Users\Tommy\Documents\Visual Studio
2013\Projects\Window
sService1\WindowsService1\bin\Debug\WindowsService1.exe'. Affected
parameters are: 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 rvice1\WindowsService1\bin\Debug\WindowsService1.exe Installing
service Service1... Creating EventLog source Service1 in log
Application...
An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager
on compute r '.'. This operation might require other privileges. The
inner exception System.ComponentModel.Win32Exception was thrown with
the fol lowing error message: Access is denied.
The Rollback phase of the installation is beginning. See the contents
of the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
asse mbly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
Rolling back assembly 'C:\Users\Tommy\Documents\Visual Studio
2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.exe'. Affected
parameters are: 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 rvice1\WindowsService1\bin\Debug\WindowsService1.exe Restoring event
log to previous state for source Service1.
The Rollback phase completed successfully.
The transacted install has completed. The installation failed, and the
rollback has been performed.
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>installutil
WindowsService1 Microsoft (R) .NET Framework Installation utility
Version 4.0.30319.32559 Copyright (C) Microsoft Corporation. All
rights reserved.
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly
'file:///C:\Use rs\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\b
in\Debug\WindowsService1' or one of its dependencies. The system
cannot find the file specified..
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>installutil
WindowsService1.exe Microsoft (R) .NET Framework Installation utility
Version 4.0.30319.32559 Copyright (C) Microsoft Corporation. All
rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
asse mbly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
Installing assembly 'C:\Users\Tommy\Documents\Visual Studio
2013\Projects\Window
sService1\WindowsService1\bin\Debug\WindowsService1.exe'. Affected
parameters are: 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 rvice1\WindowsService1\bin\Debug\WindowsService1.exe Installing
service Service1... Creating EventLog source Service1 in log
Application...
An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager
on compute r '.'. This operation might require other privileges. The
inner exception System.ComponentModel.Win32Exception was thrown with
the fol lowing error message: Access is denied.
The Rollback phase of the installation is beginning. See the contents
of the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
asse mbly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
Rolling back assembly 'C:\Users\Tommy\Documents\Visual Studio
2013\Projects\Wind
owsService1\WindowsService1\bin\Debug\WindowsService1.exe'. Affected
parameters are: 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 rvice1\WindowsService1\bin\Debug\WindowsService1.exe Restoring event
log to previous state for source Service1.
The Rollback phase completed successfully.
The transacted install has completed. The installation failed, and the
rollback has been performed.
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsServ ice1\bin\Debug>
which also outputs an INSTALLLOG file into theDebug directory, which contains (the same info):
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
assembly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager
on computer '.'. This operation might require other privileges. The
inner exception System.ComponentModel.Win32Exception was thrown with
the following error message: Access is denied.
The Rollback phase of the installation is beginning. See the contents
of the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
assembly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
assembly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager
on computer '.'. This operation might require other privileges. The
inner exception System.ComponentModel.Win32Exception was thrown with
the following error message: Access is denied.
The Rollback phase of the installation is beginning. See the contents
of the log file for the C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe
assembly's progress. The file is located at
C:\Users\Tommy\Documents\Visual Studio
2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
So then I go back to MSDN. To see what to do if the installation fails, but instead I see this:
If the service installs successfully, installutil.exe will report success. There is no other information about what to do if the install fails.
I've spent days on this and I've followed over 8 tutorials, all of which have either incomplete or bad code (that doesn't work). So I finally decide to put my trust in MSDN again but as usual I'm left wondering what the hell is going on.
My user account has full read/write/exec permissions, is an administrator and I have checked Computer Management (> Services and Applications) and confirmed that my Windows Service is not listed there.
What do I do now? How do I create a Windows Service (that works)?
An exception occurred during the Install phase. System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges.
Run your developer command prompt "as administrator". Being an administrator is not the same as running your processes as administrator.
From MSDN:
On the Start menu or Start Page, open the shortcut menu for Developer Command Prompt, and then choose Run As Administrator.
An exception occurred during the Install phase. System.InvalidOperationException: Cannot open Service Control Manager on compute r '.'. This operation might require other privileges. The inner exception System.ComponentModel.Win32Exception was thrown with the fol lowing error message: Access is denied.
The error says what the problem is: you don't have permission to install the service.
If the machine is a domain member, it's entirely possible that the local admin account doesn't have permissions required to install the service.
It's also possible that it's being blocked by AV software or that your service needs to be added to a whitelist. The possibilities are nearly endless, so you'll need to find out what the specific error is.
You might get more information from the Security Event Log. You can also try the sysinternals Process Monitor. It should show you what it's trying to do and what is failing.
My user account has full read/write/exec permissions, is an administrator
If you're on a domain, you may need to be a domain admin.
I created a demo service.
Build project as is (Service1 constructor, OnStart, OnStop)
Added Installer, changed the required properties.
Build project.
Open command prompt, run "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" TestService.exe
Getting the following error on installation
C:\Users**>"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUt
il.exe" "C:\Users**\Documents\Visual Studio
2010\Projects\TestServi ce\TestService\bin\Debug\TestService.exe"
Microsoft (R) .NET Framework Installation utility Version > Copyright (c) Microsoft Corporation. All rights reserved.
Running a transacted installation.
Beginning the Install phase of the installation. See the contents of
the log file for the C:\Users**\Documents\Visua l Studio
2010\Projects\TestService\TestService\bin\Debug\TestService.exe
assembl y's progress. The file is located at
C:\Users**\Documents\Visual Studio 2010\Proj
ects\TestService\TestService\bin\Debug\TestService.InstallLog.
Installing assembly 'C:\Users**\Documents\Visual Studio
2010\Projec ts\TestService\TestService\bin\Debug\TestService.exe'.
Affected parameters are: logtoconsole = logfile =
C:\Users**\Documents\Visual Studio 2010\Projects\TestS
ervice\TestService\bin\Debug\TestService.InstallLog assemblypath =
C:\Users**\Documents\Visual Studio 2010\Projects\
TestService\TestService\bin\Debug\TestService.exe Installing service
Service1... Creating EventLog source Service1 in log Application...
An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some
or all eve nt logs could not be searched. Inaccessible logs:
Security.
The Rollback phase of the installation is beginning. See the contents
of the log file for the C:\Users**\Documents\Visua l
Studio 2010\Projects\TestService\TestService\bin\Debug\TestService.exe
assembl y's progress. The file is located at
C:\Users**\Documents\Visual Studio 2010\Proj
ects\TestService\TestService\bin\Debug\TestService.InstallLog. Rolling
back assembly 'C:\Users**\Documents\Visual Studio
2010\Proj ects\TestService\TestService\bin\Debug\TestService.exe'.
Affected parameters are: logtoconsole = logfile =
C:\Users**\Documents\Visual Studio 2010\Projects\TestS
ervice\TestService\bin\Debug\TestService.InstallLog assemblypath =
C:\Users**\Documents\Visual Studio 2010\Projects\
TestService\TestService\bin\Debug\TestService.exe Restoring event log
to previous state for source Service1. An exception occurred during
the Rollback phase of the System.Diagnostics.EventL ogInstaller
installer. System.Security.SecurityException: The source was not
found, but some or all eve nt logs could not be searched.
Inaccessible logs: Security. An exception occurred during the Rollback
phase of the installation. This except ion will be ignored and the
rollback will continue. However, the machine might n ot fully revert
to its initial state after the rollback is complete.
The Rollback phase completed successfully.
The transacted install has completed. The installation failed, and the
rollback has been performed.
I tried installing the service using the setup project but everytime i try and run the service it gives Error 1053
I am trying to Install a windows service I made with the following command :
C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug>InstallU
til.exe filechecker.exe
but I am getting the following message:
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.exe assembly's progress.
The file is located at C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.InstallLog.
An exception occurred during the Install phase.
System.ArgumentException: Must specify value for source.
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.exe assembly's progress.
The file is located at C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.exe assembly's progress.
The file is located at C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.InstallLog.
An exception occurred during the Install phase.
System.ArgumentException: Must specify value for source.
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.exe assembly's progress.
The file is located at C:\$(MyFiles)\Projects\Win Service\c#\filechecker\filechecker\bin\Debug\filechecker.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
How can I solve this issue?
A ServiceInstaller always1 creates an event log source, and sets the Source name to the ServiceName. The error suggests to me that you're not setting the ServiceName on your ServiceInstaller instance (although I'd have hoped for a better error).
1Unless you manually iterate its installers collection and remove it, after it's instantiated. You'd also have to make sure you turn off all of the automatic logging and/or manually add your own EventLogInstaller using the same source name - this can be useful if you wish all logging from the service (including automatic logging) to go to somewhere other than the Application event log.