本文整理汇总了C#中System.Configuration.Install.AssemblyInstaller.Uninstall方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInstaller.Uninstall方法的具体用法?C# AssemblyInstaller.Uninstall怎么用?C# AssemblyInstaller.Uninstall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.Install.AssemblyInstaller
的用法示例。
在下文中一共展示了AssemblyInstaller.Uninstall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Install
static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "Uninstalling" : "Installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WinSvc).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo) inst.Uninstall(state);
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try { inst.Rollback(state); }
catch { }
throw;
}
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
示例2: Install
private void Install(AssemblyInstaller installer, IDictionary state, bool undo)
{
try
{
if (undo)
{
_log.Write(LogLevel.Info, "Uninstalling {0}...", StringConstants.ServiceName);
installer.Uninstall(state);
_log.Write(LogLevel.Info, "{0} has been successfully removed from the system.", StringConstants.ServiceName);
}
else
{
_log.Write(LogLevel.Info, "Installing {0}...", StringConstants.ServiceName);
installer.Install(state);
_log.Write(LogLevel.Info, "Commiting changes...");
installer.Commit(state);
_log.Write(LogLevel.Info, "Install succeeded.");
}
}
catch (Exception ex)
{
_log.Write(LogLevel.Error, "An error occured during {1}. {0}", ex, undo?"uninstall" : "install");
_log.Write(LogLevel.Info, "Trying to roll back...");
TryRollback(installer, state);
}
}
示例3: Uninstall
public static void Uninstall(string[] args)
{
try
{
using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args))
{
IDictionary state = new Hashtable();
// Install the service
installer.UseNewContext = true;
try
{
installer.Uninstall(state);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
try
{
installer.Rollback(state);
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
}
}
}
catch (Exception exception)
{
Console.WriteLine("Failed to install service. Error: " + exception.Message);
}
}
示例4: UninstallWindowsService
public static bool UninstallWindowsService()
{
StopService();
IDictionary mySavedState = new Hashtable();
try
{
// Set the commandline argument array for 'logfile'.
string[] commandLineOptions = new string[1] { string.Format("/LogFile={0}", _logFile) };
// Create an object of the 'AssemblyInstaller' class.
AssemblyInstaller myAssemblyInstaller = new
AssemblyInstaller(_installAssembly, commandLineOptions);
myAssemblyInstaller.UseNewContext = true;
// Install the 'MyAssembly' assembly.
myAssemblyInstaller.Uninstall(mySavedState);
// Commit the 'MyAssembly' assembly.
myAssemblyInstaller.Commit(mySavedState);
}
catch (Exception e)
{ return false; }
return true;
}
示例5: UninstallService
/// <summary>
/// Remove um serviço do windows do registro
/// </summary>
public static void UninstallService(String fileName)
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
String serviceName = Path.GetFileNameWithoutExtension(fileName);
String[] arguments = new string[] { "/LogFile=" + serviceName + "_Install.log" };
AssemblyInstaller installer = new AssemblyInstaller(fileName, arguments);
installer.UseNewContext = true;
installer.Uninstall(null);
}
示例6: UnInstallService
/// <summary>
/// 卸载windows服务
/// </summary>
/// <param name="filepath">获取或设置要安装的程序集的路径。</param>
public static void UnInstallService(String serviceName, string filepath)
{
if (ServiceIsExisted(serviceName))
{
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Uninstall(null);
myAssemblyInstaller.Dispose();
}
}
示例7: Install
static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "uninstalling" : "installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
try
{
ServiceController service = new ServiceController("DpFamService");
TimeSpan timeout = TimeSpan.FromMilliseconds(1000);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
Console.WriteLine("Could not start the server\n");
}
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
示例8: UnInstallmyService
/// <summary>
/// 卸载Windows服务
/// </summary>
/// <param name="filepath">程序文件路径</param>
public static void UnInstallmyService(IDictionary stateSaver,string filepath)
{
try
{
AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
AssemblyInstaller1.UseNewContext = true;
AssemblyInstaller1.Path = filepath;
AssemblyInstaller1.Uninstall(stateSaver);
AssemblyInstaller1.Dispose();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString());
}
}
示例9: Uninstall
public static void Uninstall()
{
using (AssemblyInstaller installer =
new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
{
installer.UseNewContext = true;
var state = new System.Collections.Hashtable();
try
{
installer.Uninstall(state);
}
catch
{
throw;
}
}
}
示例10: UnInstallService
/// <summary>
/// 卸载windows服务:
/// </summary>
/// <param name="filepath"></param>
public void UnInstallService(string filepath)
{
try
{
string serviceName = GetServiceName(filepath);
if (ServiceIsExisted(serviceName))
{
//UnInstall Service
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller() { UseNewContext = true, Path = filepath };
myAssemblyInstaller.Uninstall(null);
myAssemblyInstaller.Dispose();
}
}
catch (Exception ex)
{
throw new Exception("unInstallServiceError/n" + ex.Message);
}
}
示例11: Install
static void Install(bool undo, string[] args)
{
try
{
Logger.Log(undo ? "Uninstalling ..." : "Installing ... ");
using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
var state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
StartService();
}
}
catch (Exception ex)
{
try
{
Logger.Log(ex);
inst.Rollback(state);
}
catch { }
throw;
}
inst.Dispose();
}
Logger.Log("... finished");
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
示例12: Install
public static bool Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "Uninstalling..." : "Installing...");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WakeService).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
return true;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
return false;
}
示例13: Uninstall
/// <summary>
/// Uninstalls the assembly specified by <see cref="P:assemblyPath" />
/// </summary>
/// <param name="assemblyPath">Full path to the assembly to uninstall</param>
public static void Uninstall(string assemblyPath)
{
try
{
AssemblyInstaller installer = new AssemblyInstaller(assemblyPath, new String[] { })
{
UseNewContext = true
};
installer.Uninstall(null);
installer.Commit(null);
}
catch (FileNotFoundException exception)
{
Console.WriteLine("[!] Installer state file not found, uninstalling service without storing the state" + exception.Message);
}
catch (Exception exception2)
{
Console.WriteLine("[!] Unable to uninstall service: " + exception2.Message);
}
}
示例14: Install
public static bool Install(bool undo, string[] args)
{
try
{
using(var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
inst.AfterInstall += OnAfterInstall;
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if(undo)
inst.Uninstall(state);
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch
{
return false;
}
throw;
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
return false;
}
return true;
}
示例15: OnAction
public void OnAction(Hashtable parameters)
{
System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), new string[1] { "/LogToConsole=false" });
Hashtable rollback = new Hashtable();
if (GameServerService.GetDOLService() == null)
{
Console.WriteLine("No service named \"DOL\" found!");
return;
}
Console.WriteLine("Uninstalling DOL system service...");
try
{
asmInstaller.Uninstall(rollback);
}
catch (Exception e)
{
Console.WriteLine("Error uninstalling system service");
Console.WriteLine(e.Message);
return;
}
Console.WriteLine("Finished!");
}