Using mklink command with network drives - windows-7

I have two network drives that I access through Windows 7: V:\ and T:\ I am trying to create shortcuts between the two that alphabetise with folders (rather than files), so I am using the mklink command:
mklink /d \Photos V:\Photos
which creates a symlink at C:\.
I can move the symlink around locally. However, when I try to move the symlink to a network location, it begins copy the actual files over rather than symlinking them.
I figure that if I can create a symlink of a network drive on a local drive, what's stopping me creating a symlink of a network drive on another network drive. Am I correct in assuming this?
Is there any way to designate the destination file path when creating symlinks with the mklink command? Or is there any way to move symlinks to a network drive at all?

If you need to make a directory junction (using /J) on a network drive, you can first creation a directory (/D) symbolic link and then create a junction off of that, like so:
mklink /D D:\shareLink \\network\share
mklink /J D:\junctionLink D:\shareLink

You need to enable local to remote links by running this command with elevated rights:
fsutil behavior set SymlinkEvaluation L2R:1
Also you can enable this with your local or group policy:
Computer\System\Filesystem\Selectively allow the evaluation of a symbolic link --> allow local to remote

You will need to log onto the computer hosting the network drive and run the mklink command from there.
I recommend creating a junction /J instead of a symlinkd /D. Symlinks have some additional settings you need to be aware of. See symbolic-link-cannot-be-followed.

Related

Unable to change the directory using Git CMD

I'm trying: cd /e/project/
it says: The system cannot find the path specified.
But the drive and folder exists! & the same error shows to all the directory I tried to use.
note: It works with GitBash
/e/project is something MSYS emulates to be able to access the different drive letters on a Windows system. Windows itself does not have a single root directory, but multiple drive letters. This is a mismatch between Linux filesystems, which only have a single root directory (/) and Windows filesystems, which can have multiple roots, designated by their drive letter (A:, C:, D:, …).
In cmd.exe or powersell, it works differently – first you have to select the drive, then change into the directory:
C:\> E:
E:\> cd project
E:\project\>
I'm not aware of a single command to switch drive and directory at the same time. Even if you did:
C:\> cd E:\project
you need to switch the drive aftewards:
C:\> E:
E:\project\>

Windows User home directory

So odd situation here. in AD, we have our user's home directory set as a network drive (D:), so when you open command prompt, it starts you in D:. I need to make a script that copies a file to their desktop. I can't use %userprofile% because it will use D:. Any ideas?
I found out, I was able to use C:\users\%username%\desktop or %UserProfile%\Desktop.

Viewing and copying document on a laptop onto a usb only using command prompt

I am trying to download a file onto a usb from my laptop which is suffering from software issues. I used the command C:users\username>\dir documents on another pc, and was able to view the documents in the folder however, on the laptop in question, the command did not work and I was given the message "The system cannot find the path specified." I am trying to find the name of the document I need to copy so I am requesting a command which enables me to view all documents in the folder. After I find the name of the document, I am also unaware of how I can use command prompt to copy the file onto the USB i have inserted.
I am accessing the command prompt through System Recovery. I do not know code in any form. IMPORTANT Information which may be the reason for the lack of ability to do anything. When I type prompt>dir ****.docx /s /p, I get the message Volume in drive C has no label rather than Windows 7.
This could help-
http://www.dummies.com/computers/operating-systems/windows-xp-vista/how-to-search-for-files-from-the-dos-command-prompt/
As for copying files in cmd, it's as easy as-
prompt>copy <source> <destination>
For changing the drive (to the USB drive), use the "/d" option-
prompt>cd /d <USB drive name>
To view all the contents of current directory, use "dir"-
prompt>dir
Basically, you're not using right syntax. Kindly make cd c:\users and than write dir like this C:> cd C:/Users than your directory will be changed after that you can see C:/Users. So you can write dir in order to see your directories

Windows 7 Symbolic Link - Cannot create a file when that file already exists

