windows service & updating c# console app - c#

I have a windows service that executes a console app every hour and it's running with no problems. I didn't set this up though, and I'm not familiar with windows services at all.
Today I had to update the console app, so I presumed that if I just copied the exe file back into the folder were it was called from the windows service after I modified it it would be fine. But it looks like it stopped working.
I ran the console app mannually from the command prompt and it works fine though.
Any ideas on why this could have stopped working?
Thanks

first try to stop/start your service, then
try to uninstall and install your service again
you can do the first thing in administrative tools/services
install/uninstall with installUtil

Related

How to create a windows service for an executable application?

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>"

Creating a windows service to run a Visual Studio solution

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

C# application crashes in Windows CE

I have some console C# application, which is working on Windows CE environment. This application start the other main application.This part is working. But also it have to detect when/if main application crash and in this case restart main application. Is there any way to detect application crash by program?
Thanks, Slava.
I have found the solution, which is pretty match to my needs.I just put the application to \Windows\StartUp folder and that is it. After restart all applications in StartUp folder are coming up,including MyApp.

Installing a Windows Service -Setup.exe fails

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.

C#: Running and Debugging a Windows Service

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.

Categories