Solved

How to delete a "sharing violation" file?

Posted on 2000-03-09
7
184 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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