I'm trying to create a symbolic link between two directories. I have a directory called TestDocs and TestDocs2. I will be doing all my work in TestDocs, but I need it all to be reflected in TestDocs2. So all files that are in TestDocs2 will be replicated in TestDocs, and if I add a file, change a file, etc in TestDocs it should be reflected in TestDocs2.
So I thought it would be as simple as just doing this:
mklink /D TestDocs TestDocs2
But when I do that I get the error:
Cannot create a file when that file already exists
Why am I getting this?
Also, do I have the order of my TestDocs and TestDocs2 wrong in the command?
Thanks for the help, Symbolic Links have always confused me!
The correct usage is:
MKLINK [options] {link} {target}
You're creating a link, so the link is the new link you're about to create.
And the target is the link's target, which is the existing directory.
Here is how that worked for me.
I wanted to relocate my C:\ProgramData\Package Cache to F: partition.
Steps I had to do:
Physically move "C:\ProgramData\Package Cache" to F:. Now I had "F:\ProgramData\Package Cache" and "C:\ProgramData\Package Cache" is gone since I moved it.
In cmd run (all in one line, split here for readability)
mklink /J "C:\ProgramData\Package Cache"
"F:\ProgramData\Package Cache"
Result:
Junction created for C:\ProgramData\Package Cache <<===>>
F:\ProgramData\Package Cache`
I did this for Google Picasa so I could access photographs on more than one machine. It works very well as Picasa is not really a netowrk enabled program.
For me I did the following:
Install Picasa
Run the application. This will create all the necessary database files.
Close the application.
Navigate to the directory where the database is - on Windows 7 it will be created in c:\users\\AppData\Local\Google
There will be two folders Picasa2 and Picasa2Albums
Copy these folders to a network location. In my case I created a folder called o:\PicasaDatabase and copyied these folders into it.
Next rename the original folders to Picasa2.old and Picasa2Albums.old
Run the following commands from an elevated cmd prompt:
mklink /D "c:\Users\\AppData\Local\Google\Picasa2" "o:\PicasaDatabase\Picasa2"
mklink /D "c:\Users\\AppData\Local\Google\Picasa2Albums" "o:\PicasaDatabase\Picasa2Albums"
Two symbolic links will have been created in the source location and they will point to the network drive.
Obviously using symbolic links like this is a workaround for application that are not networkable and only one user can access the database at once.
I had the same issue. You have to make sure the Source folder does not already exist. (if it does , then rename it to something else)
In case of below Backup folder should not exist under MobileSync. Since Apple iTunes looks for Backup folder with that name, just rename the existing folder to something like OriginalBackup to avoid iTunes from finding it. Instead the mklink will synonym Backup to D: folder as below
mklink /J C:\Users\Dell\Apple\MobileSync\Backup D:\Apple\Backup\iPhoneXRBackup
I had this error. Two things I did to fix it.
check I was actually in the directory I thought I was and not another one with a very similar path.
put quotes around the new link name.
First attempt:
mklink /d \shared_files ....\my-app-public\src\shared_files
gave error described.
Second attempt:
mklink /d “.\shared_files” ....\my-app-public\src\shared_files
worked fine.

Is there a way to map a UNC path to a local folder on Windows 2003?

I know that I can map a UNC path to a local drive letter. However, I am wondering if there is a way to map a UNC path to a local folder. I have a program that has a specific folder hard coded into the program and I am wanting to try and create a folder with the same name that is mapped to a UNC path so that the data can be accessed from a network share. Is this doable? Specifically this is on a Windows 2003 server.
Yes, there is a way to map a UNC path to a local folder:
C:\>mklink /D Develop \\obsidian\Develop
symbolic link created for Develop <<===>> \\obsidian\Develop
This is because i want a build server to use my own PC's Develop folder as its Develop folder:
10/20/2012 11:01 AM <SYMLINKD> Develop [\\obsidian\Develop]
And there you have it.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: In my actual situation i needed another level of redirection, because the program i'm using realized that Develop was a symbolic link, pointing to a remote machine, and refused to comply. i told the program to shut up and do what it's told by giving it a junction that points to a local resource.
10/20/2012 11:06 AM <JUNCTION> Develop [C:\Develop2\]
10/20/2012 11:01 AM <SYMLINKD> Develop2 [\\obsidian\Develop]
This meets exactly what the OP asked for - a symbolic link for Windows 2003 that maps to a network share. After many hours looking at others and testing them, this is the only component I found that will work with network shares.
Symbolic Link Driver for Windows XP
This utility will work for both XP and 2003 mapping to a network share and creating a symlink: http://schinagl.priv.at/nt/ln/ln.html#symboliclinksforwindowsxp
Now put this in a directory that you put on the path and you have the ability to create symlinks using senable.exe (with symlink.sys) and ln.exe (you will need that from the above site as well along with its dependency on the Visual C++ runtime DLLs).
Added Bonus: Fake out MkLink
Put these additional two files into the same directory where you have senable.exe and make sure this is all on the path.
mklink.cmd:
#echo off
SET DIR=%~dp0%
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%Symlink.ps1' %*"
pushd "%DIR%"
"%DIR%senable.exe" start
popd
Symlink.ps1:
param (
[string]$symlinktype,
[string]$link,
[string]$target
)
$scriptpath = $MyInvocation.MyCommand.Path
$ScriptDir = Split-Path $scriptpath
$senable = Join-Path "$ScriptDir" senable.exe
$ln = Join-Path "$ScriptDir" ln.exe
pushd "$ScriptDir"
& cmd /c "$senable" install
popd
& cmd /c "$ln" -s "$target" "$link"
Note:
You need the following other items installed on Windows 2003 (non-R2, I'm not fully sure what you need for R2 yet):
Microsoft .NET Framework 2.0 Service Pack 1
Windows Imaging Component
Windows Server 2003 Service Pack 2
Windows Management Framework Core (this brings PowerShell 2)
Chocolatey Package
I created a chocolatey package that will do all of this for you: http://chocolatey.org/packages/win2003-mklink
Important Note
Unlike regular symlinks, you can not simply delete the folder to remove the symbolic link folder. If you do that, it will delete the real folder it it pointing to. So use with extreme care.
You can't do it directly, but if you create a symbolic link you should be able to point it at the Mapped drive letter.
net use e: \\\\shares\folder # You will want to set this up persistent or next reboot will break it.
Browse using cmd to your location you want the link:
cd c:\folder
mklink /d name e:\
Now anything that accesses c:\folder\name\ will be accessing \\\\shares\folder\
According to Microsoft YOU CAN NOT map a shared folder on a remote machine (server) to a local folder.
For example, this will not work:
shared folder on Server: \\\Server\share1
mapped share on a local machine: c:\MyProgram\Some_Useful_Files_Here
As Microsoft stated, you CAN NOT do mklink on a remote machine; at least not for Junction or Hard-links. You can ONLY do it as a Symbolic link, which is basically a shortcut.
So if a certain program needs access to a local folder which is the same as on the server, sorry no luck! Windows is not Linux, let's not forget that :-(
You cannot map it directly, no. You could try implementing a Shell Namespace Extension that is registered as part of the file system so you can root it where you need, and then have it access the UNC path internally. Not a trivial thing to implement, but it should give you the end result you are looking for.
After much trying I finally figured out that you cannot do it the way I wanted to. I tried a symbolic link using the mklink functionality in Server 2008, but it turns out that the .NET System.IO api does not recognize symbolic links.
So, if you do a Directory.GetFiles() on a folder that is symbolically linked it will throw an error.
Assuming you want to map \\moo\cow to C:\cow_files, and that there is not already a server called moo (if there was you could just share the folder directly, so I assume there isn't), you could:
Edit the hosts file (or your actual DNS if you can) to map moo to the machine with C:\cow_files on it. (Or to localhost if the directory is local to the client that needs the mapping.)
Share C:\cow_files as cow on that machine.
You should then be able to map to \\moo\cow and get the files you need, unless I've missed something (which is possible :)).

Resources