Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

Delete files/directories through VB Net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nospam@meatonconsulting.com - 01 Nov 2006 21:28 GMT
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
Cor Ligthert [MVP] - 02 Nov 2006 05:40 GMT
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/default.asp?url=/library/en-us/cpref/html/frlr
fSystemDiagnosticsProcessClassTopic.asp


I hope this helps,

Cor

>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
[quoted text clipped - 16 lines]
> them deleted, and don't want to have to shell out to a third party app.
> Thanks for any help
nospam@meatonconsulting.com - 03 Nov 2006 16:03 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.