本文整理汇总了C#中System.Configuration.Install.AssemblyInstaller类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInstaller类的具体用法?C# AssemblyInstaller怎么用?C# AssemblyInstaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyInstaller类属于System.Configuration.Install命名空间,在下文中一共展示了AssemblyInstaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallService
public void InstallService(string user, string pass) {
using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) {
installer.UseNewContext = true;
Hashtable savedState = new Hashtable();
UserPassCombination c = new UserPassCombination();
c.User = user;
c.Pass = pass;
_userPassCombination = c;
installer.BeforeInstall += new InstallEventHandler(installer_BeforeInstall);
//Rollback has to be called by user code. According msdn-doc for AssemblyInstaller.Install() is probably wrong.
try {
installer.Install(savedState);
installer.Commit(savedState);
}
catch (Exception ex) {
installer.Rollback(savedState);
throw new InstallException(String.Format("Install failed: {0}", ex.Message), ex);
}
installer.BeforeInstall -= installer_BeforeInstall;
}
}
示例2: 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;
}
示例3: GetInstaller
private static AssemblyInstaller GetInstaller()
{
AssemblyInstaller installer = new AssemblyInstaller(
typeof(SetItUpService).Assembly, null);
installer.UseNewContext = true;
return installer;
}
示例4: GetInstaller
/// <summary>
///
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public static AssemblyInstaller GetInstaller(string serviceName)
{
//TODO: THis is not working
AssemblyInstaller installer = new AssemblyInstaller();
installer.UseNewContext = true;
return installer;
}
示例5: InstallTheService
public void InstallTheService()
{
try
{
IDictionary state = new Hashtable();
using (AssemblyInstaller installer = new AssemblyInstaller(InstallersAssembly, Args))
{
installer.UseNewContext = true;
try
{
installer.Install(state);
installer.Commit(state);
InternalTrace("Installed the service");
}
catch (Exception installException)
{
try
{
installer.Rollback(state);
InternalTrace("Rolledback the service installation because:" + installException.ToString());
}
catch { }
throw;
}
}
}
catch (Exception exception)
{
InternalTrace("Failed to install the service " + exception.ToString());
}
}
示例6: GetInstaller
private static AssemblyInstaller GetInstaller()
{
AssemblyInstaller installer = new AssemblyInstaller(
typeof(Program).Assembly, null);
installer.UseNewContext = true;
return installer;
}
示例7: ServiceInstaller
private static bool ServiceInstaller(bool uninstall = false)
{
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;
if (!uninstall)
{
myAssemblyInstaller.Install(mySavedState);
// Commit the 'MyAssembly' assembly.
myAssemblyInstaller.Commit(mySavedState);
}
else
{ myAssemblyInstaller.Uninstall(mySavedState); }
}
catch (FileNotFoundException)
{
throw;
}
catch (Exception)
{ return false; }
return true;
}
示例8: InstallService
/// <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());
}
示例9: InstallService
/// <summary>
/// 安装windows服务
/// </summary>
private void InstallService(IDictionary stateSaver, string filepath, string serviceName)
{
try
{
ServiceController service = new ServiceController(serviceName);
if (!ServiceIsExisted(serviceName))
{
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Install(stateSaver);
myAssemblyInstaller.Commit(stateSaver);
myAssemblyInstaller.Dispose();
service.Start();
}
else
{
if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
service.Start();
}
}
catch (Exception ex)
{
throw new Exception("InstallServiceError\r\n" + ex.Message);
}
}
示例10: Installation
public Installation() : base()
{
#region Install on MSR.LST.Net.Rtp (a necessary dependency)
AssemblyInstaller ai = new AssemblyInstaller();
ai.UseNewContext = true;
ai.Assembly = Assembly.Load("MSR.LST.Net.Rtp");
Installers.Add(ai);
#endregion
#region Install MDShowManager (if it is in the same directory)
FileInfo fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
FileInfo[] foundFiles = fi.Directory.GetFiles("MDShowManager.dll");
if (foundFiles.Length == 1)
{
ai = new AssemblyInstaller();
ai.UseNewContext = true;
ai.Path = foundFiles[0].FullName;
Installers.Add(ai);
}
#endregion
#region Install Pipecleaner Agent Service (if it is in the same directory)
fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
foundFiles = fi.Directory.GetFiles("Pipecleaner Agent Service.exe");
if (foundFiles.Length == 1)
{
ai = new AssemblyInstaller();
ai.UseNewContext = true;
ai.Path = foundFiles[0].FullName;
Installers.Add(ai);
}
#endregion
}
示例11: InstallService
/// <summary>
/// 安装服务:
/// </summary>
/// <param name="filepath"></param>
public void InstallService(string filepath)
{
try
{
string serviceName = GetServiceName(filepath);
ServiceController service = new ServiceController(serviceName);
if (!ServiceIsExisted(serviceName))
{
//Install Service
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller() { UseNewContext = true, Path = filepath };
myAssemblyInstaller.Install(new Hashtable());
myAssemblyInstaller.Commit(new Hashtable());
myAssemblyInstaller.Dispose();
//--Start Service
service.Start();
}
else
{
if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
{
service.Start();
}
}
}
catch (Exception ex)
{
throw new Exception("installServiceError/n" + ex.Message);
}
}
示例12: 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);
}
}
示例13: btnInstall_Click
/// <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;
}
}
示例14: GetInstaller
private static AssemblyInstaller GetInstaller(System.Reflection.Assembly assem)
{
AssemblyInstaller installer = new AssemblyInstaller(
assem, null);
installer.UseNewContext = true;
return installer;
}
示例15: 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);
}
}