Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We have a system that uses Path.GetTempFile and Path.GetTempPath calls to work with temporary files fairly frequently. This system also runs as the "Network Service" user. We're finding that we're running out of room on the C drive (for other issues, our temp files are cleaned up correctly) and would like to be able to move the temp directory to a different drive.

The easiest solution to this seems to be to change the TMP or TEMP environment variables for the Network Service user, but I only seem to be able to set my own user or the "system" variables that are overwritten by the Network Service user profile. How do I set these variables for the Network Service user?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It's actually pretty difficult. You can use the setx command to set persistent environment variables for other users, but this won't work for NetworkService, because the service accounts have no passwords (so your credentials will always be rejected).

The only way that I know of to do this is using the task scheduler:

  1. Set up a task to run as the user "network service".
  2. Leave the triggers empty.
  3. For the action, have it run cmd.exe with the parameters /c setx temp [target].
  4. Run the task manually.
  5. Delete the task.

This will work to set a persistent environment variable for the NetworkService user. As to whether this will successfully work to relocate the temporary files for that user, or whether it will cause any unpredictable side-effects, I can't say for certain. You may need to reboot to verify if it's putting the temp files where you want them.

You can verify that the environment variable has been changed for the correct user by using the environment command within WMIC.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.