I have created an installer which installs windows service. I have used Visual studio default installer in VS 2010.
The service will access and write on the database file(SQLite) present in the installation folder.
During uninstall when the service is stopped or running, the service is uninstalling without any error.
But if the installer is migrated from version 1 to 2, and the service of previous version is running then"The file is being accessed by some application. Try again" error has been shown, since the previous installation service accessing the DB file.
So I need to stop the previous version service before Installing new version.
I have a custom action script for managing install and uninstall.
In BeforeInstall method I have written code to stop the service using ServiceController. That can stop the service.
ServiceController service = new ServiceController("SERVICE_NAME");
if (!(service.Status.Equals(ServiceControllerStatus.Stopped)))
{
service.Stop();
service.WaitForStatus (System.ServiceProcess.ServiceControllerStatus.Stopped);
}
But even before BeforeInstall method the installer is copying new version files replacing my previous version files.
I always have same installation folder.
So if I write code to stop the service in BeforeInstall custom Action it will still throw error, because the DB file being accessed by previous version service was tried to delete by new version.. So I am getting "The file is being accessed by some application. Try again".
So I need some hook even before the installer copies the files to the installation folder. So that I can stop the service before the installer try to update the Db file.
Any idea would be appreciated.
Windows Installer doesn't have a concept of "before install". This is a Visual Studio Setup and Deployment project abstraction. This project type failed to expose many underlying Windows Installer features and this is why Microsoft eliminated it in VS2012.
Another concept that isn't exposed is the ServiceInstall and ServiceControl tables. This is why you are being forced to write custom actions. Custom actions that are hosted in such a way ( beyond your control ) to tattoo the MSIEXEC process with a CLR version and throw modal 1001 exceptions (even during silent installation) when there is a problem.
But there is a solution. Switch to a better tool such as free and open source Windows Installer XML (WiX) and Industrial Strength Windows Installer XML (IsWiX). With these tools you can create a windows service, create the installer for it and test the install/uninstall on a VM in 10 minutes. Watch my silent demo at:
Building and Deploying a Windows Service using IsWiX
Related
I have a wpf desktop application (ERP) system
Application is using setup and deployment to create the .exe file
Now, i want to create a window service for my application to do some background check ups , synchronizations with my database etc.
I know how to create a service in.net and how manually to install it following the examples online.
My question is how i can install (or include let's say) this service within my .exe setup.
I don't want the user to be responsible to install the service.
Neither me to login every time someone pc to install the service
Not sure if i misunderstood the purpose of service but i found nothing online related to my question.
You can use Microsoft Visual Studio Installer Projects and include your service/main project at the same time
https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2017InstallerProjects
I have created windows service project (WinService.exe) using C#. Also I added installer capability with the project(ProjectInstaller.cs) as per the below guide from Microsoft:
https://learn.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer
Now, when I performed install and uninstall using installutil.exe, my windows service project adds the service into services panel and removes from it appropriately.
As I want to deploy this service into remote machine, I created windows installer project(DeployService.msi) using VisualStudio 2015 as a service deployment project. Also, I configured custom action for Install, UnInstall, Commit and Rollback targeting primary output as WinService project.
When I perform installation using this installer, the service gets added into services panel and ApplicationFolder copies all binaries required for service. But, when I perform uninstall, ApplicationFolder binaries are removed but it leaves a InstallState file i.e WinService.InstallState. IMPORTANTLY, the service is not removed from services panel.
Any help here to remove service from services panel via windows installer?
I have tried adding event handler for ServiceProcessInstaller and noticed that OnBeforeUninstall() and OnAfterUinstall() are never called by windows installer due to some reason. At same time, I noticed OnBeforeInstall() and OnAfterInstall() are called. This is main reason why windows service was not uninstalled in my case.
When I tried overriding ProjectInstaller (derviced from Installer) class methods:
protected override void OnBeforeUninstall(IDictionary savedState);
protected override void OnAfterUninstall(IDictionary savedState);
I observed windows installer calls these methods appropriately and I have written appropriate methods to remove windows service there.
You can try to execute the next command when you execute the uninstall of the application, which removes the service with the exact name (you can try it using the CMD):
sc delete “serviceName”
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?
I have made a Windows Service that reads an excel sheet and updates the values in database. The service just works fine when I install it from the visual studio command prompt.
I have also made an exe file using the other projects option in Visual Studio. When I install that the exe I made, I cannot see my service in services panel of control panel=>System and Security=>Administrative tools=>Service.
I've run into similar issues with production services I've made.
Carefully follow the solution as described here:
http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx
Note that the key is creating the "installer" service class in the service project. This creates the output you will have the MSI "install" and will specify what account will be used to run the service, etc.
Actually I want to run exe file(My Job.exe) Through window Service in C# but window service should be started automatically when I start the Computer?
I have already added Window Service (MyService) manually. I have also setup project of My application where I also added this service so that I can also be installed when I install my Application.
I have serviceInstaller1 with property
StartType=Automatic;ServiceName=MyService.
I also have serviceProcessInstaller1 with Property
Account=LocalSystem;
When I run this my Applicationo gets installed but MyService don't get installed and I also not see it in Service of Computer Management.
Could any body please help me I already spend two days on it but not finding proper guidline. thanks in Advance.
How is your application being installed? Did you create an installer (.msi file) for it? It sounds like you're trying to implement your own installer instead of using existing tool to do this.
I recommend Advanced Installer. It is a very powerful installer generator and has all the features you need in the free version, and more importantly, it's very easy to use. This tool lets you create an install wizard with the ability to patch and uninstall your software (including services, registry values, files, etc).
I recently have one project with windows service in VS2010 and .Net 4.5 and user OS will be Windows Server 2008. I was unable to create fully functional installation a long time, and still i dont have, but request are changed so no need for installation file. But i can give you advice "How to do".
If you don't have purchased version of InstallShield you need to find some other program for creating installation file.
For installation you need just to copy you .exe output of service and one batch file witch will have next content:
#ECHO off
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "%~dp0%<filename>.exe"
pause
and then you need to run with administration rights this batch file.
Both files (.exe and .bat) must be in same folder.
You can delete pause command but then you will not see if registration of service was successfully.
Make sure that you have installed target .NET Framework on PC.
I hope that this will help you.
If you just need to run your exe file(My Job.exe) when the system starts up you could add your exe to the Windows Task Scheduler.
Is there any specific purpose for using a Windows service?
The reason that I am saying this is that you have a wide variety of options to invoke you exe as follows
Schedule based on common recurring events, i.e. When the computer starts or When a user logs on.
Schedule based on the calendar, i.e. Daily, Weekly, Monthly, or One time.
Advanced options like execution based on events, etc.