Skip to main content

Running worklet as end user, not as system

  • October 20, 2020
  • 5 replies
  • 610 views

I have a use case where i need to install a certificate, and the EXE wanting to do that needs to be run as the user. Automox runs as SYSTEM, is there anyway i can execute an EXE as another user (the logged in user) to install the certificate, without prompting the user?

Full context here, under the Windows section: https://duo.com/docs/trusted-endpoints-generic

5 replies

Nic-Automox
  • Former Automox Employee
  • 832 replies
  • October 20, 2020

You can do that using the scheduled task workaround that I use in this worklet:


Forum|alt.badge.img
  • Power User
  • 52 replies
  • October 23, 2020

Please note that:

$currentusr = (Get-WmiObject -class win32_process -ComputerName ‘localhost’ | Where-Object name -Match explorer).getowner().user

only works properly IF there is a user currently logged on when you execute that command above. If the computer is turned on and no user is logged on, $currentusr will be NULL (actually, that line above will fail with an error since getowner().user won’t execute).

Since you want to install a certificate, you should check if there is a user logged on in the “Evaluation” section of the worklet. If no user is logged on, return 0.


Forum|alt.badge.img
  • Power User
  • 52 replies
  • October 23, 2020

If anyone is interested, I have a solution that allows your script to run in the context of the currently logged on user, and it gets triggered only upon user logon. This behaviour is very similar to how per-user GPOs are triggered. I’m waiting for Nic to approve my posting. 🙂


Forum|alt.badge.img
  • Power User
  • 52 replies
  • October 26, 2020

Hmmm post not yet approved. Maybe he is busy. Here it is anyway:

$ShedService = New-Object –comobject "Schedule.Service"
$ShedService.Connect()

$Task = $ShedService.NewTask(0)
$Task.RegistrationInfo.Description = "UserLogonScript"
$Task.Settings.Enabled = $true
$Task.Settings.AllowDemandStart = $true

$trigger = $task.triggers.Create(9)
$trigger.Enabled = $true

$action = $Task.Actions.Create(0)
$action.Path = "cmd.exe"
$action.Arguments = "/c echo %temp% > c:\temp\out.txt"

$taskFolder = $ShedService.GetFolder("\")
$taskFolder.RegisterTaskDefinition("UserLogonScript", $Task , 6, "Users", $null, 4)

This PS code creates a scheduled task that is triggered on user logon, and it will run in the context of the user that just logged on. You can check the contents of the file c:\temp\out.txt to verify this.


Nic-Automox
  • Former Automox Employee
  • 832 replies
  • October 26, 2020

Sorry about that, your worklet is now live!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings