I'm having kind of an odd problem.
I'm using VB.NET (in VS2005, with .NET 2.0) to write a service (controlled by Group Policy) that allows me to delete user profiles regularly to save disk space on school lab computers (and keep their Documents and Settings directory nice and neat, not to mention continually "resetting" our generic student accounts) and in my test environment the program keeps continually throwing up IOExceptions. Here's an excerpt from the log file:
The really odd part about this is that if I go in through Explorer/cmd.exe I can delete the said directories with no problem. The permissions are set up as they should be (Admininstrators, SYSTEM, and user having full control) and the files aren't being used (the ntuser.dat isn't being locked by Windows at this time) so there's no good reason that it shouldn't be working. Furthermore, it deletes about half of the contents before dying -- including the aforementioned registry file -- and the files that were actually deleted were the same between all of the test profiles.
The following code handles the deletion:
As you can see, it's pretty simple and straight-forward.
Any ideas as to what the problem could be? I'm completely stumped.
Thanks!
I'm using VB.NET (in VS2005, with .NET 2.0) to write a service (controlled by Group Policy) that allows me to delete user profiles regularly to save disk space on school lab computers (and keep their Documents and Settings directory nice and neat, not to mention continually "resetting" our generic student accounts) and in my test environment the program keeps continually throwing up IOExceptions. Here's an excerpt from the log file:
This happens both with LOCAL SERVICE (when run as a service) and under a domain administrator account (when running the CLI version of this app).Deleting C:\Documents and Settings\student
Could not delete directory: C:\Documents and Settings\student
{exception: System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings\student\ntuser.pol' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at Microsoft.VisualBasic.FileIO.FileSystem.DeleteFileInternal(String file, UIOptionInternal showUI, RecycleOption recycle, UICancelOption onUserCancel)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.DeleteFile(String file)
at ProfilePurgeEngine.ProfilePurgeEngine.DeleteProfile(String path)}
Deleting C:\Documents and Settings\uteacher
Could not delete directory: C:\Documents and Settings\uteacher
{exception: System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings\uteacher\ntuser.pol' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at Microsoft.VisualBasic.FileIO.FileSystem.DeleteFileInternal(String file, UIOptionInternal showUI, RecycleOption recycle, UICancelOption onUserCancel)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.DeleteFile(String file)
at ProfilePurgeEngine.ProfilePurgeEngine.DeleteProfile(String path)}
Deleting C:\Documents and Settings\User
Could not delete directory: C:\Documents and Settings\User
{exception: System.IO.IOException: Access to the path 'C:\Documents and Settings\User\Application Data\Microsoft\Internet Explorer\Quick Launch' is denied.
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
at Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectoryInternal(String directory, DeleteDirectoryOption onDirectoryNotEmpty, UIOptionInternal showUI, RecycleOption recycle, UICancelOption onUserCancel)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.DeleteDirectory(String directory, DeleteDirectoryOption onDirectoryNotEmpty)
at ProfilePurgeEngine.ProfilePurgeEngine.DeleteProfile(String path)}
The really odd part about this is that if I go in through Explorer/cmd.exe I can delete the said directories with no problem. The permissions are set up as they should be (Admininstrators, SYSTEM, and user having full control) and the files aren't being used (the ntuser.dat isn't being locked by Windows at this time) so there's no good reason that it shouldn't be working. Furthermore, it deletes about half of the contents before dying -- including the aforementioned registry file -- and the files that were actually deleted were the same between all of the test profiles.
The following code handles the deletion:
VB.NET:
Try
If Not pretend Then
DebugOut("Deleting " + path)
For Each file As String In Directory.GetFiles(path)
My.Computer.FileSystem.DeleteFile(file)
Next
My.Computer.FileSystem.DeleteDirectory(path, FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
DebugOut("Not really deleting " + path)
End If
Catch ex As Exception
DebugOut("Could not delete directory: " + path + vbNewLine + "{exception: " + ex.ToString + "}")
End Try
Any ideas as to what the problem could be? I'm completely stumped.
Thanks!
Last edited by a moderator: