Results 1 to 9 of 9

Thread: Can someone help translate or modify this?

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,771

    Can someone help translate or modify this?

    I found this code on SO. It apparently saves the filenames from multiple selected files from explorer, then when all are saved, launches a second program (or should), passing an array of filenames as commandline arguments. I need this program to run invisibly in the background, then launch C:\\Program Files\\WarpDrive\\copyfile.exe when it has acquired all of the filenames. Is this something that could be translated to VB?

    Code:
    Command-Queuer.cmd
    ------------------
    
    @ECHO OFF
    SETLOCAL
    
    :: SETUP PARAMETERS: Control temp file location and delay before running
    SET QueueFile="%TEMP%\Multi-Item-Queue.txt"
    SET /A Secs=5
    
    :: MAIN PROGRAM: If the first instance create the queue and wait, otherwise transfer to queue and exit
    IF EXIST %QueueFile% ( ECHO %* >> %QueueFile% ) ELSE (
        ECHO %* > %QueueFile%
        ECHO Waiting %Secs% seconds for other files to finish queuing then will activate...
        TIMEOUT /T %Secs% /NOBREAK >nul
        
        REM - ADD YOUR CODE HERE TO PROCESS THE QUEUE FILE AS A WHOLE
        REM - Example: Display popup of all file paths selected: Msg %username% <%QueueFile%
        
        REM - ALTERNATIVELY, ITERATE THROUGH EACH LINE OF THE FILE
        REM - Example: FOR /F "tokens=*" %%Z in (%QueueFile%) DO ( COPY %%Z "C:\Backup" )
        
        :: Delete the queue file when finished
        DEL %QueueFile%
    )
    GOTO:EOF
    I then have a registry association and a command. In place of C:\\Program Files\\WarpDrive\\copyfile.exe, i want to run Command-Queuer.cmd. Is this possible, and where should i put this file?

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\myactiontoplevel\Shell\myaction_a\Shell\myaction_a1\Comm and]
    @="C:\\Program Files\\WarpDrive\\copyfile.exe %1"

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,477

    Re: Can someone help translate or modify this?

    I don't really understand what's going on here but you know you can write a dll to add right click options and do whatever you want with the selection. VB.NET can do this; for VB6 language you'd probably want twinBASIC... easier than either vb.net or vb6 and x64 supported (I made a couple of these recently; here and here). Context menu handlers. Much more control than simply shelling a command file. Add an enqueue and enqueue+finish option?

    Or you could use IShellWindows to sit in the background and monitor Explorer windows and record selections.. not sure if that's more what you're looking for.

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,771

    Re: Can someone help translate or modify this?

    Quote Originally Posted by fafalone View Post
    I don't really understand what's going on here…
    The problem with the right click menu is that it runs a program once for every selected file.
    I want it to amalgamate all of the selected file names, then… run a program once for the group of selected files, instead of individually one by one.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,518

    Re: Can someone help translate or modify this?

    Quote Originally Posted by .paul. View Post
    The problem with the right click menu is that it runs a program once for every selected file.
    It looks to me like the code you posted would do that, as well. That looks like it just adds things to a text file, or suggests that you might either iterate through a queue by some means not well described.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,771

    Re: Can someone help translate or modify this?

    Quote Originally Posted by Shaggy Hiker View Post
    It looks to me like the code you posted would do that, as well. That looks like it just adds things to a text file, or suggests that you might either iterate through a queue by some means not well described.
    It will run once for every file, but it just saves the filenames, THEN, on the last run, passes all of the filenames to an executable (i need to modify that part so it runs my app)...

  6. #6
    Banned
    Join Date
    Nov 2024
    Location
    lake Titikaka
    Posts
    3

    Re: Can someone help translate or modify this?

    Yes, it is possible to translate this batch script into a VBScript that runs invisibly in the background and launches `C:\\Program Files\\WarpDrive\\copyfile.exe` when it has acquired all the filenames. Below is an example of how you can achieve this:

    ### VBScript (Command-Queuer.vbs)
    ```vbscript
    Code:
    Option Explicit
    
    Dim objFSO, objShell, objFile, objTextFile, strQueueFile, strArgs, strLine, arrArgs, i
    Dim intSecs
    
    ' Setup parameters
    strQueueFile = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%\Multi-Item-Queue.txt")
    intSecs = 5
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    
    ' Main program
    If objFSO.FileExists(strQueueFile) Then
        ' Append arguments to the queue file
        Set objTextFile = objFSO.OpenTextFile(strQueueFile, 8, True)
        For i = 0 To WScript.Arguments.Count - 1
            objTextFile.WriteLine WScript.Arguments(i)
        Next
        objTextFile.Close
    Else
        ' Create the queue file and wait
        Set objTextFile = objFSO.CreateTextFile(strQueueFile, True)
        For i = 0 To WScript.Arguments.Count - 1
            objTextFile.WriteLine WScript.Arguments(i)
        Next
        objTextFile.Close
    
        ' Wait for other files to finish queuing
        WScript.Sleep intSecs * 1000
    
        ' Process the queue file
        Set objTextFile = objFSO.OpenTextFile(strQueueFile, 1)
        strArgs = ""
        Do Until objTextFile.AtEndOfStream
            strLine = objTextFile.ReadLine
            strArgs = strArgs & " """ & strLine & """"
        Loop
        objTextFile.Close
    
        ' Launch the external program with the collected arguments
        objShell.Run """C:\Program Files\WarpDrive\copyfile.exe""" & strArgs, 0, False
    
        ' Delete the queue file
        objFSO.DeleteFile strQueueFile
    End If
    ```
    ### Registry Association
    You can update your registry association to run the VBScript instead of the batch file. Here is how you can do it:

    ```reg
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\myactiontoplevel\Shell\myaction_a\Shell\myaction_a1\Comm and]
    @="wscript.exe "C:\\Path\\To\\Command-Queuer.vbs" "%1""
    ```

    ### Explanation
    1. **VBScript**: The script creates or appends to a queue file in the `%TEMP%` directory. It waits for a specified number of seconds to allow other files to be queued. After the wait, it reads the queue file, collects all filenames, and launches `copyfile.exe` with the collected filenames as command-line arguments. The script runs invisibly in the background.

    2. **Registry Association**: The registry entry is updated to run the VBScript using `wscript.exe`, which ensures the script runs invisibly.

    Make sure to replace `"C:\\Path\\To\\Command-Queuer.vbs"` with the actual path to your VBScript file. This setup should achieve the desired functionality.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,583

    Re: Can someone help translate or modify this?

    Btw, in Chrome address bar you can type @, select Gemini and enter "translate code" or similar. Then literally copy/paste OP to get content similar to the post above my post.

    cheers,
    </wqw>

  8. #8
    New Member
    Join Date
    Dec 2024
    Posts
    3

    Re: Can someone help translate or modify this?

    The code you found on Stack Overflow seems to be a good starting point, and converting it to VB shouldn't be too difficult. You'll need to create a Windows Forms app to handle the file selection and saving of the filenames, and then use the Process.Start() method to launch the copyfile.exe program in the background when you have acquired all the filenames.

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,477

    Re: Can someone help translate or modify this?

    Quote Originally Posted by .paul. View Post
    The problem with the right click menu is that it runs a program once for every selected file.
    I want it to amalgamate all of the selected file names, then… run a program once for the group of selected files, instead of individually one by one.
    This isn't true. A shell extension receives every selected file at once. Your DLL is called once per right click with all selected files; it's not like adding an association in the registry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width