Solved

How to delete a "sharing violation" file?

Posted on 2000-03-09
7
188 Views
Last Modified: 2010-04-04
I try to delete a directory using the following procedure created by rwilson
----------------------------------
Uses shellapi ;

function DelDir(path:string):boolean;
var
   SHFileOpStruct: TSHFileOpStruct;
begin
  fillchar(SHFileOpStruct,sizeof(TSHFileOpStruct),0);
  with SHFileOpStruct do
  begin
    Wnd:=0; {form1.handle}
    wFunc:=FO_DELETE;
    pFrom:=pchar(path+#0+#0);
    pTo:=nil;
    fFlags:=FOF_NOCONFIRMATION or FOF_SILENT;
    lpszProgressTitle:=nil; {'Deleting '+path;}
  end;
  result:=SHFileOperation(SHFileOpStruct)=0;
end;
-----------------------------------
But some files is in use "sharing violation". Is their anyway I can delete those files?
0
Comment
Question by:jlislo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2602325
No, as long as files are in use you can not delete these files and the directory where the file resides.
0
 

Expert Comment

by:PetriWork
ID: 2602331
Windows NT prevents you from doing this but Win9x is more forgiving (no good to do it anyway).
What you can do is to delete the files during a reboot, I can give you a sample that does this if that's an interesting solution.

Peter
0
 

Author Comment

by:jlislo
ID: 2602374
PetriWork,

I use
                               ExitWindows(EW_RebootSystem, 0) ;

but it doesn't doing the same as you click Start/Shut Down/Restart.

Is their a better way to restart the system?

Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:PetriWork
ID: 2602656
I've not restarted Windows NT so many times from a program, I know however that you need to call:

ExitWindowsEx(EWX_REBOOT, 0);
but before this you need to adjust your process token privileges with AdjustTokenPrivileges.

There a good example at http://borrisholt.com/ for doing this, check in the WinNT section.
0
 

Author Comment

by:jlislo
ID: 2604638
Can I use this in Win98?
0
 

Accepted Solution

by:
PetriWork earned 100 total points
ID: 2604811
Yes
0
 

Author Comment

by:jlislo
ID: 2604980
Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question