[英]My .msi file installer during installation ask to close currently run console application or windows service
I am trying through my console application or windows service to run the batch. 我正在尝试通过控制台应用程序或Windows服务运行批处理。 Into batch I write commands which run my Setup.msi and create InstallLogFile.
批处理中,我编写了运行Setup.msi并创建InstallLogFile的命令。
Trying with console application. 尝试使用控制台应用程序。 Problem arises when the Setup.msi is run and pop up me with "The 'MyConsoleApplication' should be closed before continuing the install".
运行Setup.msi并出现“在继续安装之前应先关闭'MyConsoleApplication'”消息时,会出现问题。 And I have option to check Automatically close applications and attempt to restart them after setup is complete.
我可以选择检查自动关闭应用程序,并在安装完成后尝试重新启动它们。
Trying with starting my created Windows Service. 尝试启动我创建的Windows服务。 Here is the thing little bit complicated cause after the Setup.msi is run, I don't see any pop up message, just through the log I find that my service is Stopped (probably my Setup.msi requires like in 1. case but I have no idea why) and after installation, service again Started and do the whole logic again, which I want to avoid.
这是运行Setup.msi后有点复杂的原因,我没有看到任何弹出消息,仅通过日志我发现我的服务已停止(可能是我的Setup.msi需要像1.情况,我不知道为什么),然后在安装后再次启动服务,并再次执行整个逻辑,这是我想避免的。
First in OnStart method of the windows service I called Update() in separate thread method which handle whole process. 首先在Windows服务的OnStart方法中,我在处理整个过程的单独线程方法中调用Update()。
protected override void OnStart(string[] args)
{
try
{
Task.Run(() =>
{
try
{
Update();
}
catch (Exception ex)
{
}
finally
{
}
});
}
catch (Exception ex)
{
}
}
I am not including whole code, just logic without log information. 我没有包括整个代码,只是没有日志信息的逻辑。
In update method some of the core logic is: 1. Download the Setup.msi 2. Close process and stop some services 3. Start process which runs .bat with code which starts Setup.msi installation 在更新方法中,一些核心逻辑是:1.下载Setup.msi 2.关闭进程并停止一些服务3.启动运行.bat的进程,并使用启动Setup.msi的代码进行安装
public void Update()
{
var downloadLink = @"someLinkOnDropbox";
// try to download
try
{
using (var client = new WebClient())
{
client.DownloadFile(downloadLink, myDirLocation);
}
}
catch (Exception ex)
{
return;
}
while (ProcessIsRunning("someProcess") || ServiceIsRunning("someService1") || ServiceIsRunning("someService2") || ServiceIsRunning("someService3"))
{
// try to terminate process
StopProcess("someProcess");
// try to stop the service
StopService("someService1");
StopService("someService2");
StopService("someService3");
}
// wait 5 sec process and services are stopped
Thread.Sleep(5000);
// path to the my .bat file on D: disc which run Setup.msi (also downloaded on my D: disc)
const string path = @"somePath";
const string fileName = @"batName.bat";
const string workingDirectory = @"myDir";
try
{
Task.Run(() =>
{
StartProcess(path, fileName, workingDirectory);
});
}
catch (Exception ex)
{
}
}
Also, methods StopProcess, StopService, ProcessIsRunning and ServiceIsRunning are custom made and working fine in that point I have no problems. 此外,方法StopProcess,StopService,ProcessIsRunning和ServiceIsRunning是自定义的,并且在这一点上工作正常,我没有问题。
Method StartProcess is below: 方法StartProcess如下:
public void StartProcess(string path, string fileName, string workingDirectory)
{
ProcessStartInfo psi = new ProcessStartInfo(path)
{
FileName = fileName,
WorkingDirectory = workingDirectory,
UseShellExecute = true,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden
};
// Try to start the process.
try
{
Process p = new Process {StartInfo = psi};
p.Start();
Log.Instance.Warn($"Process started");
p.WaitForExit();
Log.Instance.Warn($"Process finished");
}
catch (Exception ex)
{
}
}
Code which is in .bat file: msiexec /i Setup.msi /l*v SetupInstall.log INSTALL_SETTINGS_FOR="deviceID" .bat文件中的代码:msiexec / i Setup.msi / l * v SetupInstall.log INSTALL_SETTINGS_FOR =“ deviceID”
Here is the thing what makes me problem with my service. 这就是使我的服务出现问题的原因。
My application which I want to update via MyService are on the same location and used some same files. 我要通过MyService更新的应用程序位于同一位置,并使用了一些相同的文件。 So during update process when MyService run it through the batch, installation requires to stop service cause service used some files which need to be updated, cause also application uses it.
因此,在更新过程中,当MyService通过批处理运行它时,安装需要停止服务,因为服务使用了一些需要更新的文件,导致应用程序也使用了它。
Solution was to move Service installation location into the new dir. 解决方案是将“服务”安装位置移到新目录中。 Something like D:\\MyApp for the app, and D:\\MyApp\\MyService for the service, and in this case shared files between MyApp and MyService can be updated in MyApp without requirement from MyApp to stop MyService.
诸如D:\\ MyApp(针对应用程序)和D:\\ MyApp \\ MyService(针对服务)之类的东西,在这种情况下,可以在MyApp中更新MyApp和MyService之间的共享文件,而无需MyApp停止MyService。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.