Removing/installing a Windows Service - c#

I've created a Windows Service project in C#, just some very simple code. It worked when i installed the service, but now I have to add some code and so on,but that has caused some issues:
1) When trying to uninstall using "installutil /u" it says its removed however its still on the service list in computeradministration.
1a) I tried to delete it with cmd using "sc delete ServiceName" which removes it from the list
2) BUT when i install the new build it succeeds, however it still uses the old build for some reason, and im kindda at a loss.

You only have to install once. The service will be registered with the .exe you registered using sc or installutil.
To replace the binary, just stop the service, replace the binary with the "new" one and restart: the new service will be running.
Also, you have to restart services.msc to see that some services are removed (there seems to be some "pending removal" flag).

If your service is in use (e.g. it is running) when you uninstall it you may have to restart your computer after uninstalling it before it is completely uninstalled. installutil and sc does not give you any information about this. And when a service is pending removal you can get into all sorts of problems if you try to install it again (which seems to the problem that you experience).
Make sure that the service is stopped before uninstalling it to avoid having to restart your computer to complete the uninstall.
If you just want to update the binary of the service you can simply stop it and replace the executable files before restarting the service.

Related

Microsoft Service Fabric Host Service (FabricHostSvc) Hangs on Start

I've been working with Microsoft Service Fabric since November 2015 and have encountered many issues but now Service Fabric has become completely non-functional on my development machine. Uninstall/reinstall doesn't help.
I was using 1.5-preview and have since tried 2.0 to no avail.
The problem started when I attempted to run a Service Fabric Application from Visual Studio 2015 Update 1 (as I have done hundreds of times over the past few months).
My machine blue-screened (first time I've seen a Windows 10 blue screen). After rebooting, I was unable to get my Service Fabric Application to deploy via Visual Studio. The PowerShell script failed with the following message:
Starting service FabricHostSvc. This may take a few minutes...
Start-Service : Failed to start service 'Microsoft Service Fabric Host
Service (FabricHostSvc)'.
I went into the SCM and found "Microsoft Service Fabric Host Service" was in a state of Starting. It stayed that way for an hour. I tried stopping and starting the service several times and each time it hangs.
I uninstalled Service Fabric (Service Fabric, SDK and Tools for VS) and re-installed with the latest version 2.0 and it exhibits the same problem.
Reboot, same problem.
Removed c:\SfDevCluster folder, same problem.
Based on some other articles, I looked for any stray performance counters after uninstalling but there weren't any.
I tried looking through the registry but there are other Azure components with "Fabric" in the name. If I delete them, I will probably hose the rest of my Azure dev setup.
Now... when I attempted to start the service again, it did re-create the SfDevCluster folder and give me some logs. It seems to create two trace log files per minute and they have the EXACT same contents.
Every time it fails, the final line of the trace is:
Info ,11176,General.FabricSetup.Main,Operation failed with error
0xffffffff
An earlier trace (SF 1.5) seemed to use a constant rather than the hex value for the error. Seemed to indicate an invalid argument.
Whatever this failure is, it seems to be the cause of my woes. Unfortunately, the error is completely unhelpful.
I'm trying to avoid reinstalling Windows because that will kill an entire day of productivity.
Any help is greatly appreciated.
From an elevated powershell session please run: Unregister-ScheduledTask FabricCounters.
This will fix the issue.
I was seeing very similar behaviour and reinstalls of the fabric SDK and runtime, deleting scheduled tasks, deleting the SfDevCluster contents etc. all didn't work.
I was seeing repeated Docker errors in the event log and when I tried uninstalling Docker for Windows SF instantly woke up. I have no idea what the interaction is between the two but worth checking if you have both installed.
For the benefit of searchers, this is the Powershell script I use to fix my local cluster. It was adapted from this issue fix on github.
#
# WARNING: YOU MUST STOP 'SERVICE FABRIC HOST SERVICE' IN SERVICES FIRST
# IF THE APPLICATION IS STUCK IN 'STARTING', RESTART YOUR MACHINE
#
# This script will completely reset the local cluster
#
Remove-Item 'C:\SfDevCluster' -Recurse -Force -ErrorAction Stop
New-Item -ItemType directory -Path 'C:\SfDevCluster'
Set-Location 'C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup'
./DevClusterSetup.ps1 -PathToClusterDataRoot 'C:\SfDevCluster\Data' -PathToClusterLogRoot 'C:\SfDevCluster\Log'
C:\ drive was full for me. Easy thing to overlook.
Make sure your hard disks aren't full... that was stopping mine from starting. Immediately after clearing up some logs, starts up right away.
It seems like some cluster related settings have gone into an inconsistent state on your machine. This will require looking at Service Fabric traces and figure out the actual cause. I am an engineer on the Service Fabric team. I can help you out if you can email me the Service Fabric traces (from logs folder) at harahma[at]microsoft[dot]com.
If you are familiar with logging support tickets on Azure, I would suggest you do that too so we can track this issue to resolution. In the meantime I will continue to work on this to see how we can unblock you.
I know this is an old and question, but maybe my pain can help someone else out.
You'll get a similar error if the Windows Firewall service is not running when Service Fabric attempts to start.
Check and make sure that the Windows Firewall service is set for Automatic and is running.
I have tried multiple options to resolve this issue like
Uninstall runtime and SDK - Reinstall it.
Removed cluster using powershell commands and setup using the same
and there are couple of more
BUT unfortunately none of them worked for me
Then finally I have Uninstalled Docker Desktop and suddenly issue got resolved.
This is very strange and not sure how docker desktop is obstackle for running FabricHostSvc Service.

Unable to install new version of .NET Windows Service

I have a 64-bit Windows Service, written in C#. It was previously installed on a Windows 7 64-bit machine. We've made some changes to it, and are trying to deploy the new version to the same machine.
However, no matter what we do, the behavior we are seeing seems to indicate that the service that is running is the old version.
Here are the steps we've taken in an attempt to resolve this issue:
Uninstalled the service using INSTALLUTIL.
Used SC DELETE to verify that it is removed.
Deleted all files from the service's installation directory, as specified in the service's properties page in the Services snap-in.
Removed any registry entries associated with the service from HKLM\System\CurrentControlSet001\Services.
Rebuilt the service and its dependencies with new version numbers.
Deployed the new version to the service's installation directory.
Reinstalled the service using INSTALLUTIL.
Verified that the Services snap-in and the registry are pointing to the correct location for the service executable.
Nonetheless, the behavior of the newly deployed service appears to be identical to the previous version. (Specifically, it is injecting messages into a queue in MSMQ, when that functionality was removed and can be verified to have been done so.)
We are positive that we are deploying the right version. This same behavior occurs even if we install the new version of the service from the Visual Studio project build folder (bin\x64\release).
Why is/would this be occurring? How do I resolve it? Are services cached somewhere and run from a cache when you install them? If so, where are they, and how do I properly clear them?
Or is this just something I've boned in the code?

Windows service fails to start

I'm trying to get my head around WCF applications hosted as a Windows service but I'm not sure what's happening here.
Basically, to get started, I've got a literal copy and paste of the code in this article: (I know, I shouldn't)
https://msdn.microsoft.com/en-us/library/vstudio/ms733069%28v=vs.110%29.aspx
The service builds fine and I can install it without issue. It shows up in services.msc also. I'm installing it as follows: (from the visual studio command prompt)
installutil Service.exe
However when it runs, I get the following error:
The WCFWindowsServiceSample service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
What am I doing wrong?

Do you need to re-install a Windows service after rebuilding

If I rebuild a Windows Service after making changes, can I just copy and replace the old assembly / .exe files to get those changes to run or do I need to re-install the service? Also do I have to first uninstall the service before installing the new version?
You don't have to uninstall and reinstall the service since this only adds registry info regarding the executable path and launch options. Just stop the service, copy your assemblies and restart it
You do not need to uninstall the service just make changes in your files after stopping the service and then start again it will consider your changes..
I would suggest you to use Topshelf for service hosting.

ServiceInstaller and "service already exists" 1001 error

I have an application with a project- and serviceinstaller in it. The installation usually works fine except in some cases when installed through PSEXEC remotely.
I wonder, where in the code I can intercept and check if the specific service is already installed and either, depending of best option, uninstall it or skip the current installation of service (but still continue with the overall install).
You can try uninstalling it unconditionally every time before you install.

Categories

Resources