Jump to content

right click MULTIPLE files in explorer, send to ONE script?


Recommended Posts

I want to be able to right click MULTIPLE files in explorer, then select some command (I know how to add things to the context menu) and then have it launch ONE instance of a script and feed it the paths to ALL selected files as variables. Is that possible with autoit?

(Note: windows default behaviour seems to be to launch one instance of the script for each selected file. I want to avoid that.)

Link to comment
Share on other sites

my guess is u have to play with the HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers registry key

actually no...go to HKEY_CLASSES_ROOT\* create a new key "shell" and under it create another key with the name of the app u wanna use the again under that key create another key called "command" with default value pointing to the app.

For instance HKEY_CLASSES_ROOT\*\shell\my_command_name\command

(Default) C:\Windows\dosomething.bat

Have fun!

Link to comment
Share on other sites

Tzackel,

thanks, but you're helping me with the one thing I need no help with (as I said, I know how to add things to the context menu). I want to know if there is a way to select multiple files in explorer, then right click, then see some command related to a script (the command added through the registry just like you describe) and then -- here comes what I need help with -- when the user clicks that command only ONE version of the related autoit script is launched and it has paths to all the selected files as variables to do things with. When I've tried this with other scripts, clicking the command in the right click context menu results in windows launching one instance of the related script for each file. If I've selected 100 files, then 100 instances of the script are launched. That tends to slow the system down and possible crash the script. I want to avoid that and only launch one script, as I said. Other programs seem to do that so I'd like to know if I can do the same with autoit.

Link to comment
Share on other sites

If I've selected 100 files, then 100 instances of the script are launched.

I have no idea how u can fix this....it seems all other commands under "*" in shellex are references to some sort of dll files that handle all the files u selected at once. Try google for "Context Menu Shell Extension" maybe u can find something useful about :/ (not very easy i presume) Or do some dirty tricks like look for the active controllistview get selected items...etc

If u find out how to do this easier please let me know :).

Link to comment
Share on other sites

It seems like your problem might be in where and how the shell extension is being built. But below is my code I used to get the files selected - I used a shortcut in the "Send to" folder:

#cs ====================================================================================================



    Script Type:        Shell Extension "SendTo" function (only the compiled version works)
    Script Name:        Wipe2.au3
    Compiled Name:      Wipe2.exe
    Script Function:    Wipes seleted files and folders from the drive
    Parameters:         Filepaths and Folderpaths (max. 64 [Win95] to 6400 [Win2000+])
    
    Exit Code(s):
    0  Complete apparent failure - nothing was deleted
    1  Success
    2+  Number of deletion errors + 1 - a log file in @ScriptDir lists all deletions and deletion errors.
    
    Platform(s):
        PentiumII+ or similar, running
        Windows98/WindowsNT4/Windows2000/WindowsME/WindowsXP/WindowsVista
    
    Note(s): This is an extract of the complete program - and won't work except
        to grab those filepaths.
        Installation requires the creation of a shortcut in a user's "SendTo" folder 
        pointing to a compiled version of Wipe. Hit the the ESC key to cancel a 
        wipe operation that was begun.
    
    Author(s):
        Maxwell J. Clevett  <maxwellclevett@att.net> &  AutoIt team <http://www.autoitscript.com/>
    
    AutoIt Version:     3.1.133 (beta) +
    
    ===============================================================================================


=====
#ce


Global $myCmd_Line, $the_Dir, $Hits_errors, $myRe_t
Global Const $LEADING_AND_TRAILING = 3
$myCmd_Line = $CmdlineRaw
$Hits_errors = 1

If $CmdLine[0] > 0 Then
    $the_Dir = _StringExtractDirectory($CmdLine[1])
    Sleep(80)
    Some_Enclo_sed()
EndIf

Func Some_Enclo_sed()

    Local $jeckel_part, $jk_Line, $spl_Line
    $jeckel_part = StringReplace($myCmd_Line, '" "', '*')
    $jk_Line = StringReplace($jeckel_part, ' "', '*')
    $jeckel_part = StringReplace($jk_Line, '" ', '*')
    $jk_Line = StringReplace($jeckel_part, '"', '*')
    $spl_Line = StringSplit($jk_Line, '*')

    If IsArray($spl_Line) Then
        If $spl_Line[0] > 1 Then
            Del_Work($spl_Line)
        EndIf
    EndIf

EndFunc ;==>Some_Enclo_sed

Func Del_Work($arr)
;... code to deal with the array of files
EndFunc

Func _StringExtractDirectory($st_Filepath, $mySwt = 0)
    
    Local $eRet_Val, $C_mv, $myErr, $isFol, $myR_Val, $delim_iter
    Dim $YourPath_Arr
    $myErr = 0
    $isFol = 0
    
; Prep - clean up the passed string
    $C_mv = StringStripWS(StringStripCR($st_Filepath), $LEADING_AND_TRAILING)
    $st_Filepath = $C_mv
    
; Prep - Find delimiter
    SetError(0, 0)
    $eRet_Val = StringReplace($st_Filepath, "\", "\", 1)
    If @extended > 0 Then
        $delim_iter = "\"
    Else
        SetError(0, 0)
        $eRet_Val = StringReplace($st_Filepath, "/", "/", 1)
        If @extended > 0 Then
            $delim_iter = "/"
        Else
            SetError(-2)
            Return $st_Filepath
        EndIf
    EndIf


    If StringRight($st_Filepath, 1) = $delim_iter Then
; the passed string was not a filepath but may have been a folder path
        $eRet_Val = StringTrimRight($st_Filepath, 1)
        $isFol = 1
    Else
        $eRet_Val = $st_Filepath
    EndIf


    SetError(0, 0)
    $YourPath_Arr = StringSplit($eRet_Val, $delim_iter)
    If @error Then
        If StringLen($eRet_Val) = 2 And StringRight($eRet_Val, 1) == ":" Then
    ; Apparent success !
            $myErr = 0
            SetError($myErr)
            Return $eRet_Val
        Else
    ; function failed for unknown reasons.
            $myErr = -1
            MsgBox(0, @ScriptFullPath & " - Error", _
                    "The function failed for unknown reasons.   " & @CR & _
                    "@error = " & $myErr & @CR & _
                    "@ScriptLineNumber: " & @ScriptLineNumber)
            SetError($myErr)
            Return $st_Filepath
        EndIf
    EndIf
    
    $myR_Val = StringTrimRight($eRet_Val, StringLen($YourPath_Arr[$YourPath_Arr[0]]) + 1)
    If StringLen($myR_Val) < 2 Then
; function failed for unknown reasons.
        $myErr = -1
        MsgBox(0, @ScriptFullPath & " - Error", _
                "The function failed for unknown reasons.   " & @CR & _
                "@error = " & $myErr & @CR & _
                "@ScriptLineNumber: " & @ScriptLineNumber)
        SetError($myErr)
        Return $st_Filepath
    Else
; Apparent success!
        If $mySwt = 1 Then
            If StringRight($myR_Val, 1) == $delim_iter Then
        ;
            Else
                $myR_Val &= $delim_iter
            EndIf
        EndIf
        If $isFol = 1 Then
            SetError(0, 1)
        Else
            SetError(0, 0)
        EndIf
        Return $myR_Val
    EndIf

EndFunc ;==>_StringExtractDirectory

Note: This is an extract of the complete program - and won't work except to reference those files.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Tzackel, yes som .dll might be needed. I was thinking that there might have been a need for it before from other scripters so that it already was available for use in autoit scripts. But maybe not. I've tried googling for something like that but will try some more. Will report any findings.

Squirrely1, I'm not so used to autoit so I have to read some more before I can use your code. No problem, but I'd first like to get clear if it can do what I want. You write about the "Send To" folder. Would the code you posted only let multiple files be passed to a single instance of a script IF I utilize the "Send to" part of the context menu in Windows? Because I do not want to use "Send to". I want a command in the "root" context menu, just like other applications have.

Link to comment
Share on other sites

As I recall, bloorg, I am pretty darn certain that it gets all files and subfolders - then I had to deal with them separately, using FileDelete for each file and DirRemove for the directories because it was a deletion script, a way to bypass confirmations and the Recycle Bin.

By the way - "bloorg" - is your sir-name related to "borg" in any way - your secret is maybe safe with me.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

  • 2 months later...

I've been wondering about this for some time now.

Has anyone found a way to submit a list of selected files to a script (all of them to one script) by selecting and right-clicking to launch the script?

CMenu by MHz (http://www.autoitscript.com/forum/index.php?showtopic=12057&hl=cmenu) is the best implementation I've seen. But how is it done?

“Efficiency is doing things right; effectiveness is doing the right things.”-Peter F. Drucker

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...