Solved

How to delete a "sharing violation" file?

Posted on 2000-03-09
7
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Expert Comment

by:PetriWork
Comment Utility
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
Comment Utility
Can I use this in Win98?
0
 

Accepted Solution

by:
PetriWork earned 100 total points
Comment Utility
Yes
0
 

Author Comment

by:jlislo
Comment Utility
Thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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