How to retrieve the target of a Junction or Symlink with a standard user

匆匆过客 提交于 2019-12-20 01:57:27

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2240734/how-to-retrieve-the-target-of-a-junction-or-symlink-with-a-standard-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!