C# 检查是否重新启动
我目前正在开发一个安装支持程序,该程序在安装后执行一些重要任务。现在我遇到了一个问题,如果需要重新启动,我真的需要确定这个问题 我当前的代码如下所示(用于检查):C# 检查是否重新启动,c#,.net,installation,C#,.net,Installation,我目前正在开发一个安装支持程序,该程序在安装后执行一些重要任务。现在我遇到了一个问题,如果需要重新启动,我真的需要确定这个问题 我当前的代码如下所示(用于检查): 这就足够了,还是我需要做更多/其他检查?如果您正在运行任何安装程序,您还可以检查任何挂起的文件重命名/删除。在需要检查重启之前,您是否在此程序中运行MSIs? try { bool restart = false; Console.WriteLine("Prüfe auf Neustart..."); Sy
这就足够了,还是我需要做更多/其他检查?如果您正在运行任何安装程序,您还可以检查任何挂起的文件重命名/删除。在需要检查重启之前,您是否在此程序中运行MSIs?
try
{
bool restart = false;
Console.WriteLine("Prüfe auf Neustart...");
SystemInformation t = new SystemInformation();
if (t.RebootRequired){
restart = true;
}
RegistryKey rk = null;
rk = Registry.LocalMachine;
rk = rk.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce");
string[] r = rk.GetValueNames();
if (r.Length != 0) { restart = true; }
rk = Registry.CurrentUser;
rk = rk.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce");
r = rk.GetValueNames();
if (r.Length != 0) { restart = true; }
if (restart == true)
{
Console.WriteLine("Bitte starten Sie Ihren Rechner zuerst neu und führen das Setup dann nochmal aus...");
Console.ReadKey();
Environment.Exit(0);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}