Jump to content
ZenTekDS

Run Process as Logged in User

Recommended Posts

Newer here to everything, appreciate any guidance. Basically, we have a customer running Box Sync. It doesn't run as a service and actually just runs as a background process under the logged in user. So I created a Group that Autojoins on a search to monitor the machines with Box Sync. Then a remote monitor watching the process. Looks like I'll create a new Autofix Alert Template and then I copied an Autofix script to repurpose. However, I don't see a way to launch a process as the current logged in user. Only as admin, system, or a specific user. Is it not possible to relaunch the process if it quits as the current logged in user using a Automate script function?

 

image.png.5bba74b1c2574f6c2536e59ebcdae014.png

 

Appreciate any guidance.

Share this post


Link to post
Share on other sites

Yea the guys on slack pointed me here. Worked well. Wish you could run a script as the logged on user, but doesn't appear to be possible directly. Can run a shell command calling a downloaded script will have to do.

Share this post


Link to post
Share on other sites

So here's how I'm doing this .... Seems to work for me.... Thought I would share.... (yea, code could be prettier)...

1) Test if a user is logged on or not. If they are, go for it ... if not, exit the script. So the next steps are what happens if someone is logged on....

2) Console Shell, echo %username%>c:\windows\temp\Logged_on_user.txt

3) Execute Script, Powershell, Script to Execute is as follows:

$text = Get-Content c:\windows\temp\Logged_on_user.txt -Raw 
$separator = "\"
$parts = $text.split($separator)
if ([string]::IsNullOrWhitespace($parts[1])) {$consoleUser = $parts[0]} Else {$consoleUser = $parts[1]}

$consoleUser = $consoleUser -replace "`t|`n|`r",""
$consoleUser = $consoleUser -replace " ;|; ",";"

You are left with $consoleUser containing the name of the user logged onto the console. From there you can add what ever you like to the script that needed the user name.

Hope this help you and others down the line ....

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×