I've been using both junction points and hardlinks more and more often during the last couple of months and am quite annoyed by the lack of good support by Windows Explorer, Total Commander (the recent addition of a link-icon to junction points was VERY helpfull addition) and other file managers.
Recently I've settled on using sysinternal's linkd and Anton Popov's HardLink Magic for managing links. Both programs work quite nicely but it's still bothersome to use two very different programs for something that's (from an end-user's point of view) very much alike.
So yesterday I tried to find a better solution for Total Commander in this forum and found, among others, this thread. The suggested "?%T%N %P%N" solution works quite well, but there's still the issue of using linkd for directories and HLM or Microsoft's fsutils for files. There are also some ActiveX and COM Dll's to be found, providing the appropriate interfaces to link files and directories, but never both (ie. I found no such solution).
Which is why I finally decided to try and create a better solution and wrote a Dll and an accompanying JScript myself.
Please keep in mind that fsUtilEx.dll and fslink.js were both created yesterday with some minor adjustments today, so they're not exactly tested as thouroughly as you might wish. I have however tried my best to secure the delting-parts of the code. The DeleteXXX function of fsUtilEx.dll will not delete a file if it's the last instance (ie. with a link count of 1) and won't delete a directory unless it's a junction point (ie. the directory linked to will not get deleted). Furthermore, use the /strict switch when calling fslink.js to get an additional confirmation request before deleting or replacing any file or directory.
Download the package here.
The files:
fsUtilEx.dll
Installation: regsvr32 fsUtilEx.dll
Uninstallation: regsvr32 /u fsUtilEx.dll and delete the file.
Usage: You can access the fsLink API by calling the exported functions from any program (use LoadLibrary()), rundll32 or use it's COM interfaces from a script.
fslink.js
Installation: The script uses functions defined in a file located at the path pointed to by the environment variable JSUTILS (eg. JSUTILS=c:\bin\setup_templates_utils.js). You may however choose any other path and filename, simply adjust the environment variable JSUTILS (Control Panel->System->Advanced->Environment Variables->User variables or System variables).
Uninstallation: Delete the files and remove JSUTILS.
Usage: Run the script without arguments to get a syntax description.
setup_templates_utils.js
Support functions. Not needed unless you wish to use fslink.js.
test.js
The test script I use to verify the interfaces and which shows how to call the function using rundll32, fslink.js and the COM interface. Not needed by fsUtilsEx.dll and fslink.js.
How to use the files:
by calling rundll32:
Code: Select all
rundll32 fsUtilEx,CreateLink c:\progs "c:\Program Files"
rundll32 fsUtilEx,DeleteFolderLink c:\progs
rundll32 fsUtilEx,DeleteLink c:\progs
within a JScript (VBScript very similar):
Code: Select all
var fslink = WScript.CreateObject("fsUtilEx.fsLink.1");
fslink.CreateFolderLink("c:\\temp", "c:\\WINDOWS\\temp");
fslink.DeleteFileLink("c:\\temp\\my_link");
by calling fslink.js:
Code: Select all
fslink /strict /c c:\temp c:\WINDOWS\temp
fslink /c c:\temp\file c:\WINDOWS\temp\file
fslink /strict /d c:\temp
fslink /strict /d c:\temp\file
Functions exported by fsUtilEx.dll:
Code: Select all
CreateFileLink destinationPath targetPath
CreateFolderLink destinationPath targetPath
CreateVolumeLink destinationPath targetPath
CreateLink destinationPath targetPath
DeleteFileLink path
DeleteFolderLink path
DeleteVolumeLink path
DeleteLink path
COM interface IfsLink:
Code: Select all
CreateFileLink([in] BSTR szDestinationName, [in] BSTR szTargetName);
CreateFolderLink([in] BSTR szDestinationName, [in] BSTR szTargetName);
CreateVolumeLink([in] BSTR szDestinationName, [in] BSTR szTargetName);
CreateLink([in] BSTR szDestinationName, [in] BSTR szTargetName);
DeleteFileLink([in] BSTR szName);
DeleteFolderLink([in] BSTR szName);
DeleteVolumeLink([in] BSTR szName);
DeleteLink([in] BSTR szName);
LinkCount([in] BSTR szName, [out,retval] LONG* pVal);
IsLink([in] BSTR szName, [out,retval] VARIANT_BOOL* pVal);
GetLinkTarget([in] BSTR szLinkName, [out,retval] BSTR* pszTargetName);
CreateLink creates links to files, folders and volumes depending on the target path.
DeleteLink deletes linked files, folders and volumes depending on the path.
LinkCount
- for files: Returns the number of instances of that file.
- for folders: Always returns 1.
IsLink
- for files: 1 if the link count is > 1, 0 otherwise.
- for folders: 1 if the folder is linked to another folder, 0 otherwise.
The Volume functions might not work yet.