How do I detect if my program runs in an Active Directory environment?

前端 未结 5 481
陌清茗
陌清茗 2020-12-31 16:51

How do I detect if my program runs in an Active Directory environment?

I\'m using C# and .Net 2.0

5条回答
  •  梦毁少年i
    2020-12-31 17:03

    This code will check if the Computer itself is a member of a domain

    using System.DirectoryServices.ActiveDirectory;
    
    
    bool isDomain = false;
    
    try
    {
        Domain.GetComputerDomain();
        isDomain = true;
    }
    catch (ActiveDirectoryObjectNotFoundException)
    {
    }
    

    However the computer can be in a domain, but the currently logged in user may be a local user account. If you want to check for this use the Domain.GetCurrentDomain() function

提交回复
热议问题