当前位置: 首页>>代码示例>>C#>>正文


C# ServiceProcessInstaller.Uninstall方法代码示例

本文整理汇总了C#中System.ServiceProcess.ServiceProcessInstaller.Uninstall方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceProcessInstaller.Uninstall方法的具体用法?C# ServiceProcessInstaller.Uninstall怎么用?C# ServiceProcessInstaller.Uninstall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceProcess.ServiceProcessInstaller的用法示例。


在下文中一共展示了ServiceProcessInstaller.Uninstall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        /// <summary>
        /// Installiert einen Dienst.
        /// </summary>
        /// <param name="configuration">Die Konfiguration des Dienstes.</param>
        /// <param name="fileName">Der volle Pfad zur Konfigurationsdatei.</param>
        /// <param name="install">Gesetzt, wenn eine Installation ausgeführt werden soll.</param>
        private static void Install( RecordingServiceConfiguration configuration, string fileName, bool install )
        {
            // Create the service installer
            var service =
                new ServiceInstaller
                {
                    Description = "Generic Recorder / Tuner Service based on JMS Argus TV SDK",
                    DisplayName = configuration.Name + " (Argus TV Recorder)",
                    ServiceName = CreateServiceName( configuration ),
                    StartType = ServiceStartMode.Manual,
                    Context = new InstallContext(),
                };

            // Create the process installer
            var process =
                new ServiceProcessInstaller
                {
                    Account = ServiceAccount.LocalService,
                    Context = service.Context,
                };

            // Link together
            process.Installers.Add( service );

            // Create service path
            var exePath = "\"" + new Uri( Assembly.GetExecutingAssembly().CodeBase ).LocalPath.Replace( "\"", "\"" ) + "\"";
            var configPath = "\"" + fileName + "\"";

            // Configure service path
            process.Context.Parameters["assemblypath"] = exePath + " " + configPath;

            // Create state
            var pathToState = fileName + ".install";
            var serializer = new BinaryFormatter();

            // Try it
            if (install)
            {
                // Create the state
                var state = new Hashtable();

                // Do the installation
                process.Install( state );

                // Save the state
                using (var stateFile = new FileStream( pathToState, FileMode.Create, FileAccess.Write, FileShare.None ))
                    serializer.Serialize( stateFile, state );
            }
            else
            {
                // Load the state
                using (var stateFile = new FileStream( pathToState, FileMode.Open, FileAccess.Read, FileShare.Read ))
                {
                    // Reconstruct the state
                    var state = (Hashtable) serializer.Deserialize( stateFile );

                    // Do the installation
                    process.Uninstall( state );
                }

                // Done
                File.Delete( pathToState );
            }
        }
开发者ID:JMS-1,项目名称:SDK-for-ArgusTV-Recorder-Development,代码行数:70,代码来源:Program.cs


注:本文中的System.ServiceProcess.ServiceProcessInstaller.Uninstall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。