简体   繁体   English

Windows 资源管理器(上下文菜单)

[英]Windows Explorer (Context Menu)

This is a two part questions for Windows Explorer (context menu).这是 Windows Explorer(上下文菜单)的两部分问题。

First, I have this code in VBScript that gives back to me in a string of all the selected files in an instance of Windows Explorer.首先,我在 VBScript 中有此代码,它以 Windows Explorer 实例中所有选定文件的字符串形式返回给我。 I plan to convert this VBScript code to PowerShell.我计划将此 VBScript 代码转换为 PowerShell。 Is there a better way of doing this in PowerShell?在 PowerShell 中是否有更好的方法来执行此操作? Otherwise, I will convert it and use the same COMObject "Shell.Application".否则,我将转换它并使用相同的 COMObject“Shell.Application”。

Private Function GetSelectedFilesInWindowsExplorer() 'Returns paths as array of strings
Dim oShell
Set oShell = CreateObject("Shell.Application")
    Dim strData
    Dim oSelectedItem
    For Each oSelectedItem In oShell.Windows(0).Document.SelectedItems
        strData = strData & oSelectedItem.Path & vbCRLF
    Next
Set oShell = Nothing

'PURPOSE: Get rid of the trailing vbCRLF
If Right(strData, Len(vbCRLF)) = vbCRLF Then strData = Left(strData, Len(strData) - Len(vbCRLF))
 
    GetSelectedFilesInWindowsExplorer = strData
End Function

Second, with the above code, I can save it into a script and bind the script to a registry entry "HKEY_CLASSES_ROOT\Folder\shell".其次,使用上面的代码,我可以将其保存到脚本中,并将脚本绑定到注册表项“HKEY_CLASSES_ROOT\Folder\shell”。 This will allow me to right-click on a folder and select on the entry to get the selected files.这将允许我右键单击一个文件夹并在条目上单击 select 以获取所选文件。 However, I would like to do it similar to WinRar where I can right-click on any selected files/folders and run the script to get the selected files/folders.但是,我想做类似于 WinRar 的操作,我可以右键单击任何选定的文件/文件夹并运行脚本以获取选定的文件/文件夹。

Notice, this is not the same as "HKEY_CLASSES_ROOT\*\shell" since it will run multiple instances of the same script.请注意,这与“HKEY_CLASSES_ROOT\*\shell”不同,因为它将运行同一脚本的多个实例。 For example, if I select multiple text files and right-click select Notepad, it would open multiple instances of Notepad for each text file.例如,如果我 select 多个文本文件并右键单击 select 记事本,它将为每个文本文件打开多个记事本实例。 This is not what I am looking for.这不是我要找的。

I am looking for similar to WinRar, PowerISO, etc..., it would run only one instance but captured all selected files and feed it to the script or program.我正在寻找类似于 WinRar、PowerISO 等...,它只会运行一个实例,但会捕获所有选定的文件并将其提供给脚本或程序。

Do I have to build the object in C# or something?我必须在 C# 中构建 object 还是什么? Or is there another way of doing this without building an object in C#?或者是否有另一种方法可以做到这一点而不在 C# 中构建 object?

在此处输入图像描述

I was able to resolve my second question by adding the shortcut of the script to SendTo folder which is located at:通过将脚本的快捷方式添加到位于以下位置的 SendTo 文件夹,我能够解决我的第二个问题:

C:\Users\UserName\AppData\Roaming\Microsoft\Windows\SendTo C:\Users\UserName\AppData\Roaming\Microsoft\Windows\SendTo

I also found this tool but I rather use the above because I don't like to install additional stuffs if I can avoid it.我也找到了这个工具,但我宁愿使用上面的工具,因为如果可以避免的话,我不喜欢安装额外的东西。

https://www.thewindowsclub.com/add-customize-send-to-menu-windows https://www.thewindowsclub.com/add-customize-send-to-menu-windows

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “在此处打开管理 Powershell”Windows 资源管理器上下文菜单 - “Open Admin Powershell here” Windows Explorer Context Menu Windows Shell:调用上下文菜单条目 - Windows Shell: Invoke Context Menu entry 从Windows资源管理器的“发送到”菜单调用powershell命令 - Invoking powershell command from Windows Explorer 'Send To' menu 如何在Windows中创建上下文菜单条目以使用管理员权限打开PowerShell? - How to create a context menu entry, in windows, to open PowerShell with administrator privileges? Windows 添加到文本文件上下文菜单“以尾部模式打开” - Windows add to text file context menu "open in tail mode" 将 PowerShell 命令添加到 Windows 上下文菜单(并正确转义引号) - Adding PowerShell command to Windows Context menu (and escaping quotes properly) 如何使用 PowerShell 禁用 Windows 表单标题栏上的右键单击上下文菜单 - How to disable the right click context menu on the title bar of a Windows Form using PowerShell 通过Powershell更新Windows中所有文件扩展名的上下文菜单需要花费很长时间 - Update context menu of all file extensions in Windows via powershell takes long time PowerShell NotifyIcon上下文菜单 - PowerShell NotifyIcon Context Menu 在 PowerShell 中关闭所有资源管理器窗口 - Closing All Explorer Windows in PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM