none
Psexec is running exe files on remote machine only in the background RRS feed

  • Question

  • Hi,

    Problem Statement: 

    From Jenkins Windows Batch Task, i am running the following command 

    psexec.exe -accepteula -i  \\<machineName> -u "<domain\Username>" -p "<password>" notepad.exe

    Observation : I see that in the remote machine, Notepad is not launched in the foreground but running in the background

    Reason: I think it runs on the background because PSEXEC is trying to connect to the remote machines default console session. The default console session status shows as Connected but Not Active. Psexec will run only on active Sessions.

    Ie if I run psexec.exe -accepteula -i  \\<machineName> -u "<domain\Username>" -p "<password>" qwinsta, I see that Console Session shows status as Conn .

    If i run the same with a valid session id, ie the below command, It works well.

    psexec.exe -accepteula -i 2 \\<machineName> -u "<domain\Username>" -p "<password>" regedit.exe

    Environment : 

    1. My remote machine is a VM. Windows 2012

    Expectation : PSEXEC should be able to execute .exe files on the remote machine in the Foreground.

    Workarounds : I have also enabled WindowAutoLogon on the remote machine and restarted the machine to see if an active console session is created. But that too did not work.

    Can any Help be provided to solve this problem 

    Thanks

    Raj



    • Edited by thinkraj Tuesday, March 10, 2020 10:12 AM
    Tuesday, March 10, 2020 10:11 AM

All replies

  • Starting from Windows Vista exists the sessions separation.

    Session 0 is for Services

    Session 1 is generally the console session, that is the session connected to the physical keyboard and video of the machine

    from 2 on other physical connections or remote desktop connection. Note that when there are two or more physical sessions, only one, the active session is connected to the console

    Now, as you have already discovered the -i parameter works only specifying a session number. So if you run psexec -i without specifying any session, it will run in the console session, which generally is enough if I run from a remote system and need to grab some info.

    If you want to display something on the user screen, you have to connect to the user's session and so the -i should take as a parameter the session number.

    If you simply pass the number 1, and there is no user connected to that session, you will see the notepad or the program you started only if you switch to it with alt+tab in the logon session, because the desktop runs on top of everything hiding the Notepad.

    Without specifying any sessions it will run in the console session:

    If you pass the user's session number, by example 3 in this case, it will run on user's desktop:

    So, bottom line, notepad runs on session 1, but because that session is the session where the OS is waiting for console's logon, it is displayed behind the logon screen. On recent OS version probably it cannot run at all on the console screen.. So you have to list user's active session and run your app there.

    On older OS you can bring your app on stage pressing ALT+TAB in the logon console, but it seems with Server 2019 this no longer works..

    HTH
    -mario


    Tuesday, March 10, 2020 12:46 PM
  • Hi Mario.

    Thanks . Yes , i understand that psexec needs a valid active session id to run programs on the foreground on a remote machine.

    But in my case, I am trying to execute psexec through Jenkins. So, inorder for me to execute, i will need to rdp to the remote machine first and then use the same session in PSEXEC. This is not possible for my automation.

    So what i would need is, As i deploy my VM , i will need the VM to have an active session which i can use to run psexec.

    Are u aware of anything that can create an active session when Windows Starts or so.

    I tried autoLogon but it does not create an active session.

    Wednesday, March 11, 2020 9:12 AM
  • Autologon creates an active session for sure.. I'm just discussing this on another thread:

    https://social.technet.microsoft.com/Forums/en-US/4fc17d8c-40a0-4c86-98a8-cf059f74625f/how-to-login-a-user-so-that-a-program-runs-automatically-after-reboot?forum=windowsinternals

    Look at the steps i used there to create the session..

    HTH
    -mario

    • Proposed as answer by mariora_ Friday, March 13, 2020 7:53 AM
    Wednesday, March 11, 2020 10:07 AM
  • Hi Mario,

    Yes as i said before my WindowsAutologon was not working. But i figured out later that it was basically due to a bad domain name.

    Now i re-enabled Autologon and then disabled Autolock , i am able to run PSEXEC on a active Console session.

    With Autologon, i see that the auto-logged in user, runs as an active Console User.

    this solved my problem. Anywyas, thanks a ton for your detailed info.

    thanks
    raj

    Friday, March 13, 2020 5:09 AM
  • Very well!!

    Thanks for the feedback!

    Greetings!

    -mario

    Friday, March 13, 2020 7:53 AM