首页 > 解决方案 > Powershell vs GUI shortcuts

问题描述

I have a file named new.txt. Using GUI I can create a shortcut, for example, "new.lnk". When I click on "new.lnk" file, Notepad is opened with the contents of "new.txt" file. When I create the shortcut using PowerShell

NEW-ITEM -TYPE SYMBOLICLINK -TARGET "NEW.TXT" "NEW.LNK"

I can see the contents of the file using

CAT "NEW.LNK"

but the shortcut file is not working in the GUI: it does nothing.

I expect to see the contents in Notepad editor. The properties of the file created using GUI and PowerShell are the same, except for "Start in" information: blank when the short cut is created using PowerShell and with the path file directory when using GUI.

标签: powershellnew-item

解决方案


符号链接(symlink)不等同于 Windows 快捷方式。在文件系统级别创建符号链接 - 它表示“这是一个具有此类文件名的文件,但内容实际上在另一个文件中”。它的大小是 0 字节,因为它只是指向其他文件。将文件命名为“new-linked.txt”而不是“new.lnk”会更合适。

快捷方式“.lnk”是由 Windows shell 解释的单独文件。它包含目标文件的路径(以及其他附加属性)。如果您从 UI 创建快捷方式然后尝试cat my.lnk,您将看到快捷方式文件本身的内容,而不是目标文件。

要从 Powershell 创建 Windows 快捷方式,请参阅如何使用 PowerShell 创建快捷方式


推荐阅读