I am trying to get the Application pools on a local system which I am the administrator using this code
Dim ServerManager As New Microsoft.Web.Administration.ServerManager
colAppPools = ServerManager.ApplicationPools
or
ServerManager.WorkerProcesses()
And the second line results in a FileNotFoundException on redirection.config I checked and there is a file with that name in the %systemroot%\system32\inetsrv\config directory, the file exists and I gave it and the folder permissions for the user, but still I get the same FileNotFound exception.
My guess is that this could happen for one of two reasons:
You are referencing the wrong version of Microsoft.Web.Administration.dll, make sure that you add the reference from c:\Windows\System32\Inetsrv\Microsoft.Web.Administration.dll. For example a common issue is when developers reference the IIS Express version in the "program files" directory.
Because you are running your process as a non-administrator. ServerManager requires administrative permissions to read the files in windows\system32\inetsrv\config (and schema), as well as access the runtime APIs that list worker processes and state, so make sure that you are running your app elevated (or if debugging, then launch Visual Studio elevated).