GetTempPath in a Windows NT service

Using GetTempPath in a simple executable works fine. But as soon as it's a service, the TMP or the TEMP variable is not found.

The TMP and TEMP variables are systems variables, not user.

How can I read environment variables when my program runs as NT service ?
dfillonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aldynCommented:
The Temp and Tmp environement variables are user-specific, they are stored in the HKEY_CURRENT_USER\Environement key.
You can use default values from the
HKEY_USERS\.DEFAULT\Environment registry key.
Another way is to install service into specific user account or use LogonUser+LoadUserProfile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EpsylonCommented:
I don't think that a service can access a user specific registry area, but I may be wrong here....
0
AttarSoftwareCommented:
I know they can't write to HKEY_CURRENT_USER, so I will agree with Epsylon on this one till proven wrong ;P

Tim.
0
freterCommented:
if anybody is interested: i've got some code that does the magic of loggin on a user with a different account. quite impressive: if you are logged on as a plain user , you can start off another process from this code i wrote and bang- the spawned process runs under the context of the administrator :-)

althoug i must admit: the problems with the environment remain. i wanted to add code that loads the registry hive for the respective user, but had no time anymore. if anybody would to add this code, i would be very grateful.

</freter>
0
dfillonAuthor Commented:
It's not exactly what I need, but your answer helps me a lot. thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.