如何检查当前计算机的域帐户的有效性 [英] How can I check the domain account validity of the current computer
本文介绍了如何检查当前计算机的域帐户的有效性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须承认的笔记本电脑,其域帐户
不再有效。
I must recognize notebooks whose domain accounts
are no longer valid.
该水煤浆是:
- 用户的登录工程通过缓存凭据
- 用户访问股份
和文件在服务器(NTLM)
- 通过 Kerberos访问不能正常工作
The behavour is:
- The user's logon works through cached credentials
- The user has access to shares
and files on the server (NTLM)
- Access via Kerberos does not work
即使域帐户不再有效域中,这code是工作在大多数情况下,
Even when the domain account is no longer valid in the domain, this code is working in most cases
// get the directory context to the domain the pc belogs to
DirectoryContext adsctx = new DirectoryContext(DirectoryContextType.Domain, "ourdomain.local");
// get the domain object
System.DirectoryServices.ActiveDirectory.Domain domain;
domain = System.DirectoryServices.ActiveDirectory.Domain.GetDomain(adsctx);
// get the domain controllers belonging to that domain
DomainControllerCollection dcc = domain.FindAllDiscoverableDomainControllers();
是否有可能以检查计算机帐户的有效性?
Is there any possibility to check the validity of the computer account?
推荐答案
通过这个code,我可以找到无效的计算机域帐户
:
With this code I can find invalid computer domain accounts
:
try
{
string sMyComputer = "MyComputer"
Domain computerDomain = Domain.GetComputerDomain(); // may! throw ActiveDirectoryObjectNotFoundException if computer account is invalid
string sComputerDomain = computerDomain.Name;
NTAccount acc_machine = new NTAccount(sComputerDomain, sMyComputer + "$");
SecurityIdentifier sid = (SecurityIdentifier)acc_machine.Translate(typeof(SecurityIdentifier)); // always throws an SystemException if computer account is invalid
}
catch
{
// something is wrong with the account
}
- sMyComputer +$是怎样的帐户名是存储在Active Directory
- 在我的经验是,一个异常大多没有抛出,返回值是电脑曾经域的正确名称的工作计算机帐户
- 第二异常(SystemException的)总是被抛出,如果computeraccount现在是无效的。在埃罗code是80004005(我预想的IdentityNotMappedException)
编辑:
在code纠正错误
corrected error in code
这篇关于如何检查当前计算机的域帐户的有效性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文