本文整理汇总了C#中System.Configuration.Install.AssemblyInstaller.Install方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInstaller.Install方法的具体用法?C# AssemblyInstaller.Install怎么用?C# AssemblyInstaller.Install使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.Install.AssemblyInstaller
的用法示例。
在下文中一共展示了AssemblyInstaller.Install方法的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: InstallWindowsService
public static bool InstallWindowsService()
{
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.Install(mySavedState);
// Commit the 'MyAssembly' assembly.
myAssemblyInstaller.Commit(mySavedState);
}
catch (Exception e)
{ return false; }
StartService();
return true;
}
示例3: 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);
}
}
示例4: Install
public static void Install(string[] args)
{
try
{
using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args))
{
IDictionary state = new Hashtable();
// Install the service
installer.UseNewContext = true;
try
{
installer.Install(state);
installer.Commit(state);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
try
{
installer.Rollback(state);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
}
}
catch (Exception exception)
{
Console.WriteLine("Failed to install service. Error: " + exception.Message);
}
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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());
}
}
示例8: 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);
}
}
示例9: InstallService
/// <summary>
/// 安装Windows服务
/// </summary>
/// <param name="stateSaver">状态集合</param>
/// <param name="filepath">程序文件路径</param>
public static void InstallService(IDictionary stateSaver, String filepath)
{
AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
AssemblyInstaller1.UseNewContext = true;
AssemblyInstaller1.Path = filepath;
AssemblyInstaller1.Install(stateSaver);
AssemblyInstaller1.Commit(stateSaver);
AssemblyInstaller1.Dispose();
}
示例10: InstallService
/// <summary>
/// Acrescenta um serviço do windows no registro
/// </summary>
public static void InstallService(String fileName)
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
String serviceName = Path.GetFileNameWithoutExtension(fileName);
String[] arguments = new string[] { "/LogFile=" + serviceName + "_Install.log" };
IDictionary state = new Hashtable();
AssemblyInstaller installer = new AssemblyInstaller(fileName, arguments);
installer.UseNewContext = true;
installer.Install(state);
installer.Commit(state);
}
示例11: InstallAssembly
/// <summary>
/// Install the service that is contained in specified assembly.
/// </summary>
/// <param name="pathToAssembly">Path to service assembly.</param>
/// <param name="commandLineArguments">Parameters, that are passed to assembly.</param>
public static void InstallAssembly(string pathToAssembly, string[] commandLineArguments)
{
List<string> argList = new List<string>(commandLineArguments);
argList.Add(string.Format("/LogFile={0}_install.log",
Path.GetFileNameWithoutExtension(pathToAssembly)));
using (AssemblyInstaller installer = new AssemblyInstaller(pathToAssembly, argList.ToArray())) {
var state = new Hashtable();
installer.Install(state);
installer.Commit(state);
}
}
示例12: 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);
}
}
示例13: InstallService
public static void InstallService()
{
string exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string strDir = System.IO.Path.GetDirectoryName(exePath);
string filepath = strDir + "\\MPlayerWWService.exe";
IDictionary mSavedState = new Hashtable();
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Install(mSavedState);
myAssemblyInstaller.Commit(mSavedState);
myAssemblyInstaller.Dispose();
}
示例14: Install
public static bool Install()
{
Tracker.StartServer();
bool result = true;
InstallContext context = null;
try
{
using (var inst = new AssemblyInstaller(typeof (ServerLifecycleManager).Assembly, null))
{
context = inst.Context;
LogMessage("Installing service " + AppSettings.ServiceName, inst.Context);
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
inst.Install(state);
inst.Commit(state);
Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Installed);
}
catch (Exception err)
{
Tracker.TrackException("WindowsServiceManager", "Install", err);
try
{
inst.Rollback(state);
}
catch (Exception innerErr)
{
throw new AggregateException(new List<Exception> {err, innerErr});
}
throw;
}
}
}
catch (Exception ex)
{
result = false;
WriteExceptions(ex, context);
}
finally
{
Tracker.Stop();
}
return result;
}
示例15: InstallmyService
/// <summary>
/// 安装Windows服务
/// </summary>
/// <param name="stateSaver">集合,当传递给 Install 方法时,stateSaver 参数指定的 IDictionary 应为空。</param>
/// <param name="filepath">程序文件路径</param>
public static void InstallmyService(IDictionary stateSaver, string filepath)
{
try
{
AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
AssemblyInstaller1.UseNewContext = true;
AssemblyInstaller1.Path = filepath;
stateSaver.Clear();
AssemblyInstaller1.Install(stateSaver);
AssemblyInstaller1.Commit(stateSaver);
AssemblyInstaller1.Dispose();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString());
}
}