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?
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?