0

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Sampath
  • 45
  • 2
  • 6

1 Answers1

3

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

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • This solution worked if the remote desktop machine is opened, it is locking the machine and the test scripts ran successfully. But when the remote desktop machine is not opened then the same problem i face, Automation scripts are failing again. – Sampath Dec 11 '17 at 06:00
  • I'm not sure how your system is set up but it's easy to check if query.exe is in system32 or sysnative and save the path to a variable then just use that variable to run – phuclv Dec 11 '17 at 09:09
  • Dude, this is awesome! Kudos @phuclv !! – jdmayfield Aug 31 '18 at 08:44