static void Main(string[] args) { string opt = null; if (args.Length >= 1) { opt = args[0].ToLower(); } if (opt == "/install" || opt == "/uninstall") { TransactedInstaller ti = new TransactedInstaller(); MonitorInstaller mi = new MonitorInstaller("OPC_FILE_WATCHER"); ti.Installers.Add(mi); string path = String.Format("/assemblypath={0}", Assembly.GetExecutingAssembly().Location); string[] cmdline = { path }; InstallContext ctx = new InstallContext("", cmdline); ti.Context = ctx; if (opt == "/install") { Console.WriteLine("Installing"); ti.Install(new Hashtable()); } else if (opt == "/uninstall") { Console.WriteLine("Uninstalling"); try { ti.Uninstall(null); } catch (InstallException ie) { Console.WriteLine(ie.ToString()); } } } else { ServiceBase[] services; services = new ServiceBase[] { new OPCDataParser() }; ServiceBase.Run(services); } }
/// <summary> /// 安装服务。 /// </summary> /// <param name="fileName">文件名称</param> /// <param name="args">命令行参数</param> public static void InstallService(string fileName, string[] args) { TransactedInstaller transactedInstaller = new TransactedInstaller(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(fileName, args); transactedInstaller.Installers.Add(assemblyInstaller); transactedInstaller.Install(new System.Collections.Hashtable()); }
/// <summary> /// 安装服务 /// </summary> private void btnInstall_Click(object sender, EventArgs e) { if (!Vaild()) { return; } try { string[] cmdline = { }; string serviceFileName = txtPath.Text.Trim(); string serviceName = GetServiceName(serviceFileName); if (string.IsNullOrEmpty(serviceName)) { txtTip.Text = "指定文件不是Windows服务!"; return; } if (ServiceIsExisted(serviceName)) { txtTip.Text = "要安装的服务已经存在!"; return; } TransactedInstaller transactedInstaller = new TransactedInstaller(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline); assemblyInstaller.UseNewContext = true; transactedInstaller.Installers.Add(assemblyInstaller); transactedInstaller.Install(new System.Collections.Hashtable()); txtTip.Text = "服务安装成功!"; } catch (Exception ex) { txtTip.Text = ex.Message; } }
public SpHostServiceInstaller(HostSettings settings, HostConfigurator configurator) { _hostConfigurator = configurator; _installer = CreateInstaller(settings); _transactedInstaller = CreateTransactedInstaller(_installer); }
/// <summary> /// UnInstalls the Windows service with the given "installer" object. /// </summary> /// <param name="pi"></param> /// <param name="pathToService"></param> public static void uninstallService(Installer pi, string pathToService) { TransactedInstaller ti = new TransactedInstaller (); ti.Installers.Add (pi); string[] cmdline = {pathToService}; InstallContext ctx = new InstallContext ("Uninstall.log", cmdline ); ti.Context = ctx; ti.Uninstall ( null ); }
/// <summary> /// Installs the Windows service with the given "installer" object. /// </summary> /// <param name="installer">The installer.</param> /// <param name="pathToService">The path to service.</param> public static void InstallService(Installer installer, string pathToService) { TransactedInstaller ti = new TransactedInstaller(); ti.Installers.Add(installer); string[] cmdline = { pathToService }; InstallContext ctx = new InstallContext("Install.log", cmdline); ti.Context = ctx; ti.Install(new Hashtable()); }
public void Install() { _logger.Log(Tag, "Installing service {0}", ServiceName); using (var ti = new TransactedInstaller()) { SetInstallers(ti); ti.Install(new Hashtable()); } }
public void Uninstall() { _logger.Log(Tag, "Installing service {0}", ServiceName); using (var ti = new TransactedInstaller()) { SetInstallers(ti); ti.Uninstall(null); } }
public void StartForeground(string[] args) { if (args.Length > 0) { switch (args[0]) { case "/install": case "-install": case "--install": { var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Barcodes"); if (args.Length > 1) { directory = Path.GetFullPath(args[1]); } if (!Directory.Exists(directory)) throw new ArgumentException(String.Format("The barcode directory {0} doesn't exists.", directory)); var transactedInstaller = new TransactedInstaller(); var serviceInstaller = new ServiceInstaller(); transactedInstaller.Installers.Add(serviceInstaller); var ctx = new InstallContext(); ctx.Parameters["assemblypath"] = String.Format("{0} \"{1}\"", Assembly.GetExecutingAssembly().Location, directory); transactedInstaller.Context = ctx; transactedInstaller.Install(new Hashtable()); Console.WriteLine("The service is installed. Barcode images have to be placed into the directory {0}.", directory); } return; case "/uninstall": case "-uninstall": case "--uninstall": { var transactedInstaller = new TransactedInstaller(); var serviceInstaller = new ServiceInstaller(); transactedInstaller.Installers.Add(serviceInstaller); var ctx = new InstallContext(); ctx.Parameters["assemblypath"] = String.Format("{0}", Assembly.GetExecutingAssembly().Location); transactedInstaller.Context = ctx; transactedInstaller.Uninstall(null); Console.WriteLine("The service is uninstalled."); } return; default: if (args[0][0] != '/' && args[0][0] != '-') throw new ArgumentException(String.Format("The argument {0} isn't supported.", args[0])); break; } } OnStart(args); Console.ReadLine(); }
private TransactedInstaller InitializeInstaller(Dictionary<string, string> parameters) { SetupParameters(parameters); var ti = new TransactedInstaller(); var ai = new AssemblyInstaller(Path.Combine(_sourcePath, _serviceExecutable), _parameters); ti.Installers.Add(ai); var ic = new InstallContext("Install.log", _parameters); ti.Context = ic; return ti; }
static void Main(string[] args) { // 运行服务 if (args.Length == 0) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Servicesqlbackup() }; ServiceBase.Run(ServicesToRun); } // 安装服务 else if (args[0].ToLower() == "/i" || args[0].ToLower() == "-i") { try { string[] cmdline = { }; string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location; TransactedInstaller transactedInstaller = new TransactedInstaller(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline); transactedInstaller.Installers.Add(assemblyInstaller); transactedInstaller.Install(new System.Collections.Hashtable()); } catch (Exception ex) { string msg = ex.Message; } } // 删除服务 else if (args[0].ToLower() == "/u" || args[0].ToLower() == "-u") { try { string[] cmdline = { }; string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location; TransactedInstaller transactedInstaller = new TransactedInstaller(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline); transactedInstaller.Installers.Add(assemblyInstaller); transactedInstaller.Uninstall(null); } catch (Exception ex) { string msg = ex.Message; } } //以窗口方式运行服务 else if (args[0].ToLower() == "/f" || args[0].ToLower() == "-f" || args[0].ToLower() == "/form" || args[0].ToLower() == "-form") { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }
public void Install() { using (var installer = new TransactedInstaller()) { SetInstallers(installer); // There is a bug in .NET 3.5 where the image path will not be escaped correctly. installer.Context = new InstallContext(null, new[] { "/assemblypath=\"" + Process.GetCurrentProcess().MainModule.FileName + "\" " + _configuration.CommandLineArguments }); installer.AfterInstall += ModifyImagePath; installer.Install(new Hashtable()); } }
protected void Register() { using( var transactedInstall = new TransactedInstaller() ) { transactedInstall.Installers.Add( Installer ); if ( ENTRY_ASSEMBLY != null ) { transactedInstall.Context = new InstallContext( null, CommandLine ); transactedInstall.Install( new Hashtable() ); } } }
public void SetUp () { Installer[] ins; ins = new AssemblyInstaller[3]; ins[0] = new AssemblyInstaller (); ins[1] = new AssemblyInstaller (); ins[2] = new AssemblyInstaller (); ti = new TransactedInstaller (); ic = ti.Installers; ic.AddRange (ins); }
internal static void installService() { ServiceInstaller serviceInstaller = null; ServiceProcessInstaller serviceProcessInstaller = null; Installer projectInstaller = null; TransactedInstaller transactedInstaller = null; try { serviceInstaller = new ServiceInstaller(); serviceInstaller.ServiceName = "OpenVPNManager"; serviceInstaller.StartType = ServiceStartMode.Automatic; serviceProcessInstaller = new ServiceProcessInstaller(); serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; serviceProcessInstaller.Password = null; serviceProcessInstaller.Username = null; projectInstaller = new Installer(); projectInstaller.Installers.Add(serviceInstaller); projectInstaller.Installers.Add(serviceProcessInstaller); transactedInstaller = new TransactedInstaller(); transactedInstaller.Installers.Add(projectInstaller); transactedInstaller.Context = new InstallContext(); transactedInstaller.Context.Parameters["assemblypath"] = Assembly.GetExecutingAssembly().Location + "\" \"/EXECUTESERVICE"; transactedInstaller.Install(new Hashtable()); } catch (InvalidOperationException e) { if (e.InnerException != null && e.InnerException is Win32Exception)// Probably: "Service already exists." MessageBox.Show("Error: " + e.InnerException.Message); else if (e.InnerException != null && e.InnerException is InvalidOperationException && e.InnerException.InnerException != null && e.InnerException.InnerException is Win32Exception)// Probably: "Permission denied" { String MSG_ServiceInstallPermissionErrorAdvice = Program.res.GetString("MSG_ServiceInstallPermissionErrorAdvice"); MessageBox.Show("Error: " + e.InnerException.InnerException.Message + "\r\n\r\n" + MSG_ServiceInstallPermissionErrorAdvice); } else throw; } finally { if (serviceInstaller != null) serviceInstaller.Dispose(); if (serviceProcessInstaller != null) serviceProcessInstaller.Dispose(); if (projectInstaller != null) projectInstaller.Dispose(); if (transactedInstaller != null) transactedInstaller.Dispose(); } }
private static void UninstallService(string[] args) { using (var ti = new TransactedInstaller()) { using (var pi = new ProjectInstaller()) { ti.Installers.Add(pi); ti.Context = new InstallContext("", null); string path = Assembly.GetExecutingAssembly().Location; ti.Context.Parameters["assemblypath"] = path; ti.Uninstall(null); } } }
/// <summary> /// Installiert den Dienst /// </summary> static public void InstallPrinfoService() { using (TransactedInstaller ti = new TransactedInstaller()) { if (BeforeInstall != null) ti.BeforeInstall += new InstallEventHandler(BeforeInstall); if (AfterInstall != null) ti.AfterInstall += new InstallEventHandler(AfterInstall); AssemblyInstaller asmi = new AssemblyInstaller(AppDomain.CurrentDomain.BaseDirectory + "\\Prinfo.Net Service.exe", null); ti.Installers.Add(asmi); ti.Install(new Hashtable()); } }
public void ExecuteInternal(HostArguments args) { var serviceInstaller = new ServiceInstaller { ServiceName = args.ServiceName, Description = args.Description, DisplayName = args.DisplayName, }; SetStartMode(serviceInstaller, args.StartMode); var serviceProcessInstaller = new ServiceProcessInstaller { Username = args.Username, Password = args.Password, Account = args.ServiceAccount, }; var installers = new Installer[] { serviceInstaller, serviceProcessInstaller }; var arguments = String.Empty; if (!String.IsNullOrEmpty(args.Url)) { arguments += string.Format(" --url=\"{0}\"", args.Url); } using (var hostInstaller = new HostInstaller(args, arguments, installers)) using (var transactedInstaller = new TransactedInstaller()) { transactedInstaller.Installers.Add(hostInstaller); var assembly = Assembly.GetEntryAssembly(); var path = String.Format("/assemblypath={0}", assembly.Location); string[] commandLine = {path}; var context = new InstallContext(null, commandLine); transactedInstaller.Context = context; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); action(transactedInstaller); } }
public static void Uninstall(string[] args) { string name = args.Length == 2 ? args[1] : DEFAULT_NAME; try { TransactedInstaller ti = new TransactedInstaller(); WindowsServiceProjectInstaller mi = WindowsServiceProjectInstaller.Create(name); ti.Installers.Add(mi); string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location); string[] cmdline = { path }; InstallContext ctx = new InstallContext("", cmdline); ti.Context = ctx; ti.Uninstall(null); } //Swallow exception when we're trying to uninstall non-existent service catch { } }
public static void Install(string[] args) { string name = args.Length == 2 ? args[1] : DEFAULT_NAME; try { TransactedInstaller ti = new TransactedInstaller(); WindowsServiceProjectInstaller pi = WindowsServiceProjectInstaller.Create(name); ti.Installers.Add(pi); string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location); string[] cmdline = { path }; InstallContext ctx = new InstallContext("", cmdline); ti.Context = ctx; ti.Install(new Hashtable()); } catch (Exception ex) { Console.WriteLine("ERROR: {0}", ex.Message); Environment.Exit(1); } }
private static TransactedInstaller CreateTransactedInstaller(ServiceBeschreibung name, string logFilePath) { var serviceProcessInstaller = new ServiceProcessInstaller { Account = ServiceAccount.LocalSystem }; var transactedInstaller = new TransactedInstaller(); transactedInstaller.Installers.Add(serviceProcessInstaller); var path = string.Format("/assemblypath={0}", Assembly.GetEntryAssembly().Location); var installContext = new InstallContext(logFilePath, new[] {path}); transactedInstaller.Context = installContext; var serviceInstaller = new ServiceInstaller { ServiceName = name.Name, DisplayName = name.DisplayName, Description = name.Description }; transactedInstaller.Installers.Add(serviceInstaller); return transactedInstaller; }
private static Installer CreateInstaller(string serviceName) { var installer = new TransactedInstaller(); installer.Installers.Add(new ServiceInstaller { ServiceName = serviceName, DisplayName = serviceName, StartType = ServiceStartMode.Manual }); installer.Installers.Add(new ServiceProcessInstaller { Account = ServiceAccount.LocalSystem }); var installContext = new InstallContext( serviceName + ".install.log", null); installContext.Parameters["assemblypath"] = Assembly.GetEntryAssembly().Location; installer.Context = installContext; return installer; }
private static void Install(bool install, ServiceInfo serviceInfo) { using (TransactedInstaller transactedInstaller = new TransactedInstaller()) { using (System.Configuration.Install.Installer installer = CreateInstaller(serviceInfo)) { transactedInstaller.Installers.Add(installer); string path = string.Format("/assemblypath={0}", Assembly.GetEntryAssembly().Location); transactedInstaller.Context = new InstallContext("", new[] { path }); if (install) transactedInstaller.Install(new Hashtable()); else transactedInstaller.Uninstall(null); } } }
private static void DoInstall(IDictionary<string, string> options) { if (options.ContainsKey(OPT_SERVICE_NAME)) { ProjectInstaller.ServiceName = options[OPT_SERVICE_NAME]; } TransactedInstaller ti = new TransactedInstaller(); string[] cmdline = { Assembly.GetExecutingAssembly ().Location }; AssemblyInstaller ai = new AssemblyInstaller( cmdline[0], new string[0]); ti.Installers.Add(ai); InstallContext ctx = new InstallContext("install.log", cmdline); ti.Context = ctx; ti.Install(new System.Collections.Hashtable()); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (args.Length > 0) { if (args[0] == "-i" || args[0] == "-u") { ServiceInstaller serviceInstaller = new ServiceInstaller(); serviceInstaller.ServiceName = "Performance.Agent.Service"; serviceInstaller.StartType = ServiceStartMode.Automatic; serviceInstaller.DisplayName = "Colourblind Performance Agent"; serviceInstaller.Description = "Agent for the Colourblind performance monitor"; ServiceProcessInstaller processInstaller = new ServiceProcessInstaller(); processInstaller.Account = ServiceAccount.LocalSystem; processInstaller.Username = null; processInstaller.Password = null; TransactedInstaller installer = new TransactedInstaller(); installer.Installers.Add(processInstaller); installer.Installers.Add(serviceInstaller); installer.Context = new InstallContext("install.log", null); installer.Context.Parameters.Add("assemblypath", Assembly.GetCallingAssembly().Location); if (args[0] == "-i") installer.Install(new Hashtable()); else if (args[0] == "-u") installer.Uninstall(null); } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service() }; ServiceBase.Run(ServicesToRun); } }
static void Main(string[] args) { string opt=null; if(args.Length >0 ) { opt=args[0]; } if(opt!=null && opt.ToLower()=="/install") { TransactedInstaller ti= new TransactedInstaller(); MyInstaller pi = new MyInstaller(); ti.Installers.Add(pi); String path=String.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location); String[] cmdline={path}; InstallContext ctx = new InstallContext("",cmdline); ti.Context =ctx; ti.Install(new Hashtable()); } else if (opt !=null && opt.ToLower()=="/uninstall") { TransactedInstaller ti=new TransactedInstaller(); MyInstaller mi=new MyInstaller(); ti.Installers.Add(mi); String path = String.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location); String[] cmdline={path}; InstallContext ctx = new InstallContext("",cmdline); ti.Context=ctx; ti.Uninstall(null); } if(opt==null) // e.g. ,nothing on the command line { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SiteMonitor() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }
private static TransactedInstaller CreateTransactedInstaller(Installer installer) { var transactedInstaller = new TransactedInstaller(); transactedInstaller.Installers.Add(installer); var assembly = Assembly.GetEntryAssembly(); if (assembly == null) { throw new TopshelfException(Resources.ServiceMustBeExecutableFile); } var path = string.Format("/assemblypath={0}", assembly.Location); var commandLine = new[] { path }; var context = new InstallContext(null, commandLine); transactedInstaller.Context = context; return transactedInstaller; }
// Run the installation process for a specific assembly. private void RunInstall(String filename) { // Load the installer assembly. AssemblyInstaller inst; inst = new AssemblyInstaller(filename, options); // Wrap the installer in a transaction. TransactedInstaller trans; trans = new TransactedInstaller(); trans.Installers.Add(inst); // Install the assembly. IDictionary dict = new Hashtable(); trans.Install(dict); // Write the state information, for later uninstall. // TODO }
// Run the uninstallation process for a specific assembly. private void RunUninstall(String filename) { // Load the installer assembly. AssemblyInstaller inst; inst = new AssemblyInstaller(filename, options); // Wrap the installer in a transaction. TransactedInstaller trans; trans = new TransactedInstaller(); trans.Installers.Add(inst); // Load the previous state information from the install. IDictionary dict = new Hashtable(); // TODO // Install the assembly. trans.Uninstall(dict); }
public static Installer CreateInstaller(string displayName, string serviceName, string description, string dependedon, string configFile) { var installer = new TransactedInstaller(); var install = new ServiceInstaller(){ DisplayName = displayName, ServiceName = serviceName, StartType = ServiceStartMode.Automatic, Description = description }; installer.Installers.Add(install); installer.Installers.Add(new ServiceProcessInstaller { Account = ServiceAccount.LocalSystem }); var installContext = new InstallContext(serviceName + ".install.log", null); string starterFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CStarterD.exe"); if (!string.IsNullOrEmpty(configFile)) { installContext.Parameters["assemblypath"] = "\"" + starterFullPath + "\"" + " -c=" + configFile; } else { installContext.Parameters["assemblypath"] = "\"" + starterFullPath + "\""; } if(!string.IsNullOrEmpty(dependedon)) { install.ServicesDependedOn = dependedon.Split(new char[] { ',' }); } installer.Context = installContext; return installer; }
public void InstallWith(WindowsServiceInstaller installer) { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); using (var ti = new TransactedInstaller()) { ti.Installers.Add(installer); var assembly = Assembly.GetEntryAssembly(); if (assembly == null) { throw new NullReferenceException("assembly"); } var path = string.Format("/assemblypath={0}", assembly.Location); string[] commandLine = {path}; var context = new InstallContext(null, commandLine); ti.Context = context; ti.Install(new Hashtable()); } }
public void Install() { if (IsInstalled) { Console.WriteLine("Service '{0}' is already installed.", _config.ServiceName); return; } UacHelper.RunWithAdminPrevilage(() => { var dummy = new System.Collections.Hashtable(); using (var ti = new TransactedInstaller()) { ti.Context = new InstallContext(null, new[] { "/assemblypath=" + _assemblyPath }); ti.Installers.Add(new ProjectInstaller(_config)); ti.Install(dummy); } _controller = new ServiceController(_config.ServiceName); Console.WriteLine("Service '{0}' installed successfully.", _config.ServiceName); }); }
/// <include file='doc\ManagedInstaller.uex' path='docs/doc[@for="ManagedInstallerClass.InstallHelper"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public static void InstallHelper(string[] args) { bool uninstall = false; bool isAssemblyName = false; TransactedInstaller topLevelInstaller = new TransactedInstaller(); bool showHelp = false; try { /* * StreamWriter stream = new StreamWriter("c:\\installutilargs.txt", true); * stream.WriteLine("----------"); * for (int i = 0; i < args.Length; i++) * stream.WriteLine(args[i]); * stream.Close(); */ // strategy: Use a TransactedInstaller to manage the top-level installation work. // It will perform rollback/commit as necessary. Go through the assemblies on the // command line and add an AssemblyInstaller for each of them to the TransactedInstaller's // Installers collection. // // as we walk the parameters, we'll encounter either a filename or a // parameter. If we get to a filename, create an assembly installer with // all of the parameters we've seen _so far_. This way parameters can // be different for the different assemblies. ArrayList parameters = new ArrayList(); for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("/") || args[i].StartsWith("-")) { string str = args[i].Substring(1); if (string.Compare(str, "u", true, CultureInfo.InvariantCulture) == 0 || string.Compare(str, "uninstall", true, CultureInfo.InvariantCulture) == 0) { uninstall = true; } else if (string.Compare(str, "?", true, CultureInfo.InvariantCulture) == 0 || string.Compare(str, "help", true, CultureInfo.InvariantCulture) == 0) { showHelp = true; } else if (string.Compare(str, "AssemblyName", true, CultureInfo.InvariantCulture) == 0) { isAssemblyName = true; } else { parameters.Add(args[i]); } } else { Assembly asm = null; try { if (isAssemblyName) { asm = Assembly.Load(args[i]); } else { asm = Assembly.LoadFrom(args[i]); } } catch (Exception e) { if (args[i].IndexOf('=') != -1) { // probably a mistake where /key=value was written as key=value, // try to explain that throw new ArgumentException(Res.GetString(Res.InstallFileDoesntExistCommandLine, args[i]), e); } else { // the assembly.Load{From} gives a good descriptive error - pass it up throw; } } AssemblyInstaller installer = new AssemblyInstaller(asm, (string[])parameters.ToArray(typeof(string))); topLevelInstaller.Installers.Add(installer); } } if (showHelp || topLevelInstaller.Installers.Count == 0) { // we may have seen some options, but they didn't tell us to do any // work. Or they gave us /? or /help. Show the help screen. showHelp = true; topLevelInstaller.Installers.Add(new AssemblyInstaller()); throw new InvalidOperationException(GetHelp(topLevelInstaller)); } topLevelInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])parameters.ToArray(typeof(string))); } catch (Exception e) { if (showHelp) { // it's just the help message throw e; } else { throw new InvalidOperationException(Res.GetString(Res.InstallInitializeException, e.GetType().FullName, e.Message)); } } try { // MSI mode. // If the parameter /installtype=notransaction is specified, then we don't want to run // a TransactedInstaller. Instead, we just use that installer as a container for all // the AssemblyInstallers we want to run. string installType = topLevelInstaller.Context.Parameters["installtype"]; if (installType != null && string.Compare(installType, "notransaction", true, CultureInfo.InvariantCulture) == 0) { // this is a non-transacted install. Check the value of the Action parameter // to see what to do string action = topLevelInstaller.Context.Parameters["action"]; if (action != null && string.Compare(action, "rollback", true, CultureInfo.InvariantCulture) == 0) { topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallRollbackNtRun)); for (int i = 0; i < topLevelInstaller.Installers.Count; i++) { topLevelInstaller.Installers[i].Rollback(null); } return; } if (action != null && string.Compare(action, "commit", true, CultureInfo.InvariantCulture) == 0) { topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallCommitNtRun)); for (int i = 0; i < topLevelInstaller.Installers.Count; i++) { topLevelInstaller.Installers[i].Commit(null); } return; } if (action != null && string.Compare(action, "uninstall", true, CultureInfo.InvariantCulture) == 0) { topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallUninstallNtRun)); for (int i = 0; i < topLevelInstaller.Installers.Count; i++) { topLevelInstaller.Installers[i].Uninstall(null); } return; } // they said notransaction, and they didn't tell us to do rollback, commit, // or uninstall. They must mean install. topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallInstallNtRun)); for (int i = 0; i < topLevelInstaller.Installers.Count; i++) { topLevelInstaller.Installers[i].Install(null); } return; } // transacted mode - we'll only get here if /installtype=notransaction wasn't specified. if (!uninstall) { IDictionary stateSaver = new Hashtable(); topLevelInstaller.Install(stateSaver); // we don't bother writing out the saved state for this guy, because each assembly // we're installing gets its own saved-state file. } else { topLevelInstaller.Uninstall(null); } } catch (Exception e) { /* * StreamWriter stream = new StreamWriter("c:\\installutilargs.txt", true); * stream.WriteLine("Caught exception: " + e.GetType().FullName + ": " + e.Message); * stream.WriteLine(e.StackTrace); * stream.Close(); */ throw e; } /* * StreamWriter stream2 = new StreamWriter("c:\\installutilargs.txt", true); * stream2.WriteLine("Caught no exceptions. Returning 0."); * stream2.Close(); */ return; }
public static void InstallHelper(string[] args) { bool flag1 = false; bool flag2 = false; TransactedInstaller transactedInstaller = new TransactedInstaller(); bool flag3 = false; try { ArrayList arrayList = new ArrayList(); for (int index = 0; index < args.Length; ++index) { if (args[index].StartsWith("/", StringComparison.Ordinal) || args[index].StartsWith("-", StringComparison.Ordinal)) { string strA = args[index].Substring(1); if (string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0) { flag1 = true; } else if (string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0) { flag3 = true; } else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0) { flag2 = true; } else { arrayList.Add((object)args[index]); } } else { Assembly assembly; try { assembly = !flag2?Assembly.LoadFrom(args[index]) : Assembly.Load(args[index]); } catch (Exception ex) { if (args[index].IndexOf('=') != -1) { throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", new object[1] { (object)args[index] }), ex); } else { throw; } } AssemblyInstaller assemblyInstaller = new AssemblyInstaller(assembly, (string[])arrayList.ToArray(typeof(string))); transactedInstaller.Installers.Add((Installer)assemblyInstaller); } } if (flag3 || transactedInstaller.Installers.Count == 0) { flag3 = true; transactedInstaller.Installers.Add((Installer) new AssemblyInstaller()); throw new InvalidOperationException(ManagedInstallerClass.GetHelp((Installer)transactedInstaller)); } else { transactedInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])arrayList.ToArray(typeof(string))); } } catch (Exception ex) { if (flag3) { throw ex; } throw new InvalidOperationException(Res.GetString("InstallInitializeException", (object)ex.GetType().FullName, (object)ex.Message)); } try { string strA1 = transactedInstaller.Context.Parameters["installtype"]; if (strA1 != null && string.Compare(strA1, "notransaction", StringComparison.OrdinalIgnoreCase) == 0) { string strA2 = transactedInstaller.Context.Parameters["action"]; if (strA2 != null && string.Compare(strA2, "rollback", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallRollbackNtRun")); for (int index = 0; index < transactedInstaller.Installers.Count; ++index) { transactedInstaller.Installers[index].Rollback((IDictionary)null); } } else if (strA2 != null && string.Compare(strA2, "commit", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallCommitNtRun")); for (int index = 0; index < transactedInstaller.Installers.Count; ++index) { transactedInstaller.Installers[index].Commit((IDictionary)null); } } else if (strA2 != null && string.Compare(strA2, "uninstall", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallUninstallNtRun")); for (int index = 0; index < transactedInstaller.Installers.Count; ++index) { transactedInstaller.Installers[index].Uninstall((IDictionary)null); } } else { transactedInstaller.Context.LogMessage(Res.GetString("InstallInstallNtRun")); for (int index = 0; index < transactedInstaller.Installers.Count; ++index) { transactedInstaller.Installers[index].Install((IDictionary)null); } } } else if (!flag1) { IDictionary stateSaver = (IDictionary) new Hashtable(); transactedInstaller.Install(stateSaver); } else { transactedInstaller.Uninstall((IDictionary)null); } } catch (Exception ex) { throw ex; } }
/// <summary>Handles the functionality of the Installutil.exe (Installer Tool).</summary> /// <param name="args">The arguments passed to the Installer Tool.</param> public static void InstallHelper(string[] args) { var doUninstall = false; var shouldLoadByName = false; var transactedInstaller = new TransactedInstaller(); var showHelp = false; try { var arrayList = new ArrayList(); foreach (var arg in args) { if (arg.StartsWith("-", StringComparison.Ordinal)) { var strA = arg.Substring(1); if (string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0) { doUninstall = true; } else if (string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0) { showHelp = true; } else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0) { shouldLoadByName = true; } else { arrayList.Add(arg); } } else { Assembly assembly; try { assembly = shouldLoadByName ? Assembly.Load(arg) : Assembly.LoadFrom(arg); } catch (Exception innerException) { if (arg.IndexOf('=') != -1) { throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", arg), innerException); } throw; } var value = new AssemblyInstaller(assembly, (string[])arrayList.ToArray(typeof(string))); transactedInstaller.Installers.Add(value); } } if (showHelp || transactedInstaller.Installers.Count == 0) { showHelp = true; transactedInstaller.Installers.Add(new AssemblyInstaller()); throw new InvalidOperationException(GetHelp(transactedInstaller)); } transactedInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])arrayList.ToArray(typeof(string))); } catch (Exception ex) { if (showHelp) { throw ex; } throw new InvalidOperationException(Res.GetString("InstallInitializeException", ex.GetType().FullName, ex.Message)); } var installType = transactedInstaller.Context.Parameters["installtype"]; if (installType != null && string.Compare(installType, "notransaction", StringComparison.OrdinalIgnoreCase) == 0) { var action = transactedInstaller.Context.Parameters["action"]; if (action != null && string.Compare(action, "rollback", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallRollbackNtRun")); for (var j = 0; j < transactedInstaller.Installers.Count; j++) { transactedInstaller.Installers[j].Rollback(null); } } else if (action != null && string.Compare(action, "commit", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallCommitNtRun")); for (var k = 0; k < transactedInstaller.Installers.Count; k++) { transactedInstaller.Installers[k].Commit(null); } } else if (action != null && string.Compare(action, "uninstall", StringComparison.OrdinalIgnoreCase) == 0) { transactedInstaller.Context.LogMessage(Res.GetString("InstallUninstallNtRun")); for (var l = 0; l < transactedInstaller.Installers.Count; l++) { transactedInstaller.Installers[l].Uninstall(null); } } else { transactedInstaller.Context.LogMessage(Res.GetString("InstallInstallNtRun")); for (var m = 0; m < transactedInstaller.Installers.Count; m++) { transactedInstaller.Installers[m].Install(null); } } } else if (!doUninstall) { IDictionary stateSaver = new Hashtable(); transactedInstaller.Install(stateSaver); } else { transactedInstaller.Uninstall(null); } }
public static void InstallHelper(string[] args) { bool flag = false; bool flag2 = false; TransactedInstaller installerWithHelp = new TransactedInstaller(); bool flag3 = false; try { ArrayList list = new ArrayList(); for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("/", StringComparison.Ordinal) || args[i].StartsWith("-", StringComparison.Ordinal)) { string strA = args[i].Substring(1); if ((string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)) { flag = true; } else if ((string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0)) { flag3 = true; } else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0) { flag2 = true; } else { list.Add(args[i]); } } else { Assembly assembly = null; try { if (flag2) { assembly = Assembly.Load(args[i]); } else { assembly = Assembly.LoadFrom(args[i]); } } catch (Exception exception) { if (args[i].IndexOf('=') != -1) { throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", new object[] { args[i] }), exception); } throw; } AssemblyInstaller installer2 = new AssemblyInstaller(assembly, (string[])list.ToArray(typeof(string))); installerWithHelp.Installers.Add(installer2); } } if (flag3 || (installerWithHelp.Installers.Count == 0)) { flag3 = true; installerWithHelp.Installers.Add(new AssemblyInstaller()); throw new InvalidOperationException(GetHelp(installerWithHelp)); } installerWithHelp.Context = new InstallContext("InstallUtil.InstallLog", (string[])list.ToArray(typeof(string))); } catch (Exception exception2) { if (flag3) { throw exception2; } throw new InvalidOperationException(Res.GetString("InstallInitializeException", new object[] { exception2.GetType().FullName, exception2.Message })); } try { string str2 = installerWithHelp.Context.Parameters["installtype"]; if ((str2 != null) && (string.Compare(str2, "notransaction", StringComparison.OrdinalIgnoreCase) == 0)) { string str3 = installerWithHelp.Context.Parameters["action"]; if ((str3 != null) && (string.Compare(str3, "rollback", StringComparison.OrdinalIgnoreCase) == 0)) { installerWithHelp.Context.LogMessage(Res.GetString("InstallRollbackNtRun")); for (int j = 0; j < installerWithHelp.Installers.Count; j++) { installerWithHelp.Installers[j].Rollback(null); } } else if ((str3 != null) && (string.Compare(str3, "commit", StringComparison.OrdinalIgnoreCase) == 0)) { installerWithHelp.Context.LogMessage(Res.GetString("InstallCommitNtRun")); for (int k = 0; k < installerWithHelp.Installers.Count; k++) { installerWithHelp.Installers[k].Commit(null); } } else if ((str3 != null) && (string.Compare(str3, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)) { installerWithHelp.Context.LogMessage(Res.GetString("InstallUninstallNtRun")); for (int m = 0; m < installerWithHelp.Installers.Count; m++) { installerWithHelp.Installers[m].Uninstall(null); } } else { installerWithHelp.Context.LogMessage(Res.GetString("InstallInstallNtRun")); for (int n = 0; n < installerWithHelp.Installers.Count; n++) { installerWithHelp.Installers[n].Install(null); } } } else if (!flag) { IDictionary stateSaver = new Hashtable(); installerWithHelp.Install(stateSaver); } else { installerWithHelp.Uninstall(null); } } catch (Exception exception3) { throw exception3; } }