1

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.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Lima
  • 1,203
  • 3
  • 22
  • 51

1 Answers1

1

This folders can be removed only if your application is run in administrator mode, because this is important part of the user data.

So the only way your application can do is request run in administrator mode:

How do I force my .NET application to run as administrator?

Check the folder on which exception is raised, and check the rights on it.

Community
  • 1
  • 1
VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • I already had my application running in requireAdmin in the app.manifest file, we have UAC disabled as we are in a corporate network and don't wish to annoy our users any more then we have to. Is there any way of hiding the All Users shortcuts? – Lima Sep 09 '11 at 12:03
  • @Lima Check the folder on which exception is raised, and check the rights on it. – VMAtm Sep 09 '11 at 12:08