Thread: hard links in windows

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    hard links in windows

    Is there such a thing as a hard link with windows?

    If so how can one be made?
    "Assumptions are the mother of all **** ups!"

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    umm... ever heard of a shortcut? You can make a link to almost any file/directory you want (where most Linux distros will not allow you to use the ln command to make a hard link to a directory).

    To make a shortcut to any file/folder, right-click and drag a file/folder in any direction. Three options should pop-up and one is to make a shortcut to the item you just dragged. Click and wa-la!

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, there are hard links in Windows (only on NTFS). They are not equivalent to shortcuts.

    They work like Unix hard links and was implemented in NTFS to make it POSIX-compatible

    Even though no Windows GUI uses hard links, you can create them with the function
    Code:
    BOOL CreateHardLink(
      LPCTSTR lpFileName,
      LPCTSTR lpExistingFileName,
      LPSECURITY_ATTRIBUTES lpSecurityAttributes
    );
    the security attributes must be NULL, and the other two parameters should be very easy to understand.

    I used this a long time ago to fake-share in some file sharing program. They are impossible (unlike linux hardlinks) to distinguish from 'normal' files.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    excellent! Thankyou sang drax that is exactly what I was after.

    Yes, i have heard of shortcuts, but if that was what I was asking I would have said symlinks in windows. I would like a program to exist in multiple places with different names, but I was hoping to be more efficient than copying it all over the place. Program has to get its name from argv[0] so shortcuts are out. But thankyou anyway ober.
    "Assumptions are the mother of all **** ups!"

  5. #5
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    ??? You can still send command line arguments to a program with a shortcut!! Don't make something harder than it has to be.

  6. #6
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    really? I didnt know that, I hadn't even considered it but I will now. It would certainly add the advantage of portablility to fat.

    Will argv[0] show up the name of the program or the name of the shortcut?
    "Assumptions are the mother of all **** ups!"

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    argv[0] will hold the name of the program even if invoked with the shortcut....

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Will argv[0] show up the name of the program or the name of the shortcut?
    Just try it and see! You shouldn't really rely on argv[0] for the process name, try something like GetModuleFileName (if available!)

    So, to clarify your question, if you have a program and a link, like so:
    c:\dirA\prog1.exe
    c:\dirB\prog1.exe.lnk
    ... do you want argv[0] to display the same for both, or to be different?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows programming links
    By Ken Fitlike in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2016, 11:12 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  4. Lil Anti Windows Humor
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-02-2002, 12:01 PM
  5. Reformating hard drive with Windows XP
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-14-2002, 03:36 PM