[Q] - How to create a hard link for a file

Discussion in 'Application Software' started by Mr.X, Mar 16, 2017.

  1. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,721
    13,164
    180
    #1 Mr.X, Mar 16, 2017
    Last edited: Mar 16, 2017
    How to create a hard link in C:\Windows if the file is located in D:\Documents\CommandLineScanner\cmdscanner.log


    I want to locate the log file at D:\Documents\CommandLineScanner\cmdscanner.log then create a hard link in C:\Windows

    My goal is to keep the driver from writing at this log file in C:\ which is a SSD. I want to prolong its life as long as I can. The log file grows rapidly as it logs every process and its cmd line found in the system.
     
  2. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,746
    1,959
    210
    Check out the command mklink /h in Windows. That should do the job!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,721
    13,164
    180
    I did check but no luck, it throws an error:
    Then I ask for help.
     
  4. Joe C

    Joe C MDL Guru

    Jan 12, 2012
    2,357
    1,260
    90
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,721
    13,164
    180
  6. GezoeSloog

    GezoeSloog MDL Addicted

    Feb 10, 2012
    671
    2,522
    30
    #6 GezoeSloog, Mar 16, 2017
    Last edited by a moderator: Apr 20, 2017
    You cannot create a hard link between different disks/volumes, but you can make a soft (symbolink) link.

    Code:
    mklink C:\Windows\cmdscanner.log D:\Documents\CommandLineScanner\cmdscanner.log
     
  7. Carlos Detweiller

    Carlos Detweiller MDL Spinning Tortoise

    Dec 21, 2012
    2,287
    1,875
    90
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,721
    13,164
    180
    Could you tell me how to do that please?
    Not much time these days lately... :worthy:

    See, the symlink does not survives a machine restart and when managing the mini driver from its tray application. It just simply vanishes and the real log file is re-created. Maybe the mini driver is quite sensitive to such tweaks.
     
  9. Carlos Detweiller

    Carlos Detweiller MDL Spinning Tortoise

    Dec 21, 2012
    2,287
    1,875
    90
    #9 Carlos Detweiller, Mar 17, 2017
    Last edited by a moderator: Apr 20, 2017
    The system policy is in the Group Policy Editor under Administrative Templates - System - Filesystem - Selectively allow the evaluation of a symbolic link.

    Local admin uses the commandline:
    Code:
    fsutil.exe behavior query/set symlinkevaluation
    But in the end, it depends on how exactly the log is accessed: If the log is simply opened and written into, the symlink should stay in place. However, some applications might delete or rename the log file, then create a brand new one. In this case, symlinking the directory the log is in might help.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...