Avatar of Elime
Elime
Flag for Switzerland asked on

SHGetKnownFolderPath - Get token of logged on users

Hey there

My daily business is software deployment, software packaging, installation automation. In order to do so it is often required to put some datas into the userprofile(s) that is (are) currently logged on to the system.

To avoid a logoff (for example when installing via SCCM or other deployment tools) i want to create a little tool that is going to update the current user profile straight away.
(for your info: When deploying an app the current user is a SYSTEM account! NOT the CU of the System)

For now we used a vb script that enumartes through HKEY_USERS, find all SIDS with a "Volatile Environment-Key" and update those (you can get to the profiles folder from this key on too, not only registry).

As this key is not documented and I am writing a C#-App I want to do it properly. Now that seems to be a problem :) In order to "do it properly" I'm supposed to use SHGetKnownFolderPath (Vista and up). There I need the Token of the Users. Which I am not able to get for all logged on users: Only the current user is passed by using System.Security.Principal.WindowsIdentity.GetCurrent(); LsaEnumerateLogonSessions wont give me the needed information and to get a token of a users via WTSQueryUserToken oder others I need higher privleges (LOCAL SYTEM).

That's why I am asking if ANY of you has got an idea that is going to work without a big "walk to the moon and back". I know there are solutions like increasing the privileges and other dirty stuff but if there is another way I'd like to go for it :)

Thanks very much!

Microsoft DevelopmentSystem Programming

Avatar of undefined
Last Comment
Elime

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jkr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Elime

ASKER
Yeah I read about that. I'll have to use a processIdTosessionId() in case more than one user is logged on. Seems to be the way to go on that problem. It seems like workaround that's why I was wondering if there was clear solution to this problem. There seems not to be so I'm fine with workarounds :)

Thanks a lot
Elime

ASKER
Yeah I read about that. I'll have to use a processIdTosessionId() in case more than one user is logged on. Seems to be the way to go on that problem. It seems like workaround that's why I was wondering if there was clear solution to this problem. There seems not to be so I'm fine with workarounds :)

Thanks a lot
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes