So I'm trying to put code in my application to refresh the user's icon cache so that I can ensure that their project files get the appropriate icons associated with them.

In order to do this, I need to run ie4unit.exe which is in System32. This should be simple, but for some reason I can't run this from Qt no matter what I try. I'm hoping I can get some insight from here.

Here's the code, I did test this in an isolated new project and it still doesn't work.

Qt Code:
  1. QProcess* process = new QProcess();
  2. connect(process, &QProcess::errorOccurred, this, [=]{
  3. qDebug()<<process->errorString();
  4. qDebug()<<process->arguments();
  5. qDebug()<<process->workingDirectory();
  6. qDebug()<<process->processId();
  7. });
  8.  
  9. connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus){
  10. qDebug()<<" process finished";
  11. });
  12. connect(process, &QProcess::started, this, [=]{
  13. qDebug()<<" process started";
  14. });
  15.  
  16. QString winPath = QString::fromUtf8(qgetenv("windir")) + "\\System32\\";
  17. process->setWorkingDirectory(winPath);
  18. process->start("ie4uinit.exe", QStringList()<<"-ClearIconCache");
  19. process->waitForStarted();
To copy to clipboard, switch view to plain text mode 

You can see I have some debug statements in there. The output I'm getting is:

"Process failed to start: No such file or directory"
("-ClearIconCache")
"C:\\Windows\\System32\\"
0
So it is not starting because it can't find the file, the arguments are being provided correctly, and the working directory is set up correctly. I have confirmed that I can run this via command line with the command "ie4uinit.exe -ClearIconCache". The file does exist in the correct location.

Not only that, but if I pick a different exe from System32, such as "dvdplay.exe" It runs fine. I get the "process started" and "process finished" debug messages. The code is the same, and the directory is the same, the only thing I did was change the exe in process->start().

I thought maybe the error message was misleading and this was a permissions problem, but I checked the permissions of dvdplay.exe and compared them to the permissions of "ie4uinit.exe". The permissions are all exactly the same.

I'm at a bit of a loss here.

Any suggestions?