M
M
mikeemaine2017-04-05 19:31:09
Active Directory
mikeemaine, 2017-04-05 19:31:09

How to run a program remotely as a local user?

The domain administrator account runs a script that, via psexec, launches nircmd on remote machines with certain attributes. The result of nircmd's work is saving files to a given path. Some variables are registered in the nircmd startup attributes, including ~$sys.username$, based on this, the name of the output file for saving is formed.
The problem is that on the remote machine nircmd is run as the domain administrator, which means that the ~$sys.username$ attribute returns to the file name not the name of the AD account that is currently logged in, but the name of the administrator who launched the script. The question is how to get the name of the current local PC user (domain account), so that it is a variable to create the desired nircmd file name. For example gosha_01.txt , vasya_pupkin.txt.
Of course, the names of local users are not known in advance and must be taken from some variable and substituted into the script.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadir Dolotkazin, 2017-04-05
@Q81c

Try parsing the output of quser . It will not be difficult to cut off the line with the domain admin data and get the name of another active user from the remaining line.
PS
Here is a ready-made PowerShell function that will help you solve your problem.

M
MrDywar Pichugin, 2017-04-05
@Dywar

I think you need to google for the phrase "cmd powershell get logged on users".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question