當前位置: 首頁>>代碼示例>>C#>>正文


C# ServiceProcessInstaller.Install方法代碼示例

本文整理匯總了C#中System.ServiceProcess.ServiceProcessInstaller.Install方法的典型用法代碼示例。如果您正苦於以下問題:C# ServiceProcessInstaller.Install方法的具體用法?C# ServiceProcessInstaller.Install怎麽用?C# ServiceProcessInstaller.Install使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ServiceProcess.ServiceProcessInstaller的用法示例。


在下文中一共展示了ServiceProcessInstaller.Install方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Install

        public static void Install(Type exeType, IEnumerable<OpenService> services, string username, string password)
        {
            var spi = new ServiceProcessInstaller
                          {
                              Account = string.IsNullOrEmpty(username) ? ServiceAccount.LocalSystem : ServiceAccount.User,
                              Username = username,
                              Password = password,
                              Context = new InstallContext("install.txt", new string[0])
                          };

            spi.Context.Parameters["assemblypath"] = exeType.Assembly.Location;
            
            foreach (OpenService service in services)
                service.AddInstaller(spi);

            spi.Install(new Hashtable());
        }
開發者ID:anddudek,項目名稱:anjlab.fx,代碼行數:17,代碼來源:OpenService.cs

示例2: 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.Install方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。