繁体   English   中英

如何在C#中使用任务栏启动Windows资源管理器

[英]How to start windows explorer with taskbar in c#

我需要更新外壳dll,并确保未使用它,我正在使用taskkill / F /IMexplorer.exe命令杀死当前的Windows资源管理器进程。

但是,当我尝试再次启动资源管理器时,它不带回任务栏,而是搜索使带回任务栏的其他解决方案,但是它们的问题在于,它可以在Windows 8.1、10上运行,但在Windows 7 64位上运行,没有启动,并且也随机启动(有时启动)。

以下是我尝试的解决方案:

解决方案1:

Process.Start(Path.GetDirectoryName(Environment.SystemDirectory) + "\\Explorer.exe");

解决方案2:

RegistryKey localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);

RegistryKey regKey = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
regKey.SetValue("Shell", "explorer.exe", RegistryValueKind.String);
regKey.Close();

Process.Start(Environment.SystemDirectory + "\\..\\explorer.exe");

解决方案3:

var ProcessStartInfo = new ProcessStartInfo();
string anyCommand = "%systemroot%\\sysnative\\cmd.exe /c start /B explorer.exe";
ProcessStartInfo.UseShellExecute = false;

ProcessStartInfo.WorkingDirectory = System.IO.Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Windows\\System32");

ProcessStartInfo.FileName = System.IO.Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Windows\\System32\\cmd.exe");
//ProcessStartInfo.Verb = "runas";
ProcessStartInfo.Arguments = "/c " + anyCommand;
ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
using (var exeProcess = Process.Start(ProcessStartInfo))
{
    if (exeProcess != null)
    {
        exeProcess.WaitForExit();
    }
}

如果要替换正在使用的文件,则始终可以重命名现有文件,并使用现有名称旁边的原始名称复制新版本。

然后是Windows API调用(名称使我无所适从),该调用使您可以计划重新启动时删除重命名的文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM