Jump to content

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?




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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...