右键单击并选择 Windows 中使用 Ruby 的上下文菜单选项



我怎样才能告诉Ruby右键单击Windows文件夹中的文件,然后从简单脚本的上下文菜单中选择一个选项?

使用

win32utils,您可以避免使用 API 调用将链接发送到桌面:

require 'win32/shortcut'
require 'win32/dir'
include Win32
Shortcut.new(Dir::DESKTOP + 'shortcut.lnk') do |s|
  s.path = "c:\path\to\something.exe"
  s.window_style = Shortcut::SHOWNORMAL
  s.description = "My shortcut to something"
end

您需要win32-shortcutwin32-dir gem;您还需要确定要提供给Shortcut#path的文件路径。这通常很容易完成 Dir#each ,将您感兴趣的目录传递给它,并对你迭代的目录元素进行某种控制。

最新更新