I am developing a VB.NET application which we will be running at user login on our corporate network which will be setting up the user's environment, this will include the start menu.
I have a method which is attempting to delete all files and folders located in the user's Start Menu\Programs folder (C:\Users{user}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs), our environment is Windows 7.
Private Function deleteFolderFilesAndSubFolders(ByVal location As DirectoryInfo, Optional ByVal exclude As String = "") As Boolean
For Each f As DirectoryInfo In location.GetDirectories
For Each i As FileInfo In f.GetFiles
i.Delete()
Next
f.Delete()
Next
End Function
When this method is being executed, I am receiving an exception:
Access to the path 'Maintenance' is denied.
Located in the users Programs folder are 3 standard applications, Administrative Tools, Maintenance, and Startup. I am excluding the startup directory, but would like these other two to be removed.
Can anyone point me in the right direction to be able to remove these folders, I do not mind if they are re-created on each login, my script will run on each login and will re-create the start menu each time.