psexec – Random IT Utensils https://blog.adamfurmanek.pl IT, operating systems, maths, and more. Sat, 02 Jan 2021 19:05:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Availability Anywhere Part 8 — Running interactive application on a remote server from shell https://blog.adamfurmanek.pl/2020/07/04/availability-anywhere-part-8/ https://blog.adamfurmanek.pl/2020/07/04/availability-anywhere-part-8/#comments Sat, 04 Jul 2020 08:00:33 +0000 https://blog.adamfurmanek.pl/?p=3373 Continue reading Availability Anywhere Part 8 — Running interactive application on a remote server from shell]]>

This is the eighth part of the Availability Anywhere series. For your convenience you can find other parts in the table of contents in Part 1 – Connecting to SSH tunnel automatically in Windows

Imagine that you’d like to run an interactive application on some remote server. This application should have access to UI and ideally pop-up in the session of logged-in user.
There is a psexec tool from Sysinternals and it can run applications remotely. However, it didn’t work for me (I guess some permission issues for remote shares) so I did it with PowerShell.

Run this:

$username = "DOMAIN\USER"
$pass = "PASSWORD"
$pass = convertto-securestring -asplaintext $pass -force
$cred = new-object System.Management.Automation.PSCredential -argumentlist $username, $pass
invoke-command -scriptblock { PATH_TO_SYSINTERNALS\.\psexec -accepteula -s -i 1 notepad.exe } -computername IP -credential $cred

In line 1 you specify username (with domain if needed).
In line 2 you provide a password.
Lines 3-4 create a secure password object.
Line 5 does the magic. First, it uses PowerShell Remoting to connect to the machine over IP with given credentials (see Part 3 how to configure PS Remoting). Next, it executes a command.
In the command we use psexec to run application interactively in session 1. We need to use -s parameter to run the app as a system account, otherwise it will not have an access to the UI. You may also use -u "DOMAIN\USER" -p "PASSWORD" of the session owner instead.

]]>
https://blog.adamfurmanek.pl/2020/07/04/availability-anywhere-part-8/feed/ 1