ElektroStudios / Easy-Link-File-Viewer

Desktop application for Windows to read, modify and write shortcut files (.lnk) with ease.
Apache License 2.0
125 stars 13 forks source link

Cut off when file path is longer than 260 chars. #7

Closed kotenok2000 closed 8 months ago

kotenok2000 commented 2 years ago

I can't make this link "C:\Program Files\Google\Chrome\Application\chrome.exe" --task-manager-show-extra-renderers --allow-running-insecure-content --disable-backgrounding-occluded-windows --enable-blink-features=InterestCohortAPI --enable-features="FederatedLearningOfCohorts:update_interval/10s/minimum_history_domain_size_required/1,FlocIdSortingLshBasedComputation,InterestCohortFeaturePolicy"

CongAn commented 1 year ago

I have also encountered this issue, and it is in order to solve it that I came to look for third-party tools.

RedSnt commented 11 months ago

Long ago there used to be a 260 char filename limit in Windows, but that has since been possible to bypass, and is no longer a problem at all in from Windows 10 on. Anyway, that's perhaps why there's a limit.
According to this stackoverflow thread there is a VBS script method that can up the length to 1023 characters before it is truncated.
Actually just tested this method myself, and can confirm that one can get lnk with arguments up to 1023 characters.

set WshShell = WScript.CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
set oShellLink = WshShell.CreateShortcut(strCurDir & "\Chrome with arguments.lnk")
oShellLink.TargetPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "C:\Program Files\Google\Chrome\Application\chrome.exe, 0"
oShellLink.Description = "Chrome shortcut with arguments"
oShellLink.WorkingDirectory = strCurDir
oShellLink.Arguments = "--task-manager-show-extra-renderers --allow-running-insecure-content --disable-backgrounding-occluded-windows --enable-blink-features=InterestCohortAPI --enable-features=""FederatedLearningOfCohorts:update_interval/10s/minimum_history_domain_size_required/1,FlocIdSortingLshBasedComputation,InterestCohortFeaturePolicy"""
oShellLink.Save

Save this VBS script in the Chrome.exe directory (C:\Program Files\Google\Chrome\Application) and it should create a shortcut in the same directory that works. You can obviously tinker with the script as you please, but to make things simple I just set it to use "CurrentDirectory" for working directory and where it saves the LNK file - that way it be useful for other shortcuts in the future.
While you can't verify by opening the LNK file in Easy Link File Viewer or Explorer, you can open a command prompt or powershell console and rename it to a .TXT file then look inside it you can see if it's valid. Obviously, you can also just run the shortcut 🤭.

EDIT: Note that in VBS one use double quotation marks inside a string to present a singular quotation mark so a string set to """1""" in the script would have the value "1".

ElektroStudios commented 8 months ago

Hi!. I am very sorry for the delay in offering a response, but I have had this project quite forgotten and abandoned.

Responding to your question, Easy Link File Viewer internally relies on the usage of various Windows shell interfaces, for example, IShellLinkW, which uses the method IShellLinkW::SetArguments to set the shortcut file arguments. The program uses the Unicode version, which as per the Microsoft documentation says: In the case of a Unicode string, there is no limitation on maximum string length.

However, I was able to reproduce the issue that you've exposed, so I need to check whether my implementation of the interfaces are right, and also, to do further investigation about the limitations of the Windows shell interfaces I'm using and ensure compatibility for larger strings and also for extended file paths.

A new release of Easy Link File Viewer is coming soon, and all the changes and fixes will be reflected on it. I will come back to this Issue when I have more information to offer.

Please note this may take me some time (from few days, to weeks) as there are several other Issues in this project that I also need to offer solutions to. Please be patient.

Sincerely, Elektro.

ElektroStudios commented 8 months ago

The fix has already been implemented in the new source code update. See change log of v1.5.

Please wait for the new release to be published (very soon).

If you have more questions feel free to continue this debate. For now, I consider it completed.

And really sorry again for the delay in my answer.

RedSnt commented 8 months ago

The fix has already been implemented in the new source code update. See change log of v1.5.

Please wait for the new release to be published (very soon).

If you have more questions feel free to continue this debate. For now, I consider it completed.

And really sorry again for the delay in my answer.

No worries, just happy this has been looked at and fixed 👍 (and less of a worry personally as I've moved to linux as daily driver)