Two of the questions that we get asked often in the LabTech Geek Slack are usually phrased like this:
- 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
- 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:
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.
This piece of writing is truly a good one it helps new net
visitors, who are wishing in favor of blogging.
Thank you ffor the blog post. Jones and I are actually
saving for just a new guide on this issue aand your writing has made us all to save all
of our money. Your thoughts really resolved all our questions.
In fact, in excess of what we had thhought of ahead of the time we came upon your great blog.
I noo longer nurture doubts annd a troubled minjd because you have totally
attended to the needs right here. Thanks
This is amazing. This will help me install programs by giving temp local admin access & then run from the risers session as the program installs for each user a s a click once .application file.
Second is for removing outlook profiles from the currently logged in user as that is a big issue were having with w7 corrupt profiles hanging outlook fully.
3rd for setting a file association for the user automatically after remotely installing Adobe pro.
Possibilities are endless.
Thanks again Gav!
[…] Running programs/scripts as a logged in user in a LabTech … […]
This is a really great thing.
Sadly, I cannot find the XML you provided after importing it twice. I’m sure I’m doing something wrong, I’ve searched multiple times with multiple words through my entire script section. Can anyone tell me where this script ought to show up?
Nevermind. I figured out my mistake. It would seem I imported the wrong XML. (bonks forehead). Let the floggings commence.
Thanks for this wizardry – and very useful stuff!