Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

How to delete a "sharing violation" file?

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
jlislo
Asked:
jlislo
  • 3
  • 3
1 Solution
 
EpsylonCommented:
No, as long as files are in use you can not delete these files and the directory where the file resides.
0
 
PetriWorkCommented:
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
 
jlisloAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
PetriWorkCommented:
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
 
jlisloAuthor Commented:
Can I use this in Win98?
0
 
PetriWorkCommented:
Yes
0
 
jlisloAuthor Commented:
Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now