2

I already took a look at this post: How can I start explorer.exe via C++? which is an old post. I was playing around with batch file command and I wanted to replicate this function using C++

taskkill /f /im explorer.exe

start explorer.exe

I'm using the

system(" ")

command in C++ to make it happen. Here is the code: Note, killing the explorer.exe is working but I can't start it again.

#include "pch.h"
#include <windows.h>
#include <iostream>

int main ()
{
  system("taskkill /f /im explorer.exe");
  system("explorer.exe");
}

Instead of opening the explorer.exe to bring back the windows UI, it open the quick access in windows. Any idea?

TheNoobUser
  • 406
  • 1
  • 5
  • 17
  • can you start it manually? – apple apple Jan 03 '19 at 12:58
  • Manually? You mean by opening task manager and start a process? Yes I can. If I run the first lines of code in a .bat file I get the result I want, however not by using C++ which is my question – TheNoobUser Jan 03 '19 at 13:00
  • OK, thanks. interesting. – apple apple Jan 03 '19 at 13:02
  • You just need to run explorer.exe one using CreateProcess system call. You can found the details in [over hire](https://stackoverflow.com/questions/49652210/kill-my-process-if-the-other-process-is-killed/49652550#49652550) – Victor Gubin Jan 03 '19 at 13:10
  • 1
    Maybe you start 32-bit explored from program? – Alex Guteniev Jan 03 '19 at 22:11
  • Notice that post you've linked to uses `start` command (`system("start explorer");`) – Alex Guteniev Jan 03 '19 at 22:12
  • @AlexanderGutenev Yes, that's one of the reason why I opened this question. I still can't get it to work – TheNoobUser Jan 04 '19 at 08:11
  • If you don't have an instance of explorer already open and you kill it then you are actually killing the main explorer which is used by the Windows OS, your desktop will disappear, when you relaunch explorer all you are doing is reassigning explorer to the OS...try adding a second line to launch another instance of explorer, this will confirm it as a visible instance of explorer will be visible. – SPlatten Jan 04 '19 at 08:35
  • @SPlatten I am currently killing the explorer (and my dekstop disappear) and now I need to restart it after I kileld it. I'm gonna try it thanks! – TheNoobUser Jan 04 '19 at 08:44
  • @AlexanderGutenev I totally missed your suggestion. That fixed it. Builind the solution for x64 instead of x86 worked. I didn't think about it. Thanks a lot – TheNoobUser Jan 04 '19 at 08:49

1 Answers1

-1

using cmd would be%SystemRoot%\Explorer.exe and to use in c ++ it would be if system("C:/Windows/Explorer.exe")

Your code opens the following file C:/windows/sistem32/explorer what is the user interface, and you have to open the one on this path C:/windows/Explorer.exe I hope it works for you, luck..

Example

#include "pch.h"
#include <windows.h>
#include <iostream> 

int main ()
{
   system("taskkill /f /im explorer.exe");
   system("C:/windows/Explorer.exe");
}```