0

How to run pnputil from within a Qt C++ application? The following fails with lstderr showing "pnputil is not recognized as an internal or external command." Presumably because pnputil is a built-in (substituting a non-built-in does work). QProcess class reference says that the "cmd /c" format is a "possible solution" for Windows builtins, but not for me.

QProcess process;
process.start("cmd /c \"pnputil -e\"" );

if (!process.waitForStarted())
    return false;

if (!process.waitForFinished())
    return false;

QByteArray lstderr = process.readAllStandardError();
QByteArray lstdout = process.readAllStandardOutput();
rwhenderson
  • 84
  • 1
  • 6

1 Answers1

0

Your process is probably having the wrong PATH for finding executables. Try calling PnPUtil by full PATH:

%WINDIR%\System32\PnPUtil.exe

You can use for staying in Qt Land:

qgetenv("WINDIR");

If your application will be windows only and you do not mind using native calls:

GetWindowsDirectory();
Sebastian Lange
  • 3,879
  • 1
  • 19
  • 38
  • Doesn't help -- in Windows7 PnPutil is a built-in, doesn't live there (or anywhere)... which is the problem. I can invoke anything that's an executable, the problem is with built-ins. – rwhenderson Jul 24 '14 at 19:23
  • I do run win7 and do have pnputil.exe – Sebastian Lange Jul 25 '14 at 05:36
  • 1
    Did u try calling ```where pnputil```? Whats the return for this command? I've read its missing on some systems, there is a workaround bundling some microsoft (think it has been the DPInst) or making use of native windows api. – Sebastian Lange Jul 25 '14 at 05:47
  • Another approach if this is "shell builtin" would be to spawn a shell running pnputil.exe (could be done in QProcess with in/output) – Sebastian Lange Jul 25 '14 at 05:53