C# - How to Create a Setup Project to Deploy Windows Services - Part 3/3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well hello youtubers so let's continue with a series and talk about how to add a set up project to your Windows service a solution so then you can go through a automatic installation process you don't have to do it manually so the first thing you want to do is to add the set of project and for that go to solution right click and then add new project and then in here most likely you will be under Visual Studio and the way to get to this set of projects to go to other project types and go to Vizier's to the Installer and in there you have the setup project I'm going to call this the windows service setup and click OK and the first thing that we want if you don't have this tab open if you don't have the file system tab open what you want to do is to select the window service project and then right over here on the top so if I don't have a selected selected windows service project and right here at the top you have a series of icons the first one is the file system editor go ahead and click that so then you can have that tab open under application folders right click application folders and add new project output and in here you'll be able to see under this a project drop-down you have a list of all the projects in this case we're only looking for the window service one select primary output and click OK ok so now we have our primary output in the windows service setup and at this point and you're pretty much you're pretty much ready it's going to create the files into local directory but the problem is that we actually want to start after so one thing that we want to do we actually want to install into the machine so this is going to actually put in the directory and now we have to install it and for that we go under the custom actions editor so I'm going to click in here and under install I'm going to right click add custom action double click the application folder and then choose the primary output so you have to take da first step first the file system first before you come to the custom action I'm going to do the same thing for the uninstall so when the application onion stalls it also it's also going to uninstall the service out of the computer now it's ready going to go ahead and save it close both of these under setup you have several options you can add the default company name you can change the name of your product in here there are several things that you can do and actually this is going to be used in the path I'm just going to leave everything as default let's double check our program ok you definitely want to make sure that this is not under debug especially well especially because we're using the debug a directive so change it to release and now you can see that this is the snippet of code that's going to be cheetah used I'm not I'm not sure if you work on the debug I haven't tested but anyways changed to release so that's you're in safe place and now let's see do we have anything else service project installer I have it under the local system account and service installer they start type they start type change it from manual to automatic and what this is going to do is that when you stall it under automatic whenever the user restarts the computer on during the boot up time your service is going to start automatically ok so now we have it all done save it right-click and build and this takes a little longer than this this small window service app but not that much longer so build succeed it let's look at the Windows Explorer in here so open folder in Windows Explorer and we're under release and I'm going to click setup now this is the dialog window that comes up and though this looks a little funny welcome to Windows service set up set up yeah definitely you definitely want to change this name that's the name that is under here right we called it the Windows service set up but anyways just testing click Next and this is the location where it's going to add so default company name if you change the default company name to something else then it would be reflected in here and then if you change the Windows service setup to be something else then you would be reflected in here as well I'm going to copy this path because I want to open this up later click Next Next and then the window account the user account control comes up I'm going to click yes that an installation is completed now let me go ahead and navigate to that location and as you can see I have the Windows service in here and now when I go to the task manager and services in here I'm going to open my services if we navigate all the way to the bottom you can see that the YouTube Windows service test is now installed and but he hasn't started is not running and that's because automatic does not necessarily mean running it just means that when the computer starts that's when it's going to start automatically but I'm going to right-click and click start here just make sure that it starts just fine and you can see it's running we when we go back to our folder you can see that we have the unstart file that we that's supposed to create when it starts so that's great great news and then going back to it and go ahead and just make sure that it fits in here going back to I'm going to stop the service right click and stop the service and then you can see that he creates the on stop file in there just to prove that the service started and stopped just fine now if you want to start the service immediately after the install then there's one more step that we have to take in and I'm going to show you how I'm going to show you how to do that I'm going to right click the windows service set up in here I'm going to I'm going to any stall okay so I just uninstalled the service and in the service installer when you go to events in here you have a after install so I'm going to double click the after install and that's going to create a function for us in here and in here I'm gonna say new service controller surface controller and then it's going to be see I have this limit of code here it's going to be the service installer that service name dot start that should take care of that for us so let's make sure save go ahead and rebuild the solution is this rebuild make sure that is rebuild so let's build that and let me open so I uninstall that I just want to make sure that those files are not in there okay so as you can see this location now has no files I'm just going to put it to the side here real quick and now I'm going to install you can stall it from here well let's let's do the same thing I did earlier right so it's building right now and now let's open folder location release setup now going to the same setup we went earlier this is the location where it's going to install and click close now when you open you can see that it started automatically so test manager services open services and if we go all the way to the bottom now you can see that we have our tubo YouTube Windows service and it's running now so if that's what you want to do then that's the way to accomplish that I should have stopped it so I'm just go ahead and do that really quick right click and stop and now it's been stopped because we have the on stop file in there I hope this was it educational next we're going to actually I'm not sure what the next step is just follow the link handi here on the video thanks for watching but
Info
Channel: Programming with Fabio
Views: 190,041
Rating: 4.9520001 out of 5
Keywords: C#, How to deploy Windows Services
Id: cp2aFNtcZfk
Channel Id: undefined
Length: 9min 13sec (553 seconds)
Published: Tue Nov 20 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.