简体   繁体   中英

Windows Explorer (Context Menu)

This is a two part questions for Windows Explorer (context menu).

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. I plan to convert this VBScript code to PowerShell. Is there a better way of doing this in PowerShell? Otherwise, I will convert it and use the same 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". This will allow me to right-click on a folder and select on the entry to get the selected files. 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.

Notice, this is not the same as "HKEY_CLASSES_ROOT\*\shell" since it will run multiple instances of the same script. For example, if I select multiple text files and right-click select Notepad, it would open multiple instances of Notepad for each text file. 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.

Do I have to build the object in C# or something? Or is there another way of doing this without building an object in C#?

在此处输入图像描述

I was able to resolve my second question by adding the shortcut of the script to SendTo folder which is located at:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM