Thread: C Code to close and reopen explorer

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    1

    C Code to close and reopen explorer

    Hi,
    I wanted to stop the user from having access to USB flash drive while my program is reading data from it.
    I thought i could do so by closing the explorer at the start of my program and reopening it at the end of it.
    Could you please help me with the C Code to close and reopen the explorer?
    Or any other ideas on have to ban access to the USB flash drive?
    A simple access ban would be enough.
    Thanks for your time.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Devoted my life to programming...

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Honestly? Try sticking with existing semantics and not try to be clever (quite what do you think closing and opening explorer (which controls the start menu and taskbar too) will do when there might be a thousand programs opening things from the USB stick - everything from Windows search indexing to antivirus?). Playing with people's computers like that will NOT be appreciated.

    Locking the USB device? Unless you are able to target EXACTLY and ONLY your USB device (which you can use libusb or device drivers to do), you're going to break people's computers.

    How about you just lock the damn file you're interested in:

    LockFileEx function (Windows)

    And then handle any file errors by terminating your program? Like EVERY OTHER PROGRAM on the planet does, from Excel to notepad-equivalents? Quite what makes your program so special you think you can just kill explorer processes or block USB devices because you can't program it to account for people accessing the file you're reading?

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to reopen stdout?
    By leetow2003 in forum Linux Programming
    Replies: 4
    Last Post: 07-27-2011, 12:15 PM
  2. Replies: 11
    Last Post: 07-14-2011, 10:08 AM
  3. Replies: 10
    Last Post: 07-20-2007, 01:07 PM
  4. This code locks up explorer. Help?
    By Geolingo in forum Windows Programming
    Replies: 11
    Last Post: 08-30-2003, 03:03 PM
  5. HACKING! (reopen)
    By dayknight in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 05-08-2002, 05:53 PM

Tags for this Thread