Ich habe den folgenden Code, der einen Dienst beendet und die Installation rückgängig macht. Es den Dienst richtig hält, aber es gibt mir diese Fehlermeldung, wenn ich versuche, un-install:Objektverweis nicht auf eine Instanz eines Objekts festgelegt, wenn versucht wird, einen Dienst zu deinstallieren C#
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Configuration.Install.Installer.Uninstall(IDictionary savedState)
at System.ServiceProcess.ServiceInstaller.Uninstall(IDictionary savedState)
at UpdateOrca.FuncoesUpdater.StopService(String serviceName, Int32 timeoutMilliseconds, Boolean Unninstall) in C:\Users\me\Downloads\UpdateOrcaV2013\UpdateOrca\UpdateOrca\FuncoesUpdater.cs:line 165
Code:
public void StopService(string serviceName, int timeoutMilliseconds, bool Unninstall)
{
if (ServicoInstalado(serviceName) == true) //&& ServiceRunning(serviceName) == true
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
if (Unninstall == true)
{
ServiceInstallerObj.ServiceName = serviceName;
ServiceInstallerObj.Uninstall(null); (LINE OF THE ERROR)
}
}
catch (Exception ex)
{
Program.Erro = ex.ToString();
Erro NewErro = new Erro();
NewErro.ShowDialog();
}
}
}
Thx für die schnelle Antwort. Es funktioniert: D –