By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

Delete files/directories through VB Net

P: n/a
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

Nov 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
nobody,

I am not sure how you do it on those clients, but you can always try to do
it with the diagonsic process

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope this helps,

Cor

<no****@meatonconsulting.comschreef in bericht
news:11**********************@h48g2000cwc.googlegr oups.com...
>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

Nov 2 '06 #2

P: n/a

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.

Nov 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.