Delete files/directories through VB Net

G

Guest

I am writing this app in .net 2003 since all machines don't have 2.0
framework. I am trying to delete old profiles, but I am getting access
denied or file in use errors. A lot of these files I am able to delete
in Windows Explorer.
The app is getting launched using the System account, so there is
plenty of rights to delete the files.

I have tried the following:

Recursive delete of every file using Kill()
fso.DeleteFolder(path,True)
Directory.Delete(path)

Set Owner on directories to System and still can't delete. Can't
delete after reboot, even though the user has not logged back in. Most
of the files are index.dat from Cookies or Temp internet folders.

Is there any way to brute force delete these files and folders? I want
them deleted, and don't want to have to shell out to a third party app.
Thanks for any help
 
G

Guest

Cor,
Thanks for the reply. I ended up writing a service, starting as Local
System since that always has full rights to the file system. I then
dropped down to Kernel32:

Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA"
(ByVal lpFileName As String) As Long

Private Sub DeleteProfileFolder(ByVal UserHomeDir As String)
Try
Dim Folder As String
Dim File As String

For Each Folder In Directory.GetDirectories(UserHomeDir)
For Each File In Directory.GetFiles(Folder)
DeleteFile(File)
Next
DeleteProfileFolder(Folder)
Next
Catch Ex As Exception
WriteLog(Ex.ToString, 2)
End Try
End Sub

Unfortunately I had to use FSO.DeleteFolder to delete the main
directory since it has the force option, but all is working well now.
Hopefulle this can help out someone in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top