IIS 7 ADSI Error: System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
The following code worked fine on IIS 6 but when used on IIS it failed:
System.DirectoryServices.
DirectoryEntry iisServer;
iisServer = new System.DirectoryServices.DirectoryEntry("IIS://jsanders4/W3SVC/1");
System.DirectoryServices.DirectoryEntry rootFolder = iisServer.Children.Find("Root", "IIsWebVirtualDir"); //exception here
The exception was as follows:
[System.Runtime.InteropServices.COMException] {"Unknown error (0x80005000)"}
System.Runtime.InteropServices.COMException
Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
at System.DirectoryServices.DirectoryEntries.Find(String name, String schemaC
lassName)
The error code is not translated to anything. This indicates that the ADSI provider for IIS://jsanders4/W3SVC/1 does not exist or it is inaccessible.
Opening up IIS manager you can see that the webserver 'jsanders4' is up and running and the primary website ID is indeed 1. The logical conclusion then is that the ADSI provider for IIS://jsanders4 must be the problem.
IIS 7 does not install an ADSI provider by default. You can enable it however as a Role Service for the IIS Web Server. You need to enable the IIS 6 Metabase Compatiblity role service. Probably a better way to proceed is to change your code to use the WMI provider for IIS 7 https://msdn.microsoft.com/en-us/library/aa347459.aspx
After installing the IIS 6 Metabase Compatiblity role service the error changed:
[System.Runtime.InteropServices.COMException] {"Access is denied.\r\n"} System.Runtime.InteropServices.COMException
ErrorCode 0x80070005
Access is denied.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
at System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName)
This is because Windows Server 2008 is locked down with UAC. You need to run the program as Administrator to execute this program. Another alternative is to set the account that is running this program with the rights: Logon as a Service"/ "Logon as a Batch Job"
I hope this helps you! Let me know if you used it to solve an issue.
Comments
Anonymous
September 10, 2009
Thanks, this helped me to install Embarcadero "Performance center" on Windows 7 RCAnonymous
November 02, 2009
Thanks, this helped. This seems like a good excuse to learn WMI, since we don't want to turn compatability on unless we have to. I do wish the code would throw something more descriptive than "Unknown error", though.Anonymous
April 20, 2010
Thanks a lot for this article. Had an issue with an automated build that uses Microsoft.SDC.Tasks and it uses ADSI to do IIS related tasks. We had a server setup that didn't have the IIS 6 metabase compatibility role service installed and we had a devil of a time figuring out why the website deployment was breaking.Anonymous
April 20, 2010
Glad I could help!Anonymous
August 25, 2010
had the some issue but I got this fixed by just turning off the UAC to an internal server. Tired of having problems with UAC settings.Anonymous
August 25, 2010
Javier, Thanks for the comment. I am glad the article helped! I would not disable UAC on the server. The article descrbes how you can run as administrator to solve the UAC portion of this problem. I know security is a pain, but it is there to protect your machine from attack. You and I run as admins because we want the freedom to make changes easily. Unfortunately we do not want to give rouge processes the same amount of lattitude. You will LOVE UAC if only once it keeps your server from being compromised. It IS your server so you have the option of turning it off if you HATE it :-). Thank goodness we are flexible that way.Anonymous
June 22, 2011
I'm getting the same error running on the Cassini Web server in Visual Studio on Win 7 x64. Any ideas on how to resolve this?Anonymous
June 22, 2011
Cassini does not have an Admin object associated with it and you can't install IIS 6 tools for it right? You can't install IIS 6 tools for Cassini, only IIS.Anonymous
May 01, 2013
Thank you very much for explaining the issue! I spent a day of google-ing and tone of coffee before running across your post. Very helpful!Anonymous
February 19, 2014
Very useful post, made it clear exactly what the problem was with this error trace and gave direct advice on how to fix it. Thanks!Anonymous
February 19, 2014
tanxAnonymous
May 22, 2015
Great article :: Issue i was getting ==> [System.Runtime.InteropServices.COMException] {"Access is denied.rn"} System.Runtime.InteropServices.COMException ErrorCode 0x80070005 Solution which get my issue resolved :: After doing all above stated things. I have to do this also to resolve Access denied error ==> Run all Administrator in admin approval mode ==> Disabled ..Anonymous
May 17, 2017
IIS6 Metabase Compatibility is no need.Full solution: 1. "LDAP://…" must be uppercase; 2. Account needs "Log on as a service" right; 3. Application Pool need to load user profile.