Solved

How to delete a "sharing violation" file?

Posted on 2000-03-09
7
181 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now