Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Host Name (Win32)?

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
Hello!

I'm trying to find a way to get the complete host domain information that a win32 client workstation is logging in to.

For example:
I'm on a windows NT desktop and logging into a Windows2000 domain. I'd like a way to get the full domain name. The environment variable userdomain gives me part, but not all. If I'm logging into "ABC.MyDomain.com" then userdomain just returns "ABC". I need the fully qualified domain name.

I could use ipconfig /all and get it from "Primary DNS suffix" which doesnt seem to always be present? Or from the Host Name "mycomputer.MyDomain.com" and parse out the .myDomain.com...

I was also thinking it might be in the registry somewhere, I'm going to see if I can find that location documented anywhere and try my first Perl registry lookup! =)

Thanks in advance for any help!
 
Have you tried the environment variables?
like $ENV{HTTP_HOST} or if there is an extra step:
$ENV{HTTP_REFERER}
You can use regexes(regular expressions) if you want cut the userdomain out of it.
 
You might look at the Win32::NetAdmin module.

see c:\perldoc Win32::NetAdmin -enter-

I don't have time to do the digging but that module looks like in is the right general area.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I'm still working on this one...

I can't add any modules to my script for size reasons as this is being compiled via perlapp and must remain as small as possible...

I've found this, but it only gives part of the domain, not the FQDN...

unless ($domain = Win32::DomainName) {die "Unable to obtain the domain name!/n";}
print "Domain: $domain \n";

I am using the Win32:API in the script already - I'm going to see if I can find a way to use that or find some other work-around.

Thanks again, still lookin...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top