Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading User Environment Variables

Posted on 1999-07-29
12
Medium Priority
?
205 Views
Last Modified: 2010-04-02
Does someone have experience or knowledgebase articles on
how to load user env variables before calling
CreateProcessAsUser ? I would like to provide the new
process the same environment as if the person would have
logged on...
0
Comment
Question by:boyracer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 1201376
Happed to do this recently ;-)

Use

    LPVOID  pvEnv   =   GetEnvironmentStrings   ();

 
        //
        // launch the process
        //
        if (!CreateProcessAsUser(
             hToken,
             NULL,
             pwszCmdLine,
             NULL,
             NULL,
             FALSE,
             NORMAL_PRIORITY_CLASS,
             NULL,
             pwszPath,
             &si,
             &pi
             ))
        {
            //  error...
        }

    FreeEnvironmentStrings  (   ( LPTSTR) pvEnv);

0
 
LVL 86

Expert Comment

by:jkr
ID: 1201377
Ooops, sorry, copy&paste error ;-)

it should of course read

    LPVOID  pvEnv   =   GetEnvironmentStrings   ();

 
        //
        // launch the process
        //
        if (!CreateProcessAsUser(
             hToken,
             NULL,
             pwszCmdLine,
             NULL,
             NULL,
             FALSE,
             NORMAL_PRIORITY_CLASS,
             pvEnv,
             pwszPath,
             &si,
             &pi
             ))
        {
            //  error...
        }

    FreeEnvironmentStrings  (   ( LPTSTR) pvEnv);

0
 

Author Comment

by:boyracer
ID: 1201378
Klasse!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 1201379
Wie, keine 'vorlesungsfreie Zeit'? ;-)

So, noch'n paar Minuten & ich geh heim und mach' Feierabend...
0
 

Author Comment

by:boyracer
ID: 1201380
Bei der Hitze kann man nur nachts aktiv sein ...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1201381
Ja, genau, und deshalb werde ich jetzt in meiner Stammkneipe aktiv werden...

(igitt, erinnere mich, MA is noch heißer als HN...)
0
 

Author Comment

by:boyracer
ID: 1201382
Bei der Hitze kann man nur nachts aktiv sein ...
0
 

Author Comment

by:boyracer
ID: 1201383
oops, irgendwie auf reload gekommen.
jetzt ein kühles blondes...
0
 

Author Comment

by:boyracer
ID: 1201384
hm,
funktioniert das auch, wenn GetEnvironmentStrings
von einem Service (SYSTEM) aufgerufen wird ?

0
 
LVL 86

Expert Comment

by:jkr
ID: 1201385
Ja - kleiner Schönheitsfehler: 'LocalSystem' hat kein User-Environment...

Aber das kann man vorher setzen ;-) ('SetEnvironmentVariable()' vor GetEnvironmentStrings()')

Tschü & Prost (jetzt bin ich weg, vielleicht kuck ich vorn Schlafengehen noch 'mal rein...)!
0
 

Author Comment

by:boyracer
ID: 1201386
hi,
hi,
gibt es eine moeglichkeit, dass localsystem
die user-environment variables ausfindig machen
kann ? (fuer den user, der dann in
createprocessasuser steht)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1201387
Wenn Du HKEY_USERS\.{SID text reprsentation}\Environment lesen möchtest...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question