我编写了一些代码来检查iis元数据库,以查看安装了哪些站点以及保存虚拟目录的位置。在服务器上本地运行时,这些代码运行正常。
我正在尝试扩展它以便远程工作。我正在努力让它进行身份验证。我目前正在使用LogonUser
api,但这在登录时始终返回false
LogonUser
API调用和命令行用户runas的情况下运行应用程序,我会收到错误消息:COMException (0x80005000)
任何想法都会受到赞赏。
答案 0 :(得分:0)
通常,如果您在远程服务器上执行程序化管理,则需要将凭据传递给API。例如,如果您使用的是System.DirectoryServices
,那么您可以执行以下操作:
string server = "MyHost";
string username = "bob";
string password = "bob123$";
string path = "IIS://" + server + "/W3SVC/1";
DirectoryEntry de = new DirectoryEntry(path, username, password);