Launching applications remotely with GUI

Reference to old post with the same problem :

https://grokbase.com/p/gg/ansible-project/16442gt7pz/launching-applications-remotely-with-gui

I tried with the below options of launching application in GUI mode both through Power shell and Ansible (win_shell)

Option #1:

Enter-PSSession -ComputerName -Credential $cred
Start-Process ‘C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Snipping Tool.lnk’

Option #2:

Invoke-Command -Computername xxxx -ScriptBlock { start-process ‘C:\Windows\System32\notepad.exe’ }

Option #3:

psexec.exe \XXXX “C:\Windows\system32\notepad.exe”

All the above specified commands run as Background service and not in GUI Mode.

Appreciate suggestions for the same

The same comments in that linked post still pretty much applies here. There is never a guarantee that there will always be an interactive session that has a logged on user so whatever you write will be quite brittle unless you have some pretty in depth checks to conditionally run this beforehand. Ultimately you have to solutions;

  • Use PSExec with the ‘-s -i “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Snipping Tool.lnk”’ argument

  • The value you set for -i is the dynamic session id for the session you want to display this in, you need to get this somehow

  • This is also a security issue as the user will now see a Window that is run with SYSTEM privileges, this means a limited process will now have a way to run things under an admin scope (very dangerous)

  • Create a scheduled task that is set to run when the user is logged in and trigger it either immediate or on the next logon.

The scheduled task is your best bet and you can use win_scheduled_task to do this like;

`

  • name: create task that runs under a user’s interactive desktop
    win_scheduled_task:
    name: Interactive Process
    actions:
  • path: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Snipping Tool.lnk
    triggers:
  • type: repetition
    logon_type: interactive_token
    username: actual_user

`

When that task runs it runs in the context of that particular user.

Thanks

Jordan

Many Thanks Jordan, that was really helpful.

It worked.

Hey Jordan,

As per your suggestion , we are able to launch Application in GUI Mode for interactive session (When user is logged in).

Using “logon_type: S4U” , we are able to launch Application as a Background service, when “user is not logged on”.

Our requirement is to launch an application and take screenshot when “user is logged on or not” (preferably in logged out state).

Attached the screenshot of our requirement: