The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @WheelieNick: Wat me nu het meeste zeer doet is dat mijn gezonde jaren zijn afgepakt. Juist toen had ik de dingen kunnen doen die ik wil… 32 minutes ago
    • RT @MaaikeBallieux: Draadje 🧵 Over rode en groene handjes Zoonlief Bram zit op de bank. Hij wil ons iets vertellen, wat 'heel erg is'. Hi… 33 minutes ago
    • RT @WheelieNick: Wanneer wordt het nou eens bekend wanneer pubers hun booster kunnen krijgen? 36 minutes ago
    • RT @samgerrits: Precies 2 jaar terug sloeg ik alarm over SARS 2.0, (compromis China & W.H.O -> #COVID19). Op basis van dit grafiekje schat… 39 minutes ago
    • RT @locuta: LET OP: Als je 08007070 belt voor het maken van een vaccinatie-afspraak voor een kind, dan krijgen sommige mensen een vraag naa… 41 minutes ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,570 other followers

Archive for January 10th, 2012

great answer by Remy Lebeau on windows – CreateProcessAsUser doesn’t work when “change user” – on Stack Overflow part of @StackExchange

Posted by jpluimers on 2012/01/10

You might wonder why I quoted two great StackOverflow answers recently. Well, it is because I absolutely love the way that and changed how to find quality answers (and questions!) on topics varying from programmers through Cooking to Chines Language Usage in a community based way.

This one is by Remy Lebeau, who is part of TeamB:

You don’t need to enumerate running explorer.exe processes, you can use WTSGetActiveConsoleSessionId() instead, and then pass that SessionId to WTSQueryUserToken(). Note that WTSQueryUserToken() returns an impersonation token but CreateProcessAsUser() needs a primary token, so use DuplicateTokenEx() for that conversion.

You should also use CreateEnvironmentBlock() so the spawned process has a proper environment that is suited to the user account that is being used.

Lastly, set the STARTUPINFO.lpDesktop field to ‘WinSta0\Default’ instead of nil so the spawned UI can be made visible correctly.

I have been using this approach for several years now and have not had any problems with it. For example:

… code sample is in the answer …


via: windows – CreateProcessAsUser doesn’t work when “change user” – Stack Overflow.

Posted in Delphi, Development, Software Development | 2 Comments »

%d bloggers like this: