'Hardlinks. vbs
'Demonstrate the hard link on the NTFS Volume
'--------------------------------------------------------
Option explicit
'Some Constants
Const l_nohardlinkcreated = "unable to create hard link"
Const l_entertarget = "Enter the file name to hard-link"
Const l_hardlinks = "creating hard link"
Const l_enterhardlink = "Name of the hard link you want to create"
Const l_cannotcreate = "make sure that both files are on the same volume and the volume is NTFS"
Const l_notexist = "sorry, the file doesn't exist"
Const l_samename = "target file and hard link cannot have the same name"
'Are you sure you want to (hard) link the existing file
Dim stargetfile
If wscript. Arguments. Count & gt; 0 then
Stargetfile = wscript. Arguments (0)
Else
Stargetfile = inputbox (l_entertarget, l_hardlinks ,"")
If stargetfile = "" Then wscript. Quit
End if
'The file exists?
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
If not FSO. fileexists (stargetfile) then
Msgbox l_notexist
Wscript. Quit
End if
'Main Loop
While true
Queryforhardlink stargetfile
Wend
'Close
Wscript. Quit
'/////////////////////////////////////// //////////////////////
'// Helper Function
'create a hard link
'------------------------------------------------------
function queryforhardlink (stargetfile)
' If a hard link name is specified on the command line, extract it
dim shardlinkname
If wscript. arguments. count & gt; 1 then
shardlinkname = wscript. arguments (1)
else
dim Buf
Buf = l_enterhardlink & amp; "for" & amp; vbcrlf & amp; stargetfile
shardlinkname = inputbox (BUF, l_hardlinks, stargetfile)
If shardlinkname = "" Then wscript. quit
If shardlinkname = stargetfile then
msgbox l_samename
exit function
end if
'verify that both files are on the same volume and
'the volume is NTFS
if not cancreatehardlinks (stargetfile, shardlinkname) then
msgbox l_cannotcreate
exit function
end if
'create a hard link
dim Ohl
set Ohl = Createobject (" hardlink. object.1 ")
Ohl. createnewhardlink shardlinkname, stargetfile
end function
'Verify that both files are on the same NTFS disk.
'------------------------------------------------------------
Function cancreatehardlinks (stargetfile, shardlinkname)
Cancreatehardlinks = false
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
'Same drive?
Dim D1, D2
D1 = FSO. getdrivename (stargetfile)
D2 = FSO. getdrivename (shardlinkname)
If D1 & lt; & gt; d2 then exit function
'Ntfs drive?
Cancreatehardlinks = isntfs (stargetfile)
End Function
'isntfs ()-verify whether the file volume is NTFS
'--------------------------------------------------
function isntfs (sfilename)
dim FSO, DRV
isntfs = false
set FSO = Createobject ("scripting. fileSystemObject ")
set DRV = FSO. getdrive (FSO. getdrivename (sfilename)
set FSO = nothing
If DRV. filesystem = "NTFS" then isntfs = true
end function