Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Junction Point using WinApi?

There is CreateHardLink function to create Hardlinks.(Since Win2000)
And there is CreateSymbolicLink function since Vista has been released.

But why isn't there a CreateJunction?

How does mklink make a junction?
And How do I write codes to make junction in my app?

like image 532
Benjamin Avatar asked Sep 01 '10 04:09

Benjamin


People also ask

What is a junction point in Windows?

Junction Points (also commonly referred to as NTFS Junction or Directory Junction) is a type of reparse point which contains a link to a directory that acts as an alias of that directory. Junction points are a Windows exclusive feature, absent in other operating systems.

What is a directory junction Mklink?

A. Directory junctions allow you to join folders together so you can map a directory to any local target directory. Imagine you had three folders, c:\folder1, c:\folder2 and c:\documents.


2 Answers

They're reparse points, so FSCTL_SET_REPARSE_POINT is the magic FSCTL. Here's an example, never tried it but seems right:

http://www.flexhex.com/docs/articles/hard-links.phtml

-scott

like image 159
snoone Avatar answered Sep 23 '22 13:09

snoone


There's currently no built-in single function for creating junctions like there is for symbolic links or hard links. Like snoone said, it's a reparse point, so you have to use DeviceIoControl to interact with it. If I remember correctly, the source he linked is the same source I played around with when I was trying to figure this out, and I don't think I ran into any issues with it.

Alternatively, if you're not against using an external library in your application, and you're going to need functionality for reading/checking/deleting junctions, you might want to look into reparselib, which is a pretty decent library wrapping junctions, symbolic links, mount points, and custom reparse points.

like image 28
Charles Grunwald Avatar answered Sep 20 '22 13:09

Charles Grunwald