0

I need to access current user temp folder ,

like : C:\Users\asad\AppData\Local\Temp from a WCF service which is hosted as Windows Service on a local machine.

The Windows service is running with ServiceAccount.LocalSystem because of which System.IO.Path.GetTempPath() returns C:\Windows
and

Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.User)

gives C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Local\\Temp.

But what I require is C:\Users\asad\AppData\Local\Temp. Any help on how to get the mentioned temp path is appreciated.

Thanks

oleksa
  • 3,688
  • 1
  • 29
  • 54
A.R
  • 409
  • 8
  • 21
  • Several users can be logged in into the machine (the same time or one-by-one). So what user temp folder would you like to get ? Also your service can be started (and executed) if there is no user logged in (no active session, console or remote). I'd like to suggest to add `export` folder name to the service configuration and use it instead of `Temp` folder of any user – oleksa Feb 11 '20 at 10:38
  • In this particular case, this service is supposed to run on a localhost , accessed only by a single user logged into that machine. It's a kind of service running on a machine for interaction with a web based plugin. The service will not be accessed by any other user except the logged in one. – A.R Feb 11 '20 at 11:08
  • There is no sense to have service that depends on logged in user. What your service has to do if there is no user logged in but computer is started? You can use Tray application that is running with no window shown. – oleksa Feb 11 '20 at 11:52
  • there is an option to get special user folder please check does [this answer's](https://stackoverflow.com/questions/34992883/c-sharp-windows-service-get-the-current-logged-user-desktop-directory-path) your question. However you have to check somehow that user had not reconfigured `%temp%` environment variable to non standard path. – oleksa Feb 11 '20 at 11:58
  • Thanks oleksa. I will check the link you provided. The service I am working is only meant for consumption on a local machine. It actually works as an web addin for a user on the machine. I will explore tray option also. – A.R Feb 12 '20 at 06:00

0 Answers0