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.
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
At the moment I have a Windows Service and App (Desktop Tray Win Form App with Stop/Start buttons to stop the service and a PING to check the 3rd party API it uses it working and obtain the current balance - It's a Betfair Betting app)
At the moment I am running this off my Win 7 64 bit Desktop but we are moving to a dedicated server Win 2012.
Both the Win Service/Form are in the same project and they reference a DLL which I made that has all the code inside (connects to the DB, 3rd party Betfair API, gets runner/winner info, renews session info etc).
The Windows Server does NOT have Visual Studio on it.
Can I just copy my DLL up to the server, put it in Windows/System32 and Regsvr register it and then copy the .EXE for my Form and Service up to the server?
Also without having the VS Toolset to register a Win Service on a machine what commands do I need to run to install the Windows Service on the Server.
These are 2 distinct solutions, one with the DLL code, one with the Service Project and Win Form Project.
I just want to know the best/quickest/easiest/proper way of getting it to work on the new server without having VS on it to register the service.
Can I just copy the code up to a folder (should it go in a specific folder on the server - the log files are piped out into it's own sub folder of /programdata) and run installutil [PATH TO EXE] to install the Service or is there something more I need to do.
As there are two solutions I can't (or don't know how to) create a deployment package with all the right links and references in across solutions.
However should it be more complicated than..
-Copy DLL to System32
-Regsvr my DLL
-Build the service/win form project on my computer then copy the .EXEs up somewhere
-Run installutil [PATH TO EXE] to register the service
-Double click the windows form to open it (should auto start on reboot and sit in desktop tray)
All in .NET 4.5, Was built in vs 2012, 64 bit, C#
Thanks for any help in advance
Creating a deployment package is the better option, but, because it's not a option for you, the regsvr32 and installutil option should do the job.
Hope it helps!
i am new to windows services. please help me to know is Project installer Mandatory for Windows service or why do we need project installer. can we create and install windows service into system without project installer.
thanks,
If you're talking about the ProjectInstaller.cs file that's added to your service project if you're looking at the Service and choose "Add Installer...", then yes, it's required.
It creates two components - a ServiceProcessInstaller and a ServiceInstaller. Together, these components contain important information that is required to install a service - such as what account the service should run under (such as Local System, Local Service, Network Service or an actual user account), metadata about the service, and information about how the service should be started.
I think that DinosaurTom's answer was assuming you were talking about an installer project, a separate project in the solution that would create a setup/MSI file. It is exactly the two above mentioned components that tools such as InstallUtil or a Setup Project actually interact with to perform installation.
No, it is not mandatory. However it could be useful when installing on many maschines.
We can create a Windows Service without Project Installer. For example, like in this post Install a Windows Service using a Windows Command Prompt
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
I've created a windows service in c# and I'm trying to install it for debug using the installutil as recommended here: http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx
The installutil says Install completed. However, nothing appears in the service control manager.
I've tried this on Server 2008 and XP with the same result.
Any ideas?
A colleague of mine had a more or less identical problem.
Did you add an installer to your project? For the service to be installed you need to add an installer to your Visual Studio Project.
The easiest way to add an installer in Visual Studio is to open your service in Design Mode and right click the design area and select Add Installer. This will add a file ProjectInstaller.cs with itself contains a ServiceInstaller object and a ServiceProcessInstaller object.
With the installer added you can set the Service Name, Description and other options that will be used when installing the service. If you now try to use InstallUtil your service should be installed and should show up in the Services list.
I had a similar issue (build installer, no errors, no service appears in services.msc) but a different solution, as I had configured the installers.
In my case, the Service-project's Application Properties (Alt-Enter, Application-tab) Startup object was (not set) as shown below:
Picking the default .Program and rebuilding service and installer worked (service appeared in services.msc).
Setting this property is one of the steps in the MSDN service installer walkthrough referenced in this SO answer. Make sure to follow all of the steps!
I can't speak specifically to any issues that are the fault of C# or .NET, but I have a writeup of what has to happen for a service to be installed and work in the form of an extensively documented framework (source code included) for writing services in Lua. I offer it up here as an example of another way to do it, because sometimes just seeing things from another point of view can be helpful.
Disclaimer: It is very much at an alpha quality level, and yes, I am its author.
The framework has all the code needed to interact with the Windows SCM to install and remove the service.