How to handle multiple files at once with rightclick?

Started by white scorpion, July 06, 2006, 07:20:57 PM

Previous topic - Next topic

white scorpion

Hi all,

as you might know i'm working on a program called shredder which deletes a file securely by rightclicking it and selecting "Shredder".
However, as the program is now, if you select multiple files at once then multiple shredder.exe's are started. all with their own file.
This of course is a bit of overkill, so i want to be able to handle them clean with one process running.

but, how can i get the filenames that are highlighted / selected by explorer?

Another thing:
I was asked to use this program to take over the <SHIFT>+<DEL> function in explorer or create a similar hotkey (<CTRL>+<DEL>).
For taking over i would have to hook DeleteFileW in explorer and reroute the function to mine.
However, i feel more for registering another hotkey, so this will probably be what i'm going to do.


So for all options i have the same problem: I must be able to handle multiple files, and get the current highlighted / selected files.
Are then any API's which can help me solve this issue?

Thanks in advance!

Kind regards,

Mark

asmfan

Mark, some suggestions again. Handling command line can solve the problem. Multiple arguments of command line can be handled (GetCommandLine) but not so easy. There are some difficulties with spaces and <"> in file path of arguments... Take a look yourself on it... Just display a message box with command line...
On hotkeys... Some background task can register it globally...
Russia is a weird place

white scorpion

I know how to handle the commandline, but the problem is that every instance of the program gets it's own file associated with it.
How do i get all those commandline arguments into 1 process of the program?

Try it out yourself if you want. Just install it and highlight multiple files before right-clicking shredder. You will see a messagebox pop up for every file you highlighted and just as many instances of shredder.exe running in taskmgr.

James Ladd

White Scorpion,

My suggestion is the use a Browser Helper Object and I can send you one if you need the guts of one to
get started. These BHO's sit inside explorer IE and Windows File Explorer and get events raised whenever
things happen. This is how some shell extensions work to add functionality.
Im sure there are lots of examples out there with source you can use.

Also, maybe add a new icon to the desktop like the recycle bin but with a shredding icon.
This would be a drop target and if my memory is correct this will get all the file names as
arguments in one go.

I hope that this helps and let me know if you need me to post the BHO code?

Rgs, James.

mnemonic

A thing that spontaneously leaps to my mind is that you could add a startup code to your programm that checks if your program is already running and if it is already running sends it a message containing the filename to be added. WinAMP for example does it like that. And there are many programms out there that you can configure to allow only one instance of.

The FindWindow function would be handy to check for that case.
If it returns NULL your prog is not running and you may simply start, if it returns a valid handle, send a message to that window (e.g WM_USER+666  :wink) and set the name of the file to be added to the list.

Regards
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

white scorpion

thanks mnemonic, that's useful info. I already solved the issue of double instances with the following code, but it doesn't solve the data send to the original instance:


invoke GetFileName,addr FileName,sizeof FileName
mov proc32.dwSize,sizeof PROCESSENTRY32
invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
.IF eax==INVALID_HANDLE_VALUE
mov eax,1
ret
.ENDIF
mov Snap,eax
invoke GetCurrentProcessId
mov pid,eax
@@:
invoke Process32Next,Snap,addr proc32
      test eax,eax
      jz @F
      invoke lstrcmp,addr FileName,addr proc32.szExeFile ;if process shredder.exe is already running
      .if eax==0
      mov eax,pid
      .if proc32.th32ProcessID!=eax
        invoke CloseHandle,Snap
        invoke ExitProcess,0
      .endif
      .endif
      jmp @B   
@@:
invoke CloseHandle,Snap

GetFileName:

GetFileName PROC FileNameLocal:DWORD,FileNameLocalSize

invoke GetModuleFileName,NULL,FileNameLocal,FileNameLocalSize

invoke lstrlen,FileNameLocal
mov ecx,eax
mov eax,FileNameLocal
add eax,ecx
next_Local:
cmp byte ptr [eax],5Ch   ;first '\' from the back
jz contin_Local
dec eax
jmp next_Local
contin_Local:
inc eax
invoke lstrcpy,FileNameLocal,eax
xor eax,eax
ret
GetFileName ENDP



@James:
I totally forgot about the Browser Helper Objects. A lot of spyware uses them as well. I will do some googling to find out how they work exactly.
I was planning on making an extra icon as well, but what would be better?
- rightclick deletion
- extra icon on the desktop
- extra hotkey (<CTRL>+<DEL>)

or should i use all 3 options? Maybe it will be a bit of overkill, won't it?

James Ladd

My suggestion is to do what the adverage user would expect to be able to do.
eg:

1. Right click and select Delete Securely from the popup menu. Id add the item just under the Existing Delete so this doesnt
    change the options too much for the average user.

2. Id add a shredder icon to the desktop and make it a secure delete when the user empties the bin.
    You should make it behave like the existing recycle bin in that people can choose not to
    later is tehy choose. This should work with item 1. in that shredded items go into the shredder and are
    not shredded immediately.

3. Add a hot-key so people can do the same as shift-delete to shred.
    Eg: Ctrl-shift-delete would be the key set I would use.

So just to state it again, give the user what they have now, with the added benefit of
shredding.

If you need a BHO in VB or C/C++ let me know. I dont have one in ASM soz.
Im not sure you need one if you can subclass/extent exporer in some other way
and add your option to the popup menu.

white scorpion

Sounds great, except the recyclebin part will be something special to create.
Any ideas on how to start with that?

James Ladd

Im thinking its just a program with an icon on the desktop. It should work as a drop target
without any effort. The list of files should be the arguments when dropped.
You should be able to try this with your existing program.

white scorpion

That's not really what i meant.
How do you temporary "store" them while they are marked for deletion?
The only thing i can think of is creating a temp file which holds the filenames of the files to delete.

Mark Jones

How about the 1st instance of the program allocates a share-able 16kB block of 256 character elements, then copies the file to delete into the first element. It then proceeds to scan each element in sequence for up to 500ms, deleting the files listed in each element, then terminates. Any subsiquent instances of the program simply copy their filename into the next free shared buffer element, then terminates.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

white scorpion

The idea is nice.
Can you tell me how to create a shared buffer?
How do all instances get their handle / pointer ?

PhM

Hi WhiteScorpion,

The solution to handle multiple files with the mouse right button context menu is a Shell ContextMenu Extension : it's a DLL that is registered (regsvr32) and which sends to Shredder.exe the full paths of the files selected in the explorer. The best would be to incorporate the shedder.exe code in the dll and just regsiter the DLL : everything will be fine and you'll have only one module.
I already developed some of them in C and C++ and I think I saw some code in asm if I find it back in my numerous CDs or ZIP discs I'll send it to you. But maybe you can find some sample code on the web under Shell ContextMenu Extension.
You can build your own context menu in the Shell with icons and submenus...very pro !
Hope it helps.
Sincerly,
Philippe Marechal

KSS

White Scorpion,
you can use Shared Section (fastest way!) to store file list.
Example:
S SEGMENT
Shared_Data dd 0
S ENDS

and in liker command line add " /SECTION:S,RWS"

white scorpion

Thanks guys,

The shellcontext menu sounds exactly like what i need.
I will do some research on it.

@KSS, i will try the shellcontext menu first, but this is something definitely worth remembering!