How to end explorer.exe in Windows 8.1 (it restarts every time I do this)
So, I am writing an application that must terminate explorer.exe before installing it. However, when using the following code, Windows automatically restarts the process:
Dim proc() = System.Diagnostics.Process.GetProcessesByName("explorer.exe")
For Each item as Process in proc()
item.Kill()
Next
Due to this issue, I found a way to kill explorer.exe using taskkill here's the code and it works fine:
Dim taskkill as New ProcessStartInfo
taskkill.FileName = "cmd.exe"
taskkill.Arguments = "/c taskkill /F /IM explorer.exe"
taskkill.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(taskkill)
But I don't want to depend on cmd.exe for this task? Can someone tell me how to do this using vb.net or C # code?
Thank.
source to share
It may not be a good practice to post other answers, so please forgive me, I would just like to direct you by providing a little light on your problem. this answer is actually from the superuser provided by t3hn00b .. All credits to him
for starters, windows (Windows 7 and XP) use the registry key to automatically restart the explorer.so process, to disable it, we have to programmatically reset the value of this key, we can use the code.
Dim key As Microsoft.Win32.Registry
Dim ourkey As Microsoft.Win32.RegistryKey
ourkey = key.LocalMachine
ourkey = ourkey.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", True)
ourkey.SetValue("AutoRestartShell", 0)
' Kill the explorer by the way you've post and do your other work
ourKey.SetValue("AutoRestartShell", 1)
or in C #
RegistryKey ourKey = Registry.LocalMachine;
ourKey = ourKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
ourKey.SetValue("AutoRestartShell", 0);
// Kill the explorer by the way you've post and do your other work
ourKey.SetValue("AutoRestartShell", 1)
In any case, I do not recommend changing the default Windows settings for which there are alternatives (using cmd.exe).
the code will have errors, forgive me for that too. Just tried to sort out your problem a bit. Check it out and make sure it works well in win7 and XP. you can see more details in the superuser link above. Hope this helps. Thanks t3hn00b .
source to share
In vb.net to kill explorer.exe you can use
Try
Dim Processes() As Process = Process.GetProcessesByName("explorer")
For Each Process As Process In Processes
Process.Kill()
Next
Catch ex As Exception
End Try
This will work if you put the code in a timer and start the timer if you want to kill explorer.exe.
In C # try putting it in a timer as well and start it when you want to kill explorer.exe
try {
Process[] Processes = Process.GetProcessesByName("explorer");
foreach (Process Process in Processes) {
Process.Kill();
}
} catch (Exception ex) {
}
Hope it helps.
source to share