Search code examples
windowsbatch-filejenkins32bit-64bitwow64

Jenkins: Run Windows batch commands in 32-bit mode


Using Jenkins, we have setup automation testing - install application and run test cases in a remote machine. This process is done using a batch file. As it is a windows application I have to logout (remote machine) of the system keeping the session active. For that I have used the below script:

for /F "skip=1 tokens=3" %%s in ('query user testuser') do 
(C:\Windows\system32\tscon.exe %%s /dest:console )

In remote machine, when I run this script manually, it works perfectly. But when the same script (batch file) is run from Jenkins I am getting following error:

'query' is not recognized as an internal or external command, operable program or batch file.


Solution

  • It's because you're running query from a 32-bit process. On 64-bit Windows 32-bit processes will be put under File System Redirector

    In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Access to %windir%\lastgood\system32 is redirected to %windir%\lastgood\SysWOW64. Access to %windir%\regedit.exe is redirected to %windir%\SysWOW64\regedit.exe

    On 64-bit Windows System32 is for 64-bit system tools and SysWOW64 is for 32-bit ones. query is 64-bit only so it won't be available in SysWOW64 and can't be seen by 32-bit processes

    C:\>where query
    C:\Windows\System32\query.exe
    

    You can check this with the 32-bit cmd in SysWOW64:

    >C:\Windows\SysWOW64\cmd.exe /c query user testuser
    'query' is not recognized as an internal or external command,
    operable program or batch file.
    
    >C:\Windows\SysWOW64\cmd.exe /c where query
    INFO: Could not find files for the given pattern(s).
    

    You need to change query user testuser to %windir%\sysnative\query.exe user testuser. Or better change to 64-bit Jenkins