1

I have added support for Windows symbolic links in our application using the CreateSymbolicLink function. Our application stores data across a set of actual folders. Our users needed to store some folders outside of one main root folder. The solution we chose was symbolic links. This lets them do things like keep a subset of data in DropBox or stored out on a network drive. So far everything has been working great.

When using Windows Explorer, Windows will show the following message if the link target is not present. This could be caused by a target being renamed or a remote network drive not being available.

Location is not available
C:...\MyLink refers to a location that is unavailable. It could be on a hard drive on this computer, or on a network. Check to make sure that the disk is properly inserted, or that you are connected to the Internet or your network, and then try again. If it still cannot be located, the information might have been moved to a different location.

I am trying to duplicate this check and add the target location so users can tell why no data is present.

A normal directory exists check is not sufficient because the symbolic link is present on the system. I have worked around this by calling CreateFile to open the folder. This causes the target location to be opened instead of the symbolic link. This does fail as needed for my check. Now I am stuck trying to get the target path that the link points to.

I have found this answered Stack Overflow question for reading the Target Location from a symbolic link.
- How do I programmatically access the target path of a windows symbolic link?

However that answer requires a valid handle from opening the directory. In my case I want to find the name for a broken link to help with trouble shooting and fixing the link.

How can I get the target location of a symbolic link without a valid handle?

Community
  • 1
  • 1
Mark Elder
  • 3,987
  • 1
  • 31
  • 47
  • Looks like FSCTL_GET_REPARSE_POINT is the supported method: http://msdn.microsoft.com/en-us/library/aa364571%28v=vs.85%29.aspx – Harry Johnston Apr 27 '12 at 05:31
  • Failing all else, of course, you could shell out to cmd.exe and use the dir command. :-) – Harry Johnston Apr 28 '12 at 02:52
  • Given the number of answers on the question I may need to go that route :-). I'll dig some more into the DeviceIO stuff. I was concerned by comments in the other post that the headers were only in the driver kit. – Mark Elder Apr 28 '12 at 14:11
  • FSCTL_GET_REPARSE_POINT is in the SDK. REPARSE_DATA_BUFFER is only in the DDK, but you could just copy it from the documentation here: http://msdn.microsoft.com/en-us/library/ff552012.aspx – Harry Johnston Apr 29 '12 at 19:33
  • The DDK (actually called the WDK now) isn't all that big a download anyway: http://www.microsoft.com/en-us/download/details.aspx?id=11800 – Harry Johnston Apr 29 '12 at 19:34

0 Answers0