Sign in to follow this  
Followers 0
Anteaus

Identifying NTFS Junctions

6 posts in this topic

There are methods for creating and removing NTFS junctions, but I haven't been able to find a way of identifying that a filesystem-object IS a junction, and not a directory.

Any suggestions?

(Background is the usual problem with Vista/7 profiles, in that the cyclic junctions :) in these create problems with enumerating the contents.)

Share this post


Link to post
Share on other sites



From MSDN:

These junction points can be identified as follows:

  • They have the FILE_ATTRIBUTE_REPARSE_POINT, FILE_ATTRIBUTE_HIDDEN, and FILE_ATTRIBUTE_SYSTEM file attributes set
  • They also have their access control lists (ACLs) set to deny read access to everyone.

Share this post


Link to post
Share on other sites

Unfortunately, neither of these provide a definite means of identification.

The only defining attribute here (which is not also possessed by some other filesystem objects) is FILE_ATTRIBUTE_REPARSE_POINT - and this doesn't seem to be accessible by any of the normal routes.

Anyone got a suggestion as to how to access this property?

WMI, maybe? DLL call? Done some poking-around with both but so far got nowhere.

There is of course the cowboy method of parsing DIR output -which does work- but I'd rather avoid that if possible.

Share this post


Link to post
Share on other sites

It was already discussed here : http://www.autoitscript.com/forum/index.php?showtopic=71756&view=findpost&p=524767


Best Regards.Thierry

Share this post


Link to post
Share on other sites

It was already discussed here : #524767

Nice find, Mhz had already posted a function for this (copied for ease of reference):

GetFileAttributes can get the attributes of a symblic link though a flag for detecting a reparse point. The flag also does a symbolic link so not sure of it's accuracy ensuring for certain of symbolic link detection but it tests OK with my brief check with Vista SP1.

; example: returns true if the file is a symbolic link
$var = _ReparsePoint('C:\test.txt')
MsgBox(0, '', $var)

Func _ReparsePoint($string)
    Local $FILE_ATTRIBUTE_REPARSE_POINT = 0x400
    If Not FileExists($string) Then
        Return SetError(1, 0, '')
    EndIf
    $rc = DllCall('kernel32.dll', 'Int', 'GetFileAttributes', 'str', $string)
    If IsArray($rc) Then
        If BitAND($rc[0], $FILE_ATTRIBUTE_REPARSE_POINT) = $FILE_ATTRIBUTE_REPARSE_POINT Then
            Return True
        EndIf
    EndIf
    Return False
EndFunc

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0