簡體   English   中英

克服 Windows 7 shell MAX_PATH 限制

[英]Overcome Windows 7 shell MAX_PATH limit

如果啟動某些可執行文件的上下文菜單鍵存在於 Windows 注冊表中,並且提到了"%1"命令行參數占位符,則此可執行文件通過GetCommandLine()獲取的路徑僅限於MAX_PATH ,在某些情況下 Windows 會嘗試創建短路徑從中取名。

例子:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\showpath\command]
@="\"C:\\Program Files (x86)\\Utilities\\COMLINE.EXE\" \"%1\""

當路徑是:

"\\\\SERVER\MediaFilder25\Philosophic\20220407 Draft thoughts. Questions without answers on the background of the torn Internet\20220407-1 Draft thoughts. Questions without answers on the background of the torn Internet\20220407 Draft thoughts. Questions without answers on the background of the torn Internet.ysssss"

COMLINE.EXE 將得到以下內容:

"\\\\SERVER\MediaFilder25\39FC~1\202204~3\202204~2\20220407 Draft thoughts. Questions without answers on the background of the torn Internet.ysssss"

如今, string長度不受限制。 NTFS 路徑深度也不受限制。

如何克服這個?

注冊表中有一種允許長路徑的方法,在此 URL中進行了解釋。

我歸結為以下注冊表項:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

為了知道您當前的價值,您可以這樣做:

reg query "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" | findstr "LongPathsEnabled"

它僅限於 Windows 10,版本 1607 及更高版本,但您的問題是關於 Windows 7。

Windows 10,版本 1607 包含api-ms-win-core-path-l1-1-0.dll

有一個api-ms-win-core-path-l1-1-0.dll的副本版本,它可以像 Windows 10,版本 1607 那樣操作長路徑。

源代碼可在此處獲得: https://github.com/nalexandru/api-ms-win-core-path-HACK

在將平台工具集切換到 v110 並成功測試后,我設法在 Visual Studio 2012 中編譯它,例如,使用現在依賴於此 DLL 的 Python 3.9。

我認為,Windows 7 shell 不能利用開箱即用的LongPathsEnabled注冊表參數,應用程序應直接使用此 DLL(但在這種情況下 - 為什么要使用 DLL?我們可以在應用程序中構建正確的 function ). 我的問題是 shell 是否可以利用它,答案是 - “還沒有”。 這取決於 shell 本身。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM