PDA

View Full Version : "Process failed to start" Error when using QProcess to run ie4uinit.exe



forgottenduck
7th June 2018, 21:44
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.


QProcess* process = new QProcess();
connect(process, &QProcess::errorOccurred, this, [=]{
qDebug()<<process->errorString();
qDebug()<<process->arguments();
qDebug()<<process->workingDirectory();
qDebug()<<process->processId();
});

connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus){
qDebug()<<" process finished";
});
connect(process, &QProcess::started, this, [=]{
qDebug()<<" process started";
});

QString winPath = QString::fromUtf8(qgetenv("windir")) + "\\System32\\";
process->setWorkingDirectory(winPath);
process->start("ie4uinit.exe", QStringList()<<"-ClearIconCache");
process->waitForStarted();

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?

forgottenduck
11th June 2018, 14:41
SOLVED!

For anyone stumbling onto this thread in the future...

It seems that there is some sort of incompatibility with MinGW compiler and running this particular exe using QProcess. By using MSVC compiler it worked fine. This will be a bit of a problem for my project/organization as we have been using MinGW, but we will have to figure something out.

d_stranz
11th June 2018, 17:07
That seems really unlikely. All parts of Qt that are Windows platform-dependent go through an abstraction layer that eventually ends up making a Windows system call.

My hunch is it has nothing to do with the compiler at all and has more to do with the permissions set in the environment in which you are trying to run the program. That specific program might require elevated permissions in order to run; the standard uninformative Windows error in that case is the one you see, basically, if you don't have permission to run the program, pretend it doesn't exist. If your testing has included running it from a command line where you have admin permissions, then it will work. If you start Visual Studio with elevated permissions, it will work. If you run plain old Qt Creator with no special permission, it will fail.