I inherited a couple c# windows service projects. I have fixed some bugs in the code and now I need to deploy the new executable. What is the normal process for updating / replacing a windows service? I have remote desktop access to the server that I am installing it on.
Just stop the service and replace the executable and possibli the additional dependency you have updated. Of course it could be helpful have a backup of the running service, just to be safe :)
If you need to know exactly where the service is running, open Service Control Manager, select your serice, and look in the properties/general: you will find the executable path.
It's enough to replace exe and dlls. Obviously you have to stop the service first. If dlls were registered in GAC they might be used by other software on that machine, in such case before compiling and deploying change their version.
For a .Net Windows Service you need to use the InstallUtil command line tool to uninstall the old service, then use it to install the new one.
See...
http://msdn.microsoft.com/en-us/library/50614e95(v=vs.80).aspx
Related
So I made a .exe application which runs perfectly fine. But, now I have a requirement to run a background service for a particular reason which is related to this application. I figured out how to make a windows service and it's working, But I had to install the service manually by going to the CMD and using the service manager.
How do I install the service along with the installation of the executable that I made?
Because otherwise, everyone who uses this .exe will need to install the service manually by going to the CMD.
You can do it.
sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>"
This is probably a duplicate but I can't find recent posts and most sources recommend external tools.
We have a service that is installed via Microsoft Visual Studio 2017 Installer Projects. I assume for updating the service I need an additional tool that does the following:
Stop the service (or is it better to make the service itself check for updates and stop itself?)
Copy the new files to the install folder
Call installutil.exe MyUpdatedService.exe (or is this obsolete if the service is updated ?)
Start the service
We already have a tool for steps 1., 2. and 4. for regular applications. Do I need to implement a ServiceController Class to interact with the service or could any program start/stop the service?
If you want an external c# application, you need ServiceController.
You could stop the service from within the service, but you cannot really start it afterwards.
You don't need to update service registration once it's registered, you only need to replace the service binaries.
Rename old service binaries while service is still running
Not sure if this is possible on all versions of Windows, also it has to be a rename.
Copy new version under the original name
Restart the service
This would unload the old version and load the new one.
The service interruption is the shortest possible.
Clean-up the old version
Once the old version is stopped, you'll be able to remove old binaries.
A long time back I developped a Windows service with c# 4.0 and also created a setup file with VS2010 for that app. I installed that app and it was running. someone removed that Windows service not properly like removing some entry from registry regarding that app and as a result that app name is not showing in ADD/Remove list and removed all files and folder from program files folder related to that Windows service.
So when I try to run the setup file for that win service to install it in my pc then I am getting the error message Enter an alternate path to a folder containing the installation package
so guide me how could I again install that Windows service in my pc from that setup. thanks
I've found the "Windows Installer cleanup uitlity" to be enormously helpful in situations like this. It's an abandoned project, but you can still get it by googling. You can use it to completely remove a program from your computer, after which it won't conflict with a new installation.
I found it here:
www.majorgeeks.com
Simply download the file needed and provide the [un]installer with the download folder. And press OK. You can do it without interrupting the process. Do not use the Windows Installer Cleanup Utility It is not supported and extremely dangerous!
There is a weird issue I am facing. I created my first windows service looking through various blogs and tutorials.
Then created setup for that adding installer etc. It works fine while installing , un-installing via Visual Studio but it fails when i deploy it .
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Users\bhuvint\Documents\Visual Studio 2010\Projects\CPNS Library\ServicePackage\CommonPushNotificationWindowsService.application resulted in exception. Following failure messages were detected:
+ You cannot start application CommonPushNotificationWindowsService from this location because it is already installed from a different location.
+ You cannot start application CommonPushNotificationWindowsService from location file:///C:/Users/bhuvint/Documents/Visual%20Studio%202010/Projects/CPNS%20Library/ServicePackage/CommonPushNotificationWindowsService.application it is already installed from location file:///C:/inetpub/wwwroot/ServicePackage/CommonPushNotificationWindowsService.application. You can start it from location file:///C:/inetpub/wwwroot/ServicePackage/CommonPushNotificationWindowsService.application or you can uninstall it and reinstall it from location file:///C:/Users/bhuvint/Documents/Visual%20Studio%202010/Projects/CPNS%20Library/ServicePackage/CommonPushNotificationWindowsService.application.
I have already un-installed the service and trying to install it from the deployed service in the same pc to test. But it fails with above error.
I feel i have deployed the windows service the wrong way. Could you guys please suggest how to deploy a windows service ?? (I have looked through net. All suggest building it and installing it from visual studios. But how to publish it is the thing which i need.)
Please help asap.
Possibly you built the setup project before uninstalling the preovious service. In that case you can't use the new setup to uninstall the service, since the setup won't be the same and can't be able to access the service installed.
You should try to go to a previous version of your project and uninstall the service and for the future unistall the service each time you're building your setup project.
This happened to me several times.
Run visual studio in debug mode, and in your properties of your service project goto tab build events in Post-Build event command line and add a -d so you can run your service without installing it, it will run as an console app
The LocalService account acts as a non-privileged user on the local computer, and presents anonymous credentials to any remote server. Use the other accounts with caution, as they run with higher privileges and increase your risk of attacks from malicious code.
If your service application will not install correctly, check to make sure that the ServiceName property for the service class is set to the same value as is shown in the installer for that service. The value must be the same in both instances in order for your service to install correctly.
NoteNote
You can also look at the installation logs to get feedback on the installation process.
You should also check to determine whether you have another service with the same name already installed. Service names must be unique for installation to succeed.
STUPIDITY PERSONIFIED
As i told i was deploying my service. So this published code had a "setup.exe" file to it. Now I had already created a setup project for the windows service , which i was using for the installing , uninstalling . And i din't know (These words needs courage !!) that msi file created is required to install the windows service. So as i got through the folder structure of the setup project. I came across the .msi file . And hence the problem got solved. The Main problem was :
Me not knowing to use setup projects
And I confused setup.exe with the published windows service with the setup of windows service.
I am really sorry for stealing bandwidth off your precious time. Thanks to all for the valuable inputs.
Is it possible to deploy a Windows Service using ClickOnce? If so, how do you achieve this?
Currently we have to use a Deployment project, and the installation process could be simplified greatly by using ClickOnce.
AFAIK you can't really use ClickOnce end-to-end to deploy a service; there are issues with both the file locations (ClickOnce installs into a user's profile) and installation (ClickOnce is largely side-effect free).
You can, however, write a service as an exe that can self-install/uninstall from the services list, like so; basically, you write it as as a console exe and handle some command line args, using AssemblyInstaller to [un]install from the current assembly. Another advantage is that the same approach can be used to help debugging, since you can run it from the command line.
I guess NO according to Choosing Between ClickOnce and Windows Installer
Instead of ClickOnce, I like to use the approach using Inno Setup, like in here https://stackoverflow.com/a/1450051/396200
You have more control over what and how will be copied and executed.
As Marc Gravell said in his answer, I create a exe that self install my service, and then use Inno Setup to pack and deploy it. After Inno setup installed, it automatically run the exe and then my exe install my service.