LabTech Support Forums

Running shell command as currently logged on user

This forum is for discussion of script related issues.

Moderator: jware.connectwise

Running shell command as currently logged on user

Postby oliver.marshall.g2support » Fri Jun 21, 2013 12:33 pm

We need a way to run a shell command as the current user. The command changes the desktop background but needs to run as the current user.

Is there a way, without knowing their password or even what username might be logged on at the time the script is run?

Olly
oliver.marshall.g2support
Full Member
Full Member
 
Posts: 224
Joined: Wed Aug 22, 2012 3:00 am

Re: Running shell command as currently logged on user

Postby omair.azteq » Wed Jun 26, 2013 10:45 pm

Hi Olly,

Did you manage to get an answer for that. I am having a similar problem I am trying to delete a folder located in the %appdata% of the logged in user.

I am not very good at sql but I believe if we call sql query for the user (visible in PC login info on the welcome tab) set the results as a variable and then using that variable we can manage to access logged in user profile. are u good at SQl?
omair.azteq
Newbie
Newbie
 
Posts: 1
Joined: Wed Jun 26, 2013 10:39 pm

Re: Running shell command as currently logged on user

Postby teamits » Fri Jun 28, 2013 10:38 am

You would need the user's password too I think.

If everyone should run it, On domains we normally add "run as the user" registry imports and such from the domain login script. I suppose one could add a shortcut to the All Users Startup folder, and/or a Run registry key?
Steve
teamits
Hero Member
Hero Member
 
Posts: 1577
Joined: Wed Dec 31, 1969 8:00 pm

Re: Running shell command as currently logged on user

Postby john.pdx » Mon Aug 19, 2013 3:18 pm

If I remember correctly...

You can run an IF USER LOGGED IN which will check if a user is logged. If the answer is yes, it will save the session ID to the variable %consolenumber% automatically. From there you can use the Console Shell command to run a command like %windir%\system32\cscript.exe blahblah.

That assumes there is only one logged on user. If you're talking about a terminal server with 100 users you'll have to do an SQL query to gather the list of users, and then parse through each one using the SQL Data Sets with the IF USER LOGGED IN to get the console number.
john.pdx
Newbie
Newbie
 
Posts: 10
Joined: Thu Feb 14, 2013 10:20 am

Re: Running shell command as currently logged on user

Postby jburroughs.awecomm » Mon Nov 27, 2017 12:17 pm

I'm not sure how cscript would help you impersonate a logged on user without their credentials. Run As User within LT scripts is not going to do that for you either. See the below thread which has some explanation.

https://www.labtechgeek.com/topic/1390- ... g-labtech/
jburroughs.awecomm
Newbie
Newbie
 
Posts: 2
Joined: Thu Dec 08, 2016 10:19 am

Re: Running shell command as currently logged on user

Postby teamits » Mon Nov 27, 2017 12:24 pm

Console Shell runs the program through the tray icon which is running as the logged on user.
Steve
teamits
Hero Member
Hero Member
 
Posts: 1577
Joined: Wed Dec 31, 1969 8:00 pm


Return to Scripts

Who is online

Users browsing this forum: No registered users and 3 guests

cron