none
Stopping/intercepting drag and drop of files RRS feed

  • Question

  • Hi

    Have a regular problem where users manage to drag files/folders on network shares into other locations - and then I get support call asking where whatever folder has gone, and eventually locate it drag inside another folder

    I would like to somehow intercept the dragging/dropping of files so I can display some sort of message box asking for confirmation - bit like you get when deleting a file, but instead it comes up and says "Are you sure you want to move these files/folders" and you can click Yes or No

    I know from googling lots of other people have seen same issues with their workers, so know it is not just me

    Any thoughts on how I can using VB.NET create an app to intercept drag/drop to display a prompt

    All ideas/suggestions welcome

    Thanks


    Darren Rose

    Tuesday, September 19, 2017 8:47 PM

All replies

  • I would like to somehow intercept the dragging/dropping of files so I can display some sort of message box asking for confirmation - bit like you get when deleting a file, but instead it comes up and says "Are you sure you want to move these files/folders" and you can click Yes or No.

    You can use the example here:

    https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

    to monitor changes to nominated folders.

    Tuesday, September 19, 2017 10:39 PM
  • To add to what Acamar posted, you'll need to have multiple file watcher objects for each drive because there isn't a way to specify that. If you'll look at the last post in this question:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/ac765eaa-2011-4305-94ae-d7700059287e/drag-and-drop-file-from-datagrid-to-windows-and-change-file-name?forum=vbgeneral

    ... that's what I have it doing there.

    I'm not sure that it's the best way, as I said there, but I don't know of another way.

    When you see the code, look for this line:

    ListBox1.DoDragDrop(data, DragDropEffects.Copy)

    It might be worthwhile to set up a test - in fact use that one if you want - and put a breakpoint there. I think that may be the point where you "intervene" like you want? Let me know your findings please if you decide to test it.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, September 19, 2017 11:07 PM
  • Hi

    Thank you both for your replies

    I was hoping to find some way to intercept the call made to the OS when dragging and dropping files, rather than using a file system watcher.

    I know all about file system watcher as use it for a USB monitoring tool I created but wanted to try something different, as with file system watcher you need to know what folders/drives to monitor and that can vary from system to system, so more wanted some clever way of intercepting the call, perhaps some sort of shell extension

    I know it can be done as there is a tool which does a similar thing, just not sure how it does it

    Using something like this I think = https://code.msdn.microsoft.com/CppShellExtDragDropHandler-bbdb6bac


    Darren Rose

    Tuesday, September 19, 2017 11:25 PM
  • Hi

    Thank you both for your replies

    I was hoping to find some way to intercept the call made to the OS when dragging and dropping files, rather than using a file system watcher.

    I know all about file system watcher as use it for a USB monitoring tool I created but wanted to try something different, as with file system watcher you need to know what folders/drives to monitor and that can vary from system to system, so more wanted some clever way of intercepting the call, perhaps some sort of shell extension

    I know it can be done as there is a tool which does a similar thing, just not sure how it does it

    Using something like this I think = https://code.msdn.microsoft.com/CppShellExtDragDropHandler-bbdb6bac


    Darren Rose

    So to extend the question (which I don't have an answer for but I'm curious to know also) might be: "I'd like to know where the user has chosen to drop the files".

    Would that be a reasonable summary?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, September 19, 2017 11:31 PM
  • I know it can be done as there is a tool which does a similar thing, just not sure how it does it

    Wouldn't it be easier to lock down the server?  That's how most intranets operate.

    Tuesday, September 19, 2017 11:32 PM
  • So to extend the question (which I don't have an answer for but I'm curious to know also) might be: "I'd like to know where the user has chosen to drop the files".

    Would that be a reasonable summary?


    Yes that is definitely a question I would ask - tracking down who has done it I am trying to do with event logs and auditing, but often it is a job of searching through related subfolders to find where they have dragged the folder

    Darren Rose


    • Edited by wingers Tuesday, September 19, 2017 11:45 PM
    Tuesday, September 19, 2017 11:43 PM
  • I know it can be done as there is a tool which does a similar thing, just not sure how it does it

    Wouldn't it be easier to lock down the server?  That's how most intranets operate.


    Not quite as easy as that to be honest - the users need permissions to do the work and access the folders, and there are no permissions you can change to stop users moving folders without also impacting on ability to create/delete and basically do their jobs

    Darren Rose

    Tuesday, September 19, 2017 11:44 PM

  • Yes that is definitely a question I would ask - tracking down who has done it I am trying to do with event logs and auditing, but often it is a job of searching through related subfolders to find where they have dragged the folder

    Darren Rose


    I don't know -- it seems that we're missing an event that *should* exist; one that might likely have a CancelEventArgs (I'm totally guessing here, but if it exists, that would make sense).

    I'll just be quiet and learn. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, September 19, 2017 11:58 PM
  • Yes agreed - will research more tomorrow

    All input welcome :)


    Darren Rose

    Wednesday, September 20, 2017 12:10 AM
  • Not quite as easy as that to be honest - the users need permissions to do the work and access the folders

    So is the situation that the users need to be able to move folders to do their job, but certain movements (such as from the server to the workstation) are not permitted?

    Are they also prevented from using cut and paste to do the move, or is it only drag and drop that is not allowed?

    Wednesday, September 20, 2017 12:56 AM
  • Not quite as easy as that to be honest - the users need permissions to do the work and access the folders

    So is the situation that the users need to be able to move folders to do their job, but certain movements (such as from the server to the workstation) are not permitted?

    Are they also prevented from using cut and paste to do the move, or is it only drag and drop that is not allowed?


    its not that it is not allowed - the problem is users have habit of accidently dragging folders from one place to another

    Darren Rose

    Wednesday, September 20, 2017 12:57 AM
  • This is an example of a tool which does what I want to do - but it is in C++ which I don't understand, so want to achieve equivalent using VB

    https://github.com/broken-e/DragDropConfirm


    Darren Rose

    Wednesday, September 20, 2017 1:37 PM
  • If I understand your question it sounds like you want to create a Shell Drop Handler:

    https://www.codeproject.com/articles/529515/net-shell-extensions-shell-drop-handlers

    You could try the following as well to see if it helps users from accidently performing drag and drop:

    http://www.thewindowsclub.com/disable-drag-and-drop-in-windows


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, September 20, 2017 2:51 PM
  • Hi Paul

    Yes correct, but cannot find much code or examples in vb - everything in c++ or C#

    I had found that article and the associated SharpShell library, but again all in C# and a lot to go through in the downloads to try and make sense of it, but thanks for linking

    Had also thought of changing that setting as a work around, but from quick testing it seems to have adverse effects in other areas where you use drag and drop unfortunately


    Darren Rose

    Wednesday, September 20, 2017 7:01 PM
  • My first response was going to be that it isn't worth the effort, but I thought I would provide an option if you wanted to get into developing a Shell extension. There aren't really any other options, especially since you're trying to handle OS functionality that occurs outside of your app. A global message hook would not be an option since it's not supported in .NET and can cause all sorts of problems when your app fails.

    You may want to tell your users to use Edit...Undo Move from Windows Explorer if they accidently move a file. Otherwise, I'm afraid this is simply user error and you're not going fix all the bad things a user does.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, September 20, 2017 8:03 PM
  • Okay thanks

    Seems you can do it fine in C++ as per the app I linked, so will have to try using that for now perhaps

    I did notice MS didn't seem to approve using shell extensions and had removed most if not all samples they had

    We are talking about network drives / mapped shares etc and edit.. undo doesn't work, and the point is a user doesn't always know they have done it, until other report finding folders missing from data drives etc and then it is too late to "undo"

    Have got auditing in place so can trace who deletes (moves) a file but can't then know where it was moved/dragged too, but can at least give the user a bollocking :)

    Happens too regularly hence why I have been tasked with finding a solution so will keep trying as not going to be beaten!


    Darren Rose

    Wednesday, September 20, 2017 8:07 PM
  • Sure, you can do just about anything in C++ with respect to the OS, since you can generate and work with native Windows libraries and COM directly, but .NET still has limitations in this respect.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, September 20, 2017 8:38 PM
  • Have you considered reducing the mouse drag and drop sensitivity to make it less likely that an inadvertent drag and drop operation will occur?
    Wednesday, September 20, 2017 10:36 PM
  • Have you considered reducing the mouse drag and drop sensitivity to make it less likely that an inadvertent drag and drop operation will occur?

    I have a link for that in one of my posts.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, September 21, 2017 11:49 AM
  • Have you considered reducing the mouse drag and drop sensitivity to make it less likely that an inadvertent drag and drop operation will occur?


    I have a link for that in one of my posts.

    Yes indeed, It was mentioned in the link you posted http://www.thewindowsclub.com/disable-drag-and-drop-in-windows

    But mentioning the technique explicitly doesn't hurt either. :)

    • Edited by RLWA32 Thursday, September 21, 2017 11:59 AM
    Thursday, September 21, 2017 11:57 AM