A discussion about running a script in the user context of the currently logged on user, but triggered by a system event. Suggestions were made to use system-based and user-based scripts, with an example of setting and clearing tags using registry values. The issue of user/administrative permissions was discussed.
Read the entire ‘How to Run System-Based and User-Based Scripts in ControlUp’ thread below:
Is there a way to run a script in the user context of the currently logged on user, but triggered by a system event? Whenever I do event log triggers, it is only giving me access to machine based scripts
not really possible as it might be a multi user system so how would it know which user to target
This is a single system VDI so was hoping since there is a 1:1 mapping it’d be possible
you could make it a 2-stepper: a system based sba that sets a specific tag for sessions and a user based one that responds to that (and clear the tag)
do you have an example?
not immediately maybe @member has something
In your computer script
[microsoft.win32.registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Smart-X\ControlUp\Agent\SessionTags", "SomeUniqueKey", "SomeUniqueValue")
Then create a session trigger and attach another script action. The script action does whatever you need it to do and clear the tags. You can clear the tags using:
“`$RegKeyPath = "HKLM:\SOFTWARE\Smart-X\ControlUp\Agent\ComputerTags"
Remove-Item -Path $RegKeyPath -Recurse -Force“`
Do note that to be able to clear tags the user needs to be an administrator. As the tags are stored in HKLM


Alternatively you can also consider invoke-cuaction.
The issue is around the user not being an admin. We are trying to catch if the user is trying to elevate a process with admin credentials so the user is a standard user by default
Are the machines persistent? If not, not being able to delete the tag might not be the worst
mixture of both
If there was a way to do a user context script based on an event ID I’d have everything I need
Continue reading and comment on the thread ‘How to Run System-Based and User-Based Scripts in ControlUp’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers
