I am writing a program in qt that will execute commands in windows.
Here is the method I am using to try to get the commands to work.
bool FirmwareUpdater::RunCommand( QString& command, QStringList& args, int expectedCode )
{
QProcess *proc = new QProcess();
proc->setWorkingDirectory ( "C:\\windows\\" );
int exitCode = proc->execute(command, args );
proc->waitForFinished();
this->stream << command << " " << exitCode << "\n";
return ( exitCode == expectedCode );
}
If I run
QString command = "ping";
QStringList args;
args << "localhost";
RunCommand( command, args );
It works fine and it returns 0;
But if I try any other windows utility it returns -2. Right now im trying to get pnpUtil too work.
QString command = qgetenv( "WINDIR" ) + "\\System32\\PnPUtil.exe";
QStringList args;
args << "-a";
args << updateDriver;
I have the code print the command with the arguments out to me and if I run the command manually it works. But in qt it doesn't.
Perhaps i'm doing something wrong. Is there any other way of doing this without QProcess?
I have also tried calling the static meathod
QProcess::startDetached
But that fails on me too.
CreateProcess()). - Michael Burr