Running programs/scripts as a logged in user in a LabTech/Automate Script

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:

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



One Comment

  1. Tim Wiser 24th January 2018 at 9:51 am - Reply

    Another trick is to use a REG ADD against HKLM which inserts a command into HKLM\Software\Microsoft\Windows\CurrentVersion\Run which will run a command or script (which needs to be written to a file locally or exist within the single Reg key) each and every time any user logs on.
    A ‘cleaner’ way to achieve a similar result but only have the command execute once is to look at Active Setup. Great for single, one-hit tasks. Active Setup is the thing that appear/appeaed when you logged into older versions of Windows and displayed messages in a box at the top left corner of the screen.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.