Installation d'un service Windows programme
-
27-10-2019 - |
Question
Je tente d'installer un service programmation via C #, mais je l'ai courir dans une question que je ne peux pas se déplacer.
Après avoir lu des tas de documents que je suis à ce moment-là où je crois que Microsoft a un bug, (mais nous savons tous que ce n'est pas le cas).
Alors, voici la Main
de ma demande.
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
if (System.Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "/install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
Console.Read();
break;
case "/uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase.Run(new ProxyMonitor());
}
}
Lorsqu'il est exécuté dans les CMD sous les privilèges d'administration comme si ProxyMonitor /install
l'étape en descend à la ligne:
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
comme prévu, et saute alors dans ma classe installer comme ceci:
namespace Serco.Services.ProxyMonitor
{
[RunInstaller(true)]
public class ManagedInstallation : ServiceInstaller
{
public ManagedInstallation()
{
var ProcessInstaller = new ServiceProcessInstaller();
var ServiceInstaller = new ServiceInstaller();
//set the information and privileges
ProcessInstaller.Account = ServiceConfiguration.AccountType;
ServiceInstaller.DisplayName = ServiceConfiguration.DisplayName;
ServiceInstaller.StartType = ServiceConfiguration.StartType;
ServiceInstaller.Description = ServiceConfiguration.Description;
ServiceInstaller.ServiceName = ServiceConfiguration.ServiceName;
Installers.Add(ProcessInstaller);
Installers.Add(ServiceInstaller);
}
}
}
Après avoir vérifié le fichier de débogage je reçois le texte suivant:
Installing assembly 'C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.InstallLog
assemblypath = C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.exe
Installing service ...
Creating EventLog source in log Application...
Rolling back assembly 'C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.InstallLog
assemblypath = C:\Users\Robert\documents\visual studio 2010\Projects\ProxyMonitor\ProxyMonitor\bin\Debug\ProxyMonitor.exe
Restoring event log to previous state for source .
Je reçois aussi l'exception levée dans le appel suivant:
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
Déclarant:
L'installation a échoué, et la restauration a été effectuée. Doit spécifier la valeur de la source.
Mises à jour:
Classe de configuration
namespace Serco.Services.ProxyMonitor
{
class ServiceConfiguration
{
public static string DisplayName
{
get { return "Serco Proxy Monitor"; }
}
public static string ServiceName
{
get { return "Serco Proxy Monitor"; }
}
public static string Description
{
get
{
return "Serco ProxyMonitor is a helper developed to manage the state of the proxy for the employess whilst of the internal network.";
}
}
public static ServiceStartMode StartType
{
get{return ServiceStartMode.Automatic;}
}
public static ServiceAccount AccountType
{
get{return ServiceAccount.LocalSystem;}
}
/*.. /Snip/ ..*/
}
}
La solution
Il ressemble à la source du journal est nulle; êtes-vous sûr que ServiceConfiguration.ServiceName
est défini et a une valeur?
Autres conseils
j'ai tout compris et pensé que je posterais d'autres de Encase peut être avoir la même question.
Il était une combinaison de quelques choses, mais malade juste vous montrer rapidement les:
public static string ServiceName
{
get { return "Serco Proxy Monitor"; }
}
- Nous avons dû devenir
return "SercoProxyMonitor";
en raison des espaces - Suppression de la
UnhandledException
qui montrait alors plus en traces de la pile de profondeur - nécessaire d'avoir des droits d'administrateur complets.
Je pense que la question principale était que le ServiceInstaller
utilisait le ServiceName
pour créer et EventLogSource
, Et comme il y avait des espaces dans le EventLogSource
il vomissait un ajustement.