Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 8949

Is there a way to use Linux-like symlinks on a Windows computer, referring to a location on another computer?

$
0
0

My application is writing logs to a directory, which is hardcoded "Logs" and is present under the runtime directory of my application.
Today, a customer asked me if it was possible to have those logs on another place (on another computer).

As a first test, I tried to create a symlink:

  1. I stopped the application.
  2. I removed the "Logs" directory.
  3. Using a WSL on my computer, I created a symlink, something like ln -s /mnt/c/Temp_Folder/TestLog/ /mnt/c/<Application>/Logs.
  4. I started up my application.

I did not see any logs appearing in the directory C:\Temp_Folder\TestLog\.

I see different reasons:

  • Either it's a complete stupid idea to try to use Linux technology on a Windows computer.
  • Either it might work, but some extra things need to be taken into account.

I hope it's the second choice, but in that case, what things do I need to take into account?

Edit after Harry's answer:
Why use WSL's ln -s if you can use Windows technology, like mklink? :-)

I like the idea, but unfortunately it seems not to be working, as you can see from the following experiments:

C:\<Runtime_Dir>mklink /D Logs E:\TestLog\=> result:29/03/2024  08:21    <SYMLINKD>     Logs [E:\TestLog\]

=> So, indeed, the Logs directory symlink is created, but when I launch my application, it seems not to write any logs anymore (I see them being created in a console window, but they are not written down in a file).

Some other experiments: (I remember something about a junction from before, but the details have slipped my mind)

C:\<Runtime_Dir>mklink /D /J Logs E:\TestLog\Local volumes are required to complete the operation.
C:\<Runtime_Dir>mklink /D /H Logs E:\TestLog\The system cannot find the path specified.
C:\<Runtime_Dir>mklink /J Logs E:\TestLog\Local volumes are required to complete the operation.

Edit2 after some more experiments:
It seems not to work, while referring to another drive, but it does seem to work when I refer to another directory on the same computer, as you can see here:

C:\<Runtime_Dir>mklink /D Logs C:\Temp_Folder\TestLog\symbolic link created for Logs <<===>> C:\Temp_Folder\TestLog\C:\<Runtime_Dir>mklink /D /J Logs C:\Temp_Folder\TestLog\Junction created for Logs <<===>> C:\Temp_Folder\TestLog\

I can confirm that, in both cases, the logs are being created!

In other words, the problem is not that the Windows symlink/junction is not working: the problem is with the fact that the symlink/junction is referring to another drive.
I remember that there are two, even three ways to create a drive in Windows (a drive mapping, a subst (?) and another one(???), this is all very blurry in my head), and I'm wondering whether the symlink/junction story might be working on one kind of drive, but not the other, and if there is a way to work around this.

Edit3 after the answer of u1686_gravity:
Even when using UNC path and having the "correct" configured behaviour, it still seems not to work:

fsutil behavior query symlinkEvaluationLocal to local symbolic links are enabled.Local to remote symbolic links are enabled. => That's the one, isn't it?Remote to local symbolic links are disabled.Remote to remote symbolic links are disabled.
C:\<Runtime_Dir>mklink /D Logs \\petrvs01\Log\TestLog\symbolic link created for Logs <<===>> \\petrvs01\Log\TestLog\

The link gets created, but no logfiles are being created over there.

So, as I think I'm the right track here, I decided to perform another test: use the Windows explorer to enter the Logs directory/symlink/junction and create a simple text file, using the explorer's context menu. This does not work because of the following error message:

enter image description here

I have learned three things up to now:

  1. For creating a symlink on Windows, use mklink instead of WSL's ln -s. Open a command prompt as an administrator for this.
  2. For creating a symlink/junction to a remote directory, you need to use the UNC path, not the drive letter.
  3. Permission for creating symlinks/junctions from and to remote directories is checked, using the fsutil command fsutil behavior query symlinkEvaluation.

Next thing I need to learn: where to check for the symlink/junction destination permissions? Does anybody have an idea?


Viewing all articles
Browse latest Browse all 8949

Trending Articles