Return to Technical Information Index

Sharing Violation Solutions  
[Updated December 26, 2003, the original posting is available here:  Cannot delete sharing violation source destination file  ]
There are many causes of a sharing violation as suggested by the following two articles - however, this posting is concerned with a sharing violation caused by an explorer.exe Open File Handle pointing to the folder - neither of the two articles mention this phenomena and information about it is not readily available -  
This Microsoft knowledge base article Q172710 discusses several possibilities;EN-US;172710 
  • The File Uses an ACL  
  • The File Is Being Used 
  • File System Corruption Is Preventing Access to the File 
  • Files Exist in Paths That Are Deeper Than MAX_PATH Characters 
  • The File Name Includes a Reserved Name in the Win32 Name Space  
  • The File Name Includes an Invalid Name in the Win32 Name Space 
  • Combinations of Causes 
  • __________________________________________________________ 
    A DevX article discusses these possibilites 
  • Insufficient rights 
  • Another program accessing that directory 
  • Program crash 
  • Remote access 
  • Application qurks 
  • ____________________________________________________________ 
    An Open (Orphaned) File Handle 
    Neither article mentions this cause - there is an old MSKB article Q165387 ( that described the same problem generated by the Windows NT 4.0 shell when an NTFS volume directory structure is uncompressed - allegedly, the Orphaned File Handle left by the uncompression utility was fixed in the Windows NT 4.0 Service Pack 4.0 -  
    Unfortunately, it appears the Orphaned File Handle is back to haunt us in Windows 2000 Professional - 
    The following steps should pretty reliably produce the problem 
  • Create a new folder [New Folder(3)] 
  • Create a sub-folder [New Folder] 
  • Copy some files into into the sub-folder 
  • Delete the files in sub-folder 
  • Trying to delete the now empty sub-folder [or it's parent, New Folder(3)] will generate a sharing violation 
    The sharing violation is caused by an 'orphaned File Handle' left by explorer.exe -  
    Since the user just created the folder, it wouldn't seem that there ought to be a 'rights issue' (and there isn't) - since it was created to 'temporarily' hold some files while the user was rearranging folder contents, it wouldn't seem that any application ought to have clamed ownership (and it hasn't) - furthermore, it can be especially aggravating because the user has deleted all the contents and the folder is empty -  
    There are four 'general' solutions, the first two are reccomended in the old MSKB article -  
  • Reboot the computer - time consuming, plus the results from any other open applications will have to be saved and those applications reopened after the boot -  
    [Some have suggested rebooting to safe mode or a command prompt - I haven't found that necessary - A normal reboot is usually all that's needed to clear the Orphaned File Handle - it is possible that there are other reasons the folder can't be deleted (as mentioned in the two articles above) and booting to safe mode or a command prompt may 'fix' those other problems] 
  • Log off the computer and log back on, which should clear the handle - same problems as rebooting, although perhaps a bit faster -  
  • Use the Task Manager (<Ctrl><Alt<Del>) to stop the explorer.exe process - Windows 2000 Professional will automatically restart the explorer.exe process to provide the WIndow's shell functions - the desktop will also be 'rebuilt', but most of the systray icons will be lost - 
  • If the 'Launch folder windows in a separate process' option is enabled, then do either one of the following: 
  • Close all open folder windows, which will stop the file manager explorer.exe process or  
  • Stop the file manager explorer.exe process from the Task Manager 
    And then 
  • Open a new explorer window and delete the folder. 
    This is probably the best solution - If there are open folder window(s), there should be two explorer.exe processes running in the Task Manager - normally the explorer.exe with the higher pid wil be the explorer.exe which is running the file manager (because the lower numbered pid explorer.exe started first and is running the Window's shell) -  
    And it does seem that if ignored for some period of time, maybe a few hours, the open file handle may clear itself - or you may end up rebooting for some other reason -  
    Running Handle.exe from displays the following open File Handles (Handle.exe is run from a Command prompt window): 
    F:\Current_Updates\Useful_Utilities_Free\SysInternals\Handle\handle>handle "C:\New Folder (3)\New Folder" 
    Handle v2.10 
    Copyright (C) 1997-2003 Mark Russinovich 
    Sysinternals - 
    explorer.exe       pid: 1840   C:\New Folder (3)\New Folder 
    explorer.exe       pid: 1840   C:\New Folder (3)\New Folder 
  • pid number's are dynamically and uniquely assigned by Windows, although they appear to be somewhat arbitrary - 
  • pid: 1840 is an explorer process for explorer windows - stopping it (in the Task Manager) will close all open explorer windows - restarting explorer.exe (by opening a new explorer window) should clear the open file handle and allow deletion of the empty folder -  
  • If pid: 1840 is the ONLY instance of explorer.exe running, then the Window's shell will also be stopped and automatically restarted and the Desktop will be rebuilt but unfortunately most of the systray icons will be lost - 
  • If option "Launch folder windows in a separate process" is enabled (see below) then the display folders explorer.exe process (PID: 1840 in this case) will likely be the process that has the 'orphaned File Handle' on the folder rather that than the window's shell explorer.exe process (PID: 912 in this case)  - stopping the display folder window explorer.exe process (PID: 1840) will close all open windows - the explorer process (PID: 912) supporting the window's shell will continue to run - opening a new Window's Explorer session should allow the empty folder to be deleted - 
    Process Explorer is another freeware at that has a GUI interface - because it displays a lot more information, it takes a little more 'getting used to', but it will show the same problem -  
  • PID number's are dynamically and uniquely assigned by Windows, although they appear to be somewhat arbitrary - 
  • Make sure that View Handles (<Ctrl>h) is enabled in the lower pane, as opposed to View DLLs (<Ctrl>d) -  
  • PID: 912 is the explorer.exe process which in this example is running the Windows shell  -  
  • PID: 1840 is the 'separate' explorer.exe process which is running the Folder windows - the higher PID number will normally be the separate explorer.exe process which is running folder windows because it will be started after the Windows shell explorer.exe process -  
  • Process Explorer has a nice feature that will allow you to 'force' a File Handle closed - right click the File Handle and select "Close Handle" 
  • If the 'orphaned file handle' is in the same explorer.exe process that is running the WIndows shell, that is the "Launch folder windows in a separate process" option is NOT enabled, the 'Close Handle' feature will probably still work and it will not stop and restart explorer.exe, which means the Destop  won't be rebuilt and the systray icons will not be lost -  
  • Microsoft suggests using Process Explorer in MSKB article Q242131 (;EN-US;242131) 
    Launch folder windows in a separate process 
  • The "Launch folder windows in a separate process" option is turned off by default - 
  • To enabled the  "Launch folder windows in a separate process" option, Click Start|Settings|Control Panel|Click Folder Options|Click View Tab - in the 'Advanced settings: [Window]', click the check box add a check mark - 
  • Enabling "Launch folder windows in a separate process" option will not prevent the 'orphaned File Handle' - the explorer.exe process has to be stopped (or all open folder windows closed) to release the Handle', but having the option enabled will avoid a reboot or a reload of the window's shell - 
  • The "Launch folder windows in a separate process" option has to be enabled and all open folder windows closed prior to the creation of the sub folder [otherwise, the 'orphaned File Handle' will be created in same explorer.exe process that is running the Windows shell  - 
  • From Microsoft's "Running Windows 2000 Professional" (ISBN 1-57231-838-4), Chapter 5, pp85 - Launch Folder Windows In A Separate Process. Even when you don't have any Windows Explorer windows open, an Explorer.exe process is running; it controls items such as the taskbar and the desktop. When you open Windows Explorer windows with this option turned off (the default), Windows uses the already-running process. By Turning on this option, you tell Windows to open a second process in a a separate part of memory for controlling Windows Explorer windows. (To monitor and veryify this effect, open Task Managed and click the Processes tab.)  
  • Tip [Also from the book]: If you have trouble with Windows Explorer crashing on your system, turn on the Launch Folder Windows In A Separate Process option. Although performance might suffer slightly, you system will be more stable.  
    [LLH: Not so sure that the tip from MS is accurate. Explorer.exe which supports the Windows shell process grabs a lot of memory if it 'thinks' it has to run both the shell and the file manager. With separate processes, the total memory usage may be less. And as the tip mentions, stability and speed is increased.] 
    Some additional comments from others that have experienced the exact same problem -  
    > This tidbit is from:>> < <>>>> I am forced to use a Windows NT machine at work. Every so often I have to> reboot it in order to delete a file. Yes, you read that correctly.>> Windows NT can prevent more than application from opening a given file at> the same time. While this sounds like a good idea in principle, it turns> out to be very annoying in practice. Sometimes I try to delete a folder> that happens to be the "current" folder in one of my shell windows, only> to be frustrated by the following alert box:>> "Cannot remove folder MyFolder: There has been a sharing violation. The> source of destination file may be in use.">> As if this weren't annoying enough, sometimes Windows NT doesn't clean up> after itself -- it "forgets" that a file or folder is no longer in use.> Even after closing all open applications, the "sharing violation" alert> box persists, and I am forced to reboot the machine in order to delete> something.>> This happened to me again just last week. As I was using a new account> which I had just created, the "Tip of the Day" welcome feature was still> enabled. After many unsuccessful attempts at dragging a folder to the> "recycling bin", I rebooted the machine, and logged in. The welcome> message which greeted me appears below. I just couldn't help but laugh.>> "Welcome to Windows NT 
    crampp (TechnicalUser) Dec 5, 2001  
    I have Files on my desktop that I use for documents to be stored before I transfer them to the computer that they are to be used on. Is there a way of deleting locked files once I have copied the data to another computer without logging off? 
    Tek-Tips Forums is Member Supported. Click Here to donate. 
    ISmonkey (MIS) Dec 14, 2001  
    In what way are they locked?  
    cramp (Visitor) Dec 17, 2001  
    I am able to delete the documents within a file but not the file folder itself. I get the error message: Cannot remove folder "folder name": There has been a sharing violation. The source or destination file may be in use. 
    The folder has only been accessed by me, dropping files into it, Checking the file then deleting it.  
    Hamish Ahern (Visitor) Mar 26, 2002  
    Yes I have the same problem with my windows 2000 machines at work. 
    if files are deleted within a folder, the deletion of folder itself then gives the sharing violation error. 
    I have traced the lock with ms tools to explorer.exe itself. 
    why would it be creating a sharing violation of itself? 
    I have found that if I end task explorer.exe and rerun explorer.exe I can then delete the folder... until I want to delete another folder that has had files removed from it by me. (deleting a whole folder on its own is fine)  
    Hi, I have a double-pronged problem. I have a file which I need to delete, but the file is locked. How do I boot a Win2k machine to a c: prompt for me to delete this culprit? Traditional win98 boot floppy will not work due to NTFS, so how does one do this?? Going nuts trying to figure this out, and secondly how do I find out which process has this file open?  
    Comment from bhoehne  Date: 09/20/2003 11:52PM PDT   
    You can boot to the so called "Recovery Console" by pressing F8 at bootup. Before doing that, try to delete the file in Safe Mode. 
    See for more details.   
    Comment from mutter223  Date: 09/21/2003 12:23AM PDT   
    Ok, no Recovery Console on the F8 menu, but the dilemna is that I cannot be logged into the machine in order for me to succesfully erase this file, as anytime W2k starts and I log into it it locks this file.  Same goes for safe mode, thus I need to come into the system at C:\ prompt.   
    Comment from bhoehne  Date: 09/21/2003 12:46AM PDT   
    OK - I wasn't really clear. 
    Boot to Safe mode can be done as mentioned. 
    If you want to boot to the "Recovery Console" you need your Windows-CD or Setup Disks. Start your computer with the Windows Setup floppy disks, or with the Windows CD-ROM. At the "Welcome to Setup" screen, press F10, or press R to repair, and then press C to start the Windows Recovery Console. Select the appropriate number for the Windows installation that you want to repair, and then type the administrator password. If the administrator password does not exist, just press ENTER.  
    Also see for available commands in the Console. 
    Comment from mutter223  Date: 09/21/2003 02:03AM PDT   
    OK, I followed this time, but I do not have the Admin password.  Didn't know it was going to be this complicated just to get to the C:\ prompt!   
    Comment from bhoehne  Date: 09/21/2003 02:26AM PDT   
    If you don't have the admin password - are you shure that the problem is, that the file is locked? Couldn't it be that you only don't have the permissions to delete the file?   
    Comment from mutter223  Date: 09/21/2003 02:56AM PDT   
    No, the file is in my personal folder and the exact message when I attempt to delete it is: 
    "Cannot delete FileName: There jas been a sharing violation.  The source or destination file may be in use." 
    So back to my original question...   
    Accepted Answer from bhoehne  Date: 09/21/2003 03:24AM PDT   
    The problem with this message is, that it has not really to be a sharing violation. So it can be a permission problem - so I recommend in doublecheking this. 
    Some other solutions about solving this message are provided by 
    Another possibility which could work: 
    1) Start the Task Manager and end the explorer.exe process. Then go into New Task (run) and start it again by running "explorer.exe" and try to delete the file then, or 
    2) Start the Task Manager and end the explorer.exe process. Then go into New Task (run) and run "cmd" and try to delete it. Run the explorer process again after finished.   
    Comment from Redwulf__53  Date: 09/21/2003 03:38AM PDT   
    Do delete a file from a command prompt in 2k: 
    -start->run->cmd [ok] 
    In the command prompt window that opens, type 
    followed by a space. 
    Now, drag the file you want to delete into the command prompt window. It will now read something a bit like: 
    C:\WINNT\>del "C:\Documents and settings\username\My Documents\Myfile.jpg" 
    Close Windows Explorer.` 
    Then go back to the command prompt window and press Enter. 
    Ususally Windows Explorer opens the file to create previews or provide extra file info to the user. This is what is blocking it from being deleted. 
    Comment from mutter223  Date: 09/21/2003 03:48AM PDT   
    That did it. Thanks you earned the points.  Just an afterthought so I do not have to open another thread, how would I find out what process had it open?  How would one find out all open files and the associate process?  Good'day and thanx.   
    Comment from bhoehne  Date: 09/21/2003 03:59AM PDT   
    No problem. Just to make the solution accessible to others in the future: Which solution worked for you? Restarting the explorer? 
    A nice command line tool to search for file handles is the Handle tool from Sysinternals which can be found at 
    Sysinternal also provides a GUI tool called Process Explorer which does the same thing ( 
    As Redwulf__53 mentioned, it could be that the Windows Explorer creates a preview of a file and locks it to do this. But this handle normally should be closed very fast so this shouldn't be a real problem.   
    Comment from mutter223  Date: 09/21/2003 05:02PM PDT   
    Bhoehne restarting the explorer did the trick, and thanx to Redwulf_53 as well for his comment.