I've been working to update a C# service with a new Visual Studio 10 Installer. The old installer is a batch based installer that is a pain to use with Windows 7 and higher, but still works correctly (for both install and uninstall).
I created the new Visual Studio Installation project using this as my guide.
The solution includes a small application used to show the service status in the tray. It's output is added to the installation project and included in all of the custom actions alongside the service.
The service installs and runs correctly with my new installer, but uninstall causes a happy little blue screen of death. The dump shows the crash is coming from ntoskrnl.exe+22fa3 (Critical_Object_Termination).
What methods can be used to track down a crash that occurs during uninstall?
If the service can be stopped, then there is something really aweful in your custom action. Custom actions shouldn't be needed in the first place so try this tutorial instead.
Related
OK, I have never made a windows service before so sorry if this question seems a bit dumb. I currently have a windows form application with a few buttons that perform certain operations. When the buttons have been clicked these operations currently would run infinitely using a timer that i set up.
I want to set this up as a windows service, but do not really know how to. There are a lot of examples of creating a service as another project, but is this what I want or can i include it within my existing project? How would i take the process of actually having to click on these buttons once and placing that within the service?
I would highly recommend creating a Console Application to run your service, and then use TopShelf.
This will enable you to run your application easily for debugging by just launching your Exe and you can write all your debug messages to the Console window, but it has built in code to allow you to install your Exe as a windows service and will use the same code.
You can read more about Topshelf at http://docs.topshelf-project.com/en/latest/overview/index.html.
Create a new Console Application Project.
Add the Topshelf Nuget package
There is a good example of a simple program and how to wire it up at http://docs.topshelf-project.com/en/latest/configuration/quickstart.html
When you have finished, you can just launch and debug your application as a console app from inside Visual Studio or from the built executable.
When you are happy that your program is working as expected, you can then install your executable as a windows service
Copy your built code into a location where you want to run your service from permanently. eg C:\MyService
Open a Command Prompt (With Administrative Privilages)
Change directory to your Service Directory (Eg. C:\MyService)
Install your service, using the following. MyService.exe install
There are several options you can pass for installing your service, which you can find here. http://docs.topshelf-project.com/en/latest/overview/commandline.html
You should try to use Topshelf in your C# application. It is really easy to use and well documented. When you add this nuget package into you project and configure it in C# code, then simple command
you_app.exe -install
is everything you need. For more details please have a look here:
http://topshelf.readthedocs.org/en/latest/index.html
http://topshelf.readthedocs.org/en/latest/configuration/quickstart.html
How-To create a C# Windows-Service with Topshelf Console-Application
Steps:
Start Visual Studio and create a new C# Console-Application
Right click on references and go to manage NuGet-Packages
Download and install Topshelf via NuGet
Paste the
Code below into your application and include all imports.
Switch from “Debug” mode to “Release” and build the application.
Run cmd.exe as administrator
Navigate the console to
“.\myConsoleApplication\bin\Release\”
Run the command
“.\myConsoleApplication.exe install”
Run the command
“.\myConsoleApplication.exe start”
Code: http://pastebin.com/BAFH27wB
I have a GUI based windows application which is an .exe application(TestServer.exe )application. Now I need to add a windows service to this project solution.
So the solution would then build two executables. The first is the one it is currently building using the UserApplication; MyTestServer.exe
The second would be the new Windows Service; MyTestservice.exe.
Both would share the MyTestServerLibrary and our 3rd party dlls.
How can i do that in C# - Visual studio 2010?
As #nvoigt said, you simply add another project to your solution. If you'll right-click on your solution in the Solution Explorer window, select the Add|New Project... menu option. In the resulting dialog, select the Windows Service project type, give it a name, and press OK. Note that this step assumes you have one of the paid versions of Visual Studio 2010. My recollection is that the Windows Service project type is not delivered with the Express version.
From there, you simply build out your Windows service project just like you would any other project. If you've never done this before, I've got a set of instructions for how to do this here. The instructions target Visual Studio 2008 (I really need to update it...), but they are practically identical for Visual Studio 2010.
At this point, when you build your project, you'll get your TestServer.exe, any other C# assemblies that are part of your solution, and the newly-added Windows service executable. By default, running the Windows service directly from the Visual Studio debugger won't work for two reasons. First, your solution probably has TestServer.exe marked as the startup project, which simply means that when you press F5 to start debugging, the TestServer.exe will be run. But even if you change the startup project to be the new Windows service, it still won't work because services don't start the way normal Windows applications do. To get around this, you can look at the instructions here for how to have your Windows service operate in an "interactive" mode, which will let you debug it like any other application. For my purposes, though, I prefer to debug my Windows service when it's actually running as a Windows service. To do this, just put a call to System.Diagnostics.Debugger.Launch() in the constructor for your Windows service. Providing you are an administrator on your system, this will give you the opportunity to jump into a debug session when you start the service from the Services console.
This leads directly to the point of installing the service. To actually run a Windows service, it has to be installed on the system. For .NET-based Windows services, you can use the Microsoft-provided InstallUtil.exe to do this. If you open the Visual Studio command prompt from the Start menu, it's available in the directory path. I prefer the solution that Marc Gravell suggested to have the Windows service install/uninstall itself. I've got a set of instructions for how to do that here.
That should get you started. There are many good answers regarding Windows services on SO, so if you get stuck, be sure to search for it on this site. HTH.
I have created a win form application in c# with sqlce. I followed the steps here http://erikej.blogspot.dk/2013/10/sql-server-compact-4-desktop-app-with.html making some tweaks along the way since I was using sqlce 3.5 .net and that blog was talking about 4.0 .net.
When I finished the application, I created a set up project and build it which gave me an msi and setup file.
Now when I run this set up on my own machine where I developed the applicaton, it works a charm.
I tried it on a friend's machine as well, it worked well, he had visual studio 2010 as well on his machine.
Now when I tried it on 2 other machines with VS, after installation, on launching the exe, it launches and immediately closes, I do not see anything although.
I know it launches as i look at processes from my task manager it shows it in there for like 3-4 seconds and its gone.
I tried using this Not able to run the .exe file created from c# where i wrapped the try and catch around all the code inside the root win form but no text file was created with any errors.
On doing some research, it says it could be because I am missing some dll's, how do i make sure all the dlls from the references would be copied into the project ? I set all dll's to true for copy local.
Is this something else and not related to dlls?
I really just want to be able to install the application on any machine without any problems.
Thank you for your time.
EDIT
I need to add that this was a project that involved using an XBox controller sending data to a wireless receiver that was hooked to a PC. I used the XNA framework to intercept these and display some form of output on the Win Forms.
When packing and installing/deploying an application that makes use of the XNA DLLs on another non developer machine, the XNA framework needs to be installed.
My solution was packing my application along with the xna installer and so the xna framework installs as a prerequisite and then my application installs and then it no longer crashes.
Thanks to mrlucmoring and Mark for their support and troubleshooting.
I've to create a service in Visual Studio for one customer.
The customer IT service indicate me that they don't want any installer, only one exe that can be installed with instsrv.exe.
So I created a Service project on VS2010, compilated it(in 64 bits, it's an application that has to be ran in 64bits).
First problem: I didn't found any instsrv.exe, so I used InstallUtil.exe, the 64 bits version :
C:\Windows\Microsoft.Net\Framework64\v4.0.xxxx\InstallUtil.exe "PathToMyGeneratedExe"
It says me that "The commit phase completed successfully." and "The transacted install has completed.".
So I assume that the install completed successfully.
But if I go in the service console, I can't find the created service.
So what am I missing?
InstallUtil is intended for usage with a service installer (which is really easy to make, but a bit buried) I imagine your client wasnt after a gui installer but I think it may be worth your while putting in the base serviceinstaller.
Normally InstallUtil will also prompt for a user to run the service under as well. if you havent got this you probably arent installed
Take a read of http://arcanecode.com/2007/05/23/windows-services-in-c-adding-the-installer-part-3/ for details of how to do this
(TLDR right click on your service design surface and add installer)
I am currently building a Windows Service with C# and I just can't figure out how to debug it.
I am building it and then registering with installutil:
> installutil MusicRepo_FileMonitor.exe
The Commit phase completed successfully.
The transacted install has completed.
And as you can see above, it is supposedly being registered successfully, but I can't find it in services.smc. I have also tried starting the service with net start [ServiceName] but it's telling me The service name is invalid. so I guess it's not finding it.
For the record, I'm on Vista and I'm developing the ws with .Net 3.5
[Update]
Solution
Try Task Manager and see if you see MusicRepo_FileMonitor.exe. If not, then the service is definitely not running.
Alternatively, in Visual Studio, Debug > Attach to Process, check show processes from all users, and see if its there.
Upon further research, I realized that I had no Installer attached to the service, so the problem was now fixed by adding an Installer.
Here is the tutorial I used to add a Service Installer and so on.