Two of the questions that we get asked often in the LabTech Geek Slack are usually phrased like this:

  1. I am trying to map a drive/delete a desktop icon/edit the registry for a user in a script and it is not working
  2. How do I run things on the user desktop?

The reason number 1 doesn’t work is because the LabTech/Automate Agent Service that runs on each machine almost always is running as SYSTEM – giving it open access to pretty much everything on the machine. SYSTEM is king. In many ways, SYSTEM is like a user – if Bob logged on to a machine and had a mapped drive of M:, and Mary logged on to the same machine and had a network drive of F:, you wouldn’t expect to be able to map a drive for Mary when logged on a Bob; it’s the same concept here. When you map a drive as SYSTEM (IE from within a LabTech/Automate Script) it maps the drive under the context of the SYSTEM “User”.

There are a number of methods built in to LabTech/Automate to help facilitate you in doing many things for the currently logged on user, at it’s most basic you use the function IS USER LOGGED IN to expose a variable called %consolenumber% – this can then be used in numerous other script functions to execute things in the context of the logged in user.

Instead of going through them in depth in this blog post, I have put all of these actions into a script and added a heavy amount of notes. It is available here: https://github.com/gavsto/Connectwise-Automate-Public-Scripts/tree/master/Running%20as%20a%20user%20in%20an%20Automate%20Script

For those who just love a good screenshot, here is the script: