Copy/move a symlink/junction to UNC folder through command line

3.9k views Asked by At

I need to find a way to copy/move a symlink/junction from my C: to a network drive.

I am able to create the symlink with MKLINK command but I can't move it to my UNC folder where I need it.

If I try to create it in the UNC folder MKLINK will fail, if I try to XCOPY /b /i I get an error message and the file is not copied.

Of course I can always use Windows Explorer and drag/drop or copy/paste or cut/paste but this is something I need to automate in a batch script.

3

There are 3 answers

1
AudioBubble On

Symlinks are disk dependent.

A hard link is the file system representation of a file by which more than one path references a single file in the same volume.

A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories, and a junction can link directories located on different local volumes on the same computer. Otherwise, junctions operate identically to hard links. Soft links are implemented through reparse points.

From Windows Vista SDK. If you have it installed Hardlinks and Junctions ms-help://MS.MSSDK.1033/MS.WinSDK.1033/fileio/fs/hard_links_and_junctions.htm

Here's something from another of my post's explaining how all files in system32 have two hardlinks (because explorer/cmd shows windows using a few gig more than it actually does).

The current version of a file is hardlinked to the appropiate place in the rest of the file system. A hardlink is a file name. All files have at least one hardlink. Windows system files have two hard links, one in WinSxS and one in (usually) c:\windows\system32. Both names point to the same bytes on disk.

As the files have two names they are counted twice by explorer, once in System32 and once in WinSxS.

There are other uses for it as well. It allows multiple programs to use different versions of dlls.

The point is it stored in the folder file. It's can't be on another disk. Reparse points run code when accessed. For some reason the code allows other drives but not remote.

See if this helps

subst /?

subst k: \\127.0.0.1\C$

or use a shortcut.

0
CHUY SANCHEZ On

I ended up using a VB Script I found somewhere else to create a shortcut. It doesn't care if you save the resulting link on a local or UNC location.

file "createshortcut.vbs"

Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = WScript.Arguments(0)
Set oLink = oWS.CreateShortcut(sLinkFile)
    oLink.TargetPath = WScript.Arguments(1)
 '  oLink.Arguments = ""
 '  oLink.Description = "MyProgram"   
 '  oLink.HotKey = "ALT+CTRL+F"
 '  oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
 '  oLink.WindowStyle = "1"   
 '  oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save

invoke as "cscript createshortcut.vbs link_filename target_location"

0
user1005462 On

not sure if helpfull: I was able to use mklink to local pc when used RDC

during conect in settings add what partion should be connected with RDC,

then if connection active you will able to use mklink to that drive like: \tsclient\I\data .... based on your disc it can be I: or C: D: etc