John Doe
John Doe

Reputation: 1

Call TPath.GetDocumentsPath from within a Service Application

I want to access some files in the MyDocuments folder when I run my service on WIndows. The documentation says that in case of Windows GetDocumentsPath returns:

In my case I get C:\WINDOWS\system32\config\systemprofile\Documents. Is it some kind of link to the Documents directory in Windows? Btw, I see no Documents folder in the C:\WINDOWS\system32\config\systemprofile path.

Can someone explain this to me?

Upvotes: 0

Views: 264

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596256

The Documents folder is a per-user folder. TPath.GetDocumentsPath() returns the Documents folder of the user account that is associated with the calling thread. But if your service is running under the SYSTEM account, not a particular user account, you cannot use TPath to obtain the path of any user-specific folder.

In order for a service to retrieve a user's Documents folder (or any other user-specific folder), the service must either:

  1. be running as the desired user to begin with, not the SYSTEM account.

  2. if running as the SYSTEM account, obtain a token for the desired user account, and then pass that token to SHGetFolderPath() or SHGetKnownFolderPath().

Upvotes: 2

Related Questions