首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >[ADSI]::Exists引发异常而不是返回False

[ADSI]::Exists引发异常而不是返回False
EN

Stack Overflow用户
提问于 2012-05-25 23:35:54
回答 1查看 4.6K关注 0票数 5

如果ADSI对象不存在,我正尝试使用它创建一个用户。下面是我得到的奇怪的结果

代码语言:javascript
复制
#Check a user that I know exists
[ADSI]::Exists("WinNT://localhost/micah,user") #True

#Check a group that I know exists
[ADSI]::Exists("WinNT://localhost/administrators,group") #True

#Check a group that DOESN'T exist
[ADSI]::Exists("WinNT://localhost/whoops,group") #False

#Check a user that DOESN'T exist (NOT specifying that the obect is a user)
[ADSI]::Exists("WinNT://localhost/test") #False (This works fine)

#Check a user that DOESN'T exist (specifying that the obect IS a user)
[ADSI]::Exists("WinNT://localhost/test,user") 
#Throws exception "The user name could not be found"

最后一行对我来说毫无意义。为什么当我指定特定的用户时,它会抛出异常,但当我没有指定需要的用户时,它就会正常工作?对我来说,这似乎完全不符合直觉。我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-26 01:31:45

这是一个错误,微软不会修复它--

http://connect.microsoft.com/VisualStudio/feedback/details/337682/directoryentry-exists-throws-exception-for-non-existent-winnt-object

我们正在解决这个错误,但不会修复。尽管设计不正确...应用程序可能早就预料到了这一点--而这一变化可能会破坏这些应用程序。解决办法是捕捉异常-不是很漂亮,同意,但没有足够的理由进行修复。文档需要修复,我将为此打开一个文档工作项。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10757316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档