Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查是否重新启动_C#_.net_Installation - Fatal编程技术网

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);
}