0

I need to retrieve the paths of certain special folders for the currently logged in user. For example, the current user's desktop.

This is simple using SHGetFolderLocation or ShGetSpecialFolderPath with CSIDL_DesktopDirectory, except if the user has standard rights and the application has been started using "Run as administrator", in which case the path returned is relevant to the administrator account used.

For example: Standard user "X" needs to run an application as admin by right-clicking the exe, selecting "run as administrator", then entering the account details for user "Y" who has admin rights.

CSIDL_DesktopDirectory returns "c:\users\Y\desktop" but I want to get "c:\users\X\desktop"

Thanks for any advice.

J...
  • 30,968
  • 6
  • 66
  • 143
  • This sounds like the wrong solution to your problem. Perhaps what you need to be doing is arranging that your application doesn't need to be run elevated. Or perhaps that the functionality that requires elevation is hived off to a separate process that is run elevated. – David Heffernan Apr 28 '15 at 11:25
  • See Remy's answer in above link about the "token" parameter. – Marco van de Voort Apr 28 '15 at 11:37
  • @J... Unfortunately the dupe closure led to your helpful comment being removed........ – David Heffernan Apr 28 '15 at 11:40
  • @DavidHeffernan So it would seem. I guess I'll add new comments in the future rather than editing the dupe auto-comment. I was largely echoing your original statement, in any case - that while the dupe does answer the question it is not necessarily the preferred solution; the latter being to perform as few operations as necessary in an elevated context. Since writing to the user's desktop does not require elevation that action should probably not be being performed in an elevated process. – J... Apr 28 '15 at 12:27

0 Answers0