"pnputil.exe Not Recognized as Internal/External Command" When Running Post-Installer Action

Updated Oct 26, 2023

Reported In

Software

  • LabVIEW
  • LabVIEW Application Builder Module

Issue Details

I've compiled an installer for my LabVIEW executable that runs an executable or batch file as a post-installer action to install third-party drivers necessary for the LabVIEW executable's execution. I am using pnputil.exe to perform these installations using a format similar to the one below:

pnputil.exe /i /a driver1.inf

When I run my installer my LabVIEW executable installs correctly, but I receive the below error during the post-installer actions that prevents my additional drivers from being installed:

pnputil.exe is not recognized as an internal or external command

What can I do to resolve this error?

Solution

Before we can troubleshoot this behavior, we need to confirm that your executable or batch file is functional on its own. Run your executable or batch file separately from your LabVIEW installer and ensure that it executes without error - if it still gets an error, then there is likely an error in your syntax in your file that you need to identify. If it does execute without error, there are a few steps we can take to narrow down the cause of the behavior:
  1. It's possible that this error is appearing because your post-installer action isn't being run with administrator privileges, even if your LabVIEW installer is. To ensure that your post-installer action executes with administrator privileges:
    • When running your LabVIEW installer, right-click the installer and select Run as Administrator to ensure that the installer is being run with administrator privileges.
    • Encapsulate your post-installer action in a call to the Windows API using the Call Library Function Node to explicitly call your executable or batch file with administrator privileges - an example using the Notepad program is shown below.
Image courtesy of user BowenM on NI Community Forums
You can build the VI which performs this functionality into an executable, and call this "wrapper executable" instead of the post-action executable or batch file that you'd like to call.
  1. If the issue persists after calling the executable explicitly as an administrator, then the issue is likely due to Windows rather than LabVIEW. One potential cause to look out for is being unable to find pnputil.exe due to the bitness of your program - pnputil.exe only exists as a 64-bit application on 64-bit Windows, so if your installer is a 32-bit application, it may not be able to find pnputil.exe due to the default directory for your application not containing pnputil.exe - this is explained in more detail on this StackOverflow page. If you're using a batch file, you can ensure that pnputil.exe is correctly detected by including the following snippet of code before executing your calls to pnputil.exe:
if exist %SystemRoot%\System32\pnputil.exe (
    set "SystemPath=%SystemRoot%\System32"
) else if exist %SystemRoot%\Sysnative\pnputil.exe (
    set "SystemPath=%SystemRoot%\Sysnative"
) else (
    echo ERROR: Cannot find pnputil.exe to install the driver.
    echo/
    pause
    goto :EOF
)
%SystemPath%\pnputil.exe -i -a "%USERPROFILE%\Desktop\Drivers\IPEnabled_001.inf"