• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1050
  • Last Modified:

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 ?
1 Solution
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
I don't think that a service can access a user specific registry area, but I may be wrong here....
I know they can't write to HKEY_CURRENT_USER, so I will agree with Epsylon on this one till proven wrong ;P

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.

dfillonAuthor Commented:
It's not exactly what I need, but your answer helps me a lot. thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now