4

I am trying to get the target of a junction in my program, but the only way I managed do it is:

  1. Requesting Backup privileges
  2. p-invoke CreateFile with special parameters to get a handle to the file/dir.
  3. DeviceIoControl call to the get the target.

The 1st step will not work with normal user accounts, because they have no Backup privileges, and I don't want to get the UAC User Consent window every time I do this.

I think this is doable somehow, because a normal "dir /A:L" command resolves the target of the links.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Zolka
  • 221
  • 1
  • 3
  • 8
  • There's a solution here at SO already: http://stackoverflow.com/questions/221417/how-do-i-programmatically-access-the-target-path-of-a-windows-symbolic-link – Igor Korkhov Feb 10 '10 at 22:19
  • Thanks for your answer, but unfortunately the GetFinalPathNameByHandle function needs a handle, and getting a handle on a folder needs that Backup privilege I mentioned. But, it is good to know about that API, I might need it later. So thank you for your answer. – Zolka Feb 11 '10 at 18:47
  • My accepted answer was deleted by a moderator. Not even converted to a comment, bizarre. The blog post link: http://blog.kalmbach-software.de/2008/02/ – Hans Passant May 12 '16 at 21:55

1 Answers1

0

I think that this answer in stackoverflow would help you? How do I programmatically access the target path of a windows symbolic link? It should be possible to include a reference to the function via DllImport Attribute in a c# program.

The required handle is obtainable from the a FileStream instance. Somewhat funny that it is marked as obsolete, but maybe the warning states what else you can do.

Community
  • 1
  • 1
flq
  • 22,247
  • 8
  • 55
  • 77