Results 1 to 7 of 7

Thread: .NET (C#) - intercepting file operations?

  1. #1
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre

    .NET (C#) - intercepting file operations?

    I'm trying out some different ideas for how to implement my latest project, and i've started looking into the possibility of intercepting certain file operations and handling them myself, as opposed to letting windows do it - or alternativly block the operation while I do some processing (probably the best option actually).

    As an example of what I am trying to achieve, say a user has a networked drive attached, called D:

    They want to copy fileA to D: , so they drag and drop it onto the D: icon in explorer.

    Usually windows would then copy the file over, and thats it[as far as the user is concerned]. What I want to do is when the user drags the file over and drops it, to be able to intercept that event and present the user with some extra options before continuing. To keep things simple for now, we'll say a confirmation box to make sure they want to copy the file.

    Now I know that I can monitor folders etc with the 'fileSystemWatcher', but as far as I know that doesn't let me put a block on the actual operation while I execute my code, or abort the operation itself.

    I'll keep looking for a way, but if anyone has any ideas or can point me to a class that can do this I'd be grateful, I know we have a couple of .NET experts on here

    Thanks in advance,

    Spud/Pete

    [edit] I should add that i'd prefer to do this all using .NET libraries or pure c# if possible, rather than having to mess about with COM interop to get it done..but if thats the only way then so be it ;/
    Last edited by Spud1; 01-02-2007 at 07:03 PM.

  2. #2
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    basically it depends at what level you want too do this.

    Here are two ideas:
    1. Driver level hook, in kernel mode, easy in pre-vista windows. In the past this has been used to make a shadow copy, re-cycle bin like if you will. Impossible in .net

    Major downside, this has intrinsicly no GUI support.

    2. Explorer reporting! Explorer.exe is the shell most people are using to choose too copy the files, so you hook it in here, as far as i'm aware there is no easy API for doing this, but then again i've never looked. However it wouldn't be too hard to find the API thats used internally, and hook it (so called 'EAT' Export Address Table hooking) this way your in a GUI application, and can easily make your own gui.

    .net isn't really suiteable enless there is some nice COM api. But the overheads of .net just dont make it seam right to me!
    throw new ArgumentException (String, String, Exception)

  3. #3
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    Thanks for your reply

    A KMD level hook was my original plan, and it might still be what I end up doing..and its still possible in vista from what I can tell after having a play with the new driver dev kit- but i'm trying to avoid it if i can.

    I'll look into hooking into explorer then Thanks for the idea - you're right that .NET is probably not the *best* way to go about it, especially as using COM means unmanaged code..which as you rightly say makes the overheads pointless, however the majority of the application will benefit hugely from being a .NET app so i'd like to try and keep using it for now. If I do things properly it wouldn't be too bad to have a small module of unmanaged code to deal with the explorer hooking and leave the rest of it as managed .NET.

    Thanks for the ideas though, i'll keep researching

  4. #4
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    COM interop is really easy in .net once you've got over some issues.

    Okay, what i'm saying is its easy to do it, to get all those niggling little bugs in that DCOM server that was written 2 years ago by someone who's left the company... Well thats harder!

    kernel hooking in vista is hard because of the kernel protection stuff. You might be able to get away with this file system, as rather than doing a int 2e hook, it would actually be a file system filter driver, or what-ever the MS name is, which are document. Either way its not the eayest option, as your taking a user mode action, crossing to kernel, back to user, to .net then window.... not going to be nice.

    Once you've loaded your .net code, created your window, its not *that* much slower at going hide/show than un-managed code. So that might be an option i supose.

    What is it ur trying to do exactly? Replace the copy dialoge?
    throw new ArgumentException (String, String, Exception)

  5. #5
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    Sort-of. What i'm really trying to do is to

    a) do some extra checks before letting the user copy over the file - basically checking that the file is one of a list of formats, and is named correctly.

    b) present the user with a window where they are required to enter some more information about the file before it is copied over to the server.

    Just to clarify the user would be copying from their windows machine (NTFS only) to their own 'virtual' network drive (which is actually just a folder on the server).

    It is possible for me to let the user fill in these details after the transfer has taken place, and to do the checks then too - and 'undo' what the user has done if there is a problem - but this is not ideal (prevention better than cure!) and could lead to some syncronisation issues.

    If I were to write my own full-blown application to deal with this, or if I used a different method of tranferring files between client and server I wouldnt have these issues..BUT that defeats the point of the exercise
    Last edited by Spud1; 06-02-2007 at 01:10 AM.

  6. #6
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    A quick update on this - i've been playing with hooking in .NET today (thanks to this article: http://msdn.microsoft.com/msdnmag/is...0/cuttingedge/)

    and its not *too* complex to implement it like this...

    the other idea I have now is to write an explorer namespace extension, which will give me enough control to be able to do what I want to do Thats tomorrows experiment though..

  7. #7
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    I was just about to say namespace extension after reading your first post!

    When i first had my psion, i thought WOW thats really narly!

    I tried to create a virtual "Music" device in C++ in explorer. It leaked buckets and had performance which can only be described as mac os x level. By the time it had searched my music database on my rediculously slow AMD k6 (1!) i had lost all intrest, and the project was junked.

    However, that is the best way to do it imo, its got a great user front end (easy to add the clsid too the desktop, network neighbourhood, my computer, the save file dialouge (on the left). Will also work smoothly with vista, and not impact the performance of the others.

    Not too mention this should be easy to do in .Net via COM interop!
    throw new ArgumentException (String, String, Exception)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help on my maxtor harddrives
    By arthurleung in forum PC Hardware and Components
    Replies: 10
    Last Post: 12-06-2007, 09:40 PM
  2. Multiple problems - help!
    By Ruggerbugger in forum Help! Quick Relief From Tech Headaches
    Replies: 7
    Last Post: 18-08-2006, 11:41 PM
  3. .NET Txt File Line counter
    By Shadow_101 in forum Software
    Replies: 5
    Last Post: 18-04-2006, 04:11 PM
  4. Nero vision express saying:'Burn process failed'
    By johnnr892 in forum Help! Quick Relief From Tech Headaches
    Replies: 15
    Last Post: 11-12-2005, 11:43 PM
  5. Dodgy DVD-r's ?
    By starside in forum Help! Quick Relief From Tech Headaches
    Replies: 12
    Last Post: 27-03-2005, 06:11 PM

Posting Permissions

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