2016-01-19 27 views
0

我需要更新我的外殼DLL,並確保它沒有被使用,我使用taskkill/F/IM explorer.exe命令殺死當前的Windows資源管理器進程。如何啓動C#中的任務欄與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(); 
    } 
} 

回答

0

如果你想替換我們中的文件e,您可以隨時重命名現有文件,並使用現有文件名旁邊的原始名稱複製新版本。

然後是Windows API調用(名稱轉義我),它允許您計劃重新啓動時刪除重命名的文件。

+0

Thnx的建議,但在閱讀這個博客後,我不認爲這是一個很好的選擇。 https://marc.durdin.net/2011/09/why-you-should-not-use-movefileex-with-movefile_delay_until_reboot-2/ – zee

相關問題