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.

2
  • is your Jenkins 32 bit? Commented Dec 7, 2017 at 15:47
  • i am new to Jenkins. what are the steps to find out Jenkins version ? Commented Dec 8, 2017 at 6:40

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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
Dude, this is awesome! Kudos @phuclv !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.