Install Program As Service Windows

  

Create Windows service from executable. Ask Question 270. Is there any quick way to, given an executable file, create a Windows service that, when started, launches it? Sc install service_name> binpath= sc stop service_name> sc queryex service_name> sc delete service_name. Software Engineering; Unix & Linux; Ask. The FireDaemon suite of software products allows you to create, manage, monitor, schedule and control FireDaemon and Windows services easily. FireDaemon Pro allows you to setup and run any third party or custom application program or script as a Windows service.

  1. Cannot Install Programs Windows 10
  2. Install Windows Programs On Mac
14 Jul 2003
A simple application to show how to create a Windows service.

Introduction

As a matter of fact Microsoft Windows services, formerly known as NT services enable you to create long-running executable applications that run in its own Windows session, which then has the ability to start automatically when the computer boots and also can be manually paused, stopped or even restarted.

This makes services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer. You can also run services in the security context of a specific user account that is different from the logged-on user or the default computer account.

Windows services don’t have any interface to the user, so it can not be debugged like any regular application, but it’s debugged as a process. .NET has a very nice tool that enables processes debugging while it’s in the run status, by easily pressing Ctrl + Alt + P shortcut.

Background

I’ve searched well so many sites about a code that I can with the help of it, build a simple Windows service, but I found a lot of code on how to manage the current Windows services of the system and that’s through the ServiceController class.

After searching the MSDN, I’ve found some nice code that helped me to create this simple Windows service. Hope it can help as a basic architecture for and usage of such a Windows service.

Using the code

At first you should simply open VS.NET and then at the File menu click on New, Project. From the New Project Dialog Box, choose the Windows service template project and name it MyNewService like shown below:

The project template automatically adds a component class that is called Service1 by default and inherits from System.ServiceProcess.ServiceBase.

Click the designer. Then, in the Properties window, set the ServiceName property for Service1 to MyNewService.

Set the Name property to MyNewService. Set the AutoLog property to true.

In the code editor, edit the Main method to create an instance of MyNewService. When you renamed the service in step 3, the class name was not modified in the Main method. To access the Main method in VC#, expand the Component Designer generated code region.

In the next section, you will add a custom event log to your Windows service. Event logs are not associated in any way with Windows services. Here the EventLog component is used as an example of the type of components you could add to a Windows service.

To add custom event log functionality to your service:

Install
  1. In the Solution Explorer, right-click Service1.vb or Service1.cs and select View Designer.
  2. From the Components tab of the Toolbox, drag an EventLog component to the designer.
  3. In the Solution Explorer, right-click Service1.vb or Service1.cs and select View Code.
  4. Edit the constructor to define a custom event log.

To access the constructor in Visual C#, expand the Component Designer generated code region.

To define what happens when the service starts, in the code editor, locate the OnStart method that was automatically overridden when you created the project, and write code to determine what occurs when the service begins running:

The OnStart method must return to the operating system once the service's operation has begun. It must not loop forever or block. To set up a simple polling mechanism, you can use the System.Timers.Timer component. In the OnStart method, you would set parameters on the component, and then you would set the Timer.Enabled property to true. The timer would then raise events in your code periodically, at which time your service could do its monitoring.

To define what happens when the service is stopped, in the code editor, locate the OnStop procedure that was automatically overridden when you created the project, and write code to determine what occurs when the service is stopped:

You can also override the OnPause, OnContinue, and OnShutdown methods to define further processing for your component. For the method you want to handle, override the appropriate method and define what you want to occur. The following code shows what it looks like if you override the OnContinue method:

Some custom actions need to occur when installing a Windows service, which can be done by the Installer class. Visual Studio can create these installers specifically for a Windows service and add them to your project. To create the installers for your service.

  1. Return to design view for Service1.
  2. Click the background of the designer to select the service itself, rather than any of its contents.
  3. In the Properties window, click the Add Installer link in the gray area beneath the list of properties. By default, a component class containing two installers is added to your project. The component is named ProjectInstaller, and the installers it contains are the installer for your service and the installer for the service's associated process.
  4. Access design view for ProjectInstaller, and click ServiceInstaller1.
  5. In the Properties window, set the ServiceName property to MyNewService.
  6. Set the StartType property to Automatic.

Tip

To avoid being asked about the system username and password you must change the Account for the serviceProcessInstaller to LocalSystem. This is done by opening the ProjectInstaller design and then selecting the serviceProcessInstaller, press F4 and then change the Account property to LocalSystem. Or you can manually do that by creating a class that inherits from System.Configuration.Install.Installer like this:

To build your service project

  1. In Solution Explorer, right-click your project and select Properties from the shortcut menu. The project's Property Pages dialog box appears.
  2. In the left pane, select the General tab in the Common Properties folder.
  3. From the Startup object list, choose MyNewService. Click OK.
  4. Press Ctrl+Shift+B to build the project.

Now that the project is built, it can be deployed. A setup project will install the compiled project files and run the installers needed to run the Windows service. To create a complete setup project, you will need to add the project output, MyNewService.exe, to the setup project and then add a custom action to have MyNewService.exe installed.

To create a setup project for your service

  1. On the File menu, point to Add Project, and then choose New Project.
  2. In the Project Types pane, select the Setup and Deployment Projects folder.
  3. In the Templates pane, select Setup Project. Name the project MyServiceSetup.

A setup project is added to the solution. Next you will add the output from the Windows service project, MyNewService.exe, to the setup.

To add MyNewService.exe to the setup project

  1. In Solution Explorer, right-click MyServiceSetup, point to Add, then choose Project Output. The Add Project Output Group dialog box appears.
  2. MyNewService is selected in the Project box.
  3. From the list box, select Primary Output, and click OK.

    A project item for the primary output of MyNewService is added to the setup project. Now add a custom action to install the MyNewService.exe file.

To add a custom action to the setup project

  1. In Solution Explorer, right-click the setup project, point to View, then choose Custom Actions. The Custom Actions editor appears.
  2. In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action. The Select Item in Project dialog box appears.
  3. Double-click the application folder in the list box to open it, select primary output from MyNewService (Active), and click OK. The primary output is added to all four nodes of the custom actions — Install, Commit, Rollback, and Uninstall.
  4. Build the setup project.

To install the Windows Service

Browse to the directory where the setup project was saved, and run the .msi file to install MyNewService.exe.

To start and stop your service

  1. Open the Services Control Manager by doing one of the following:
    • In Windows 2000 Professional, right-click My Computer on the desktop, then click Manage. In the Computer Management console, expand the Services and Applications node.

      - Or -

    • In Windows 2000 Server, click Start, point to Programs, click Administrative Tools, and then click Services.

      Note: In Windows NT version 4.0, you can open this dialog box from Control Panel.

  2. You should now see MyNewService listed in the Services section of the window.
  3. Select your service in the list, right-click it, and then click Start.

Right-click the service, and then click Stop.

To verify the event log output of your service

  1. Open Server Explorer and access the Event Logs node. For more information, see Working with Event Logs in Server Explorer.

    Note: The Servers node of Server Explorer is not available in the Standard Edition of Visual Basic and Visual C# .NET.

Cannot Install Programs Windows 10

To uninstall your service

  • On the Start menu, open Control Panel and click Add/Remove Programs, and then locate your service and click Uninstall.
  • You can also uninstall the program by right-clicking the program icon for the .msi file and selecting Uninstall.

Reinstalling a software program is one of the more basic troubleshooting steps available to any computer user after attempting automatic repair Windows problems, but it's often an overlooked step when trying to solve a software problem.

By reinstalling a software title, be it a productivity tool, a game, or anything in between, you replace all the program files, registry entries, shortcuts, and other files needed to run the program.

If whatever problem you're having with the program is caused by corrupt or missing files (the most common cause of software problems), a reinstall is very likely the solution to the problem.

The proper way to reinstall a software program is to completely uninstall it and then to reinstall it from the most updated installation source you can find.

Uninstalling and then reinstalling a program this way is really pretty easy but the exact method differs a bit depending on the Windows operating system you happen to be using. Below are instructions specific to each version of Windows.

See What Version of Windows Do I Have? if you're not sure which of those several versions of Windows is installed on your computer.

How to Properly Reinstall a Program in Windows

Install Windows Programs On Mac

  1. A quick way to open Control Panel in Windows 10 or Windows 8 is with Power User Menu, but only if you're using a keyboard or mouse. Choose Control Panel from the menu that appears after pressing WIN+X or right-clicking on the Start button.

  2. Click on the Uninstall a program link located under the Programs heading, or Add or Remove Programs if you're using Windows XP.

    If you're not seeing several categories with links below them, but instead just see several icons, pick the one that says Programs and Features.

    If the program you're planning on reinstalling requires a serial number, you'll need to locate that serial number now. If you can't find the serial number, you may be able to locate it with a product key finder program. A key finder program will only work if the program is still installed, so you must use it before uninstalling the program.

  3. Locate and click on the program you want to uninstall by scrolling through the list of currently installed programs you see on screen.

    If you need to reinstall a Windows Update or an installed update to another program, click on the View installed updates link on the left-hand side of the Programs and Features window, or toggle the Show updates box if you're using Windows XP. Not all programs will show their installed updates here but some will.

  4. Click the Uninstall, Uninstall/Change, or Remove button to uninstall the program.

    This button appears either on the toolbar above the program list when a program is selected or off to the side depending on the version of Windows you're using.

    The specifics of what happens now depends on the program you happen to be uninstalling. Some uninstallation processes require a series of confirmations (similar to what you may have seen when you first installed the program) while others may uninstall without requiring your input at all.

    Answer any prompts as best you can - just remember that you are wanting to completely remove the program from your computer.

    If uninstalling doesn't work for some reason, try a dedicated software uninstaller to remove the program. In fact, if you already have one of these installed, you may have even seen a dedicated uninstall button in Control Panel that uses that third-party program, such as the 'Powerful Uninstall' button when IObit Uninstaller is installed — feel free to use that button if you see it.

  5. Restart your computer, even if you're not required to.

    In my opinion, this is not an optional step. As annoying as it might sometimes be, taking the time to reboot your computer will help ensure that the program is completely uninstalled.

  6. Verify that the program you uninstalled has been fully uninstalled. Check that the program is no longer listed in your Start menu and also check to make sure that the program's entry in Programs and Features or Add or Remove Programs has been removed.

    If you created your own shortcuts to this program, those shortcuts will likely still exist but of course, will not work. Feel free to delete them yourself.

  7. Install the most updated version of the software available. It's best to download the latest version of the program from the software developer's website, but another option is to just get the file from the original installation disc or a past download.

    Unless instructed otherwise by the software documentation, any patches and service packs that might be available should be installed to the program after the reboot following the installation (Step 8).