[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
    8,575
    15,646
    270
    #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
    7,221
    2,273
    240
    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
    8,575
    15,646
    270
    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
    3,522
    2,093
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    8,575
    15,646
    270
  6. GezoeSloog

    GezoeSloog knows a guy, who knows another guy.

    Feb 10, 2012
    864
    8,154
    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. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    8,575
    15,646
    270
    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.
     
  8. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,358
    7,077
    210
    #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.