简体   繁体   中英

How to determine if my program is 'on the company domain'

I'm trying to determine if my service is currently connected to the company domain or not.

I tried

BOOL bResult = LogonUser(m_userName, m_domainStr, m_password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &userHandle);

but it returns true if the credentials are good.

I'm guessing that Windows is checking the cached credentials and determining that they are good.

I suppose I could use a Ping, but a Firewall would stop that too.

Is there a nice, clean way to determine if a computer is on the 'corporate network' (eg can connect to the AD).

Check for the availability of the DCs SYSVOL share.

I would query DNS for a list of DCs, then Loop through the DCs until I can Access the share. If I can, I'm online. If I can't, I'm offline.

If on the Company Lan, but the DCs are unavailable, you might just as well be offline...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM