We help IT Professionals succeed at work.
Get Started

SHGetKnownFolderPath - Get token of logged on users

Last Modified: 2013-12-03
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!

Watch Question
Top Expert 2012
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE