Loading

Inno Setup for Windows service

windows service代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration.Install;
using System.Reflection;

namespace WindowsService1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {

            if (System.Environment.UserInteractive)
            {
                string parameter = string.Concat(args);
                switch (parameter)
                {
                    case "--install":
                        ManagedInstallerClass.InstallHelper(new string[] { 
                            Assembly.GetExecutingAssembly().Location });
                        break;
                    case "--uninstall":
                        ManagedInstallerClass.InstallHelper(new string[] { 
                            "/u", Assembly.GetExecutingAssembly().Location });
                        break;
                }
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] 
                { 
				    new WinServiceDemo()
                };


                ServiceBase.Run(ServicesToRun);
            }



        }
    }
}
inno setup 代码
[Run]
;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: nowait postinstall skipifsilent
Filename: {app}\WindowsService1.exe; Parameters: --install; 


[UninstallRun]
Filename: {app}\WindowsService1.exe; Parameters: --uninstall;
posted @ 2010-12-21 13:30  .net's  阅读(910)  评论(0)    收藏  举报