#  LN.pl
#  Example 3.3:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script creates UNIX-like hard links on Win32 NTFS volumes.
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


use Win32::API::Prototype;

if( 2 != scalar @ARGV )
{
    print "Syntax:\n  $0 <File to link to> <New Link File>\n";
    exit();
}

my( $NewLink, $File ) = @ARGV;
ApiLink( 'kernel32.dll', 
         'BOOL CreateHardLink( LPCTSTR lpFileName, 
                               LPCTSTR lpExistingFileName, 
                               LPSECURITY_ATTRIBUTES lpSa )' ) 
  || die "This version of Windows does not support CreateHardLink()";
if( CreateHardLink( $File, $NewLink, 0 ) )
{
    print "Link successfully created.\n";
}
else
{
    print "Failed to create link.\nError: ";
    print Win32::FormatMessage( Win32::GetLastError() ), "\n";
}
