Getting Domain name of current computer

Getting Domain name of current computer

Post by Mark Lauritse » Wed, 27 May 1998 04:00:00



In C++, how can I determine the name of the domain to which the current
computer belongs?

--
MARKALAUR

 
 
 

Getting Domain name of current computer

Post by Felix Kasza [MV » Wed, 27 May 1998 04:00:00


Mark,

 > In C++, how can I determine the name of the domain to which the current
 > computer belongs?

By calling NetWkstaGetInfo( NULL, 100, &buf ).

Cheers,
Felix.

--
If you post a reply, kindly refrain from emailing it, too.
I have killfiled hotmail.com and yahoo.com. If you are legit,
come forth and be recognized -- with a *real* email address.

 
 
 

Getting Domain name of current computer

Post by Dave Navar » Mon, 01 Jun 1998 04:00:00



Quote:> Mark,

>  > In C++, how can I determine the name of the domain to which the current
>  > computer belongs?

> By calling NetWkstaGetInfo( NULL, 100, &buf ).

Doesn't 100 return the workstation name?

--Dave

 
 
 

Getting Domain name of current computer

Post by Dave Navar » Mon, 01 Jun 1998 04:00:00



Quote:> Mark,

>  > In C++, how can I determine the name of the domain to which the current
>  > computer belongs?

> By calling NetWkstaGetInfo( NULL, 100, &buf ).

Felix,

I tried this and I got back my workstation name.  

How can I get the names of the domains to which my workstation belongs
(especially the PDC)?

Thanks!

--Dave

 
 
 

Getting Domain name of current computer

Post by Felix Kasza [MV » Tue, 02 Jun 1998 04:00:00


Dave,

The code below works fine here:

        E:\samples> nwgi
        Computer name: "BAR"
        LAN group:     "FOO"

        E:\samples> nwgi \\bar
        Computer name: "BAR"
        LAN group:     "FOO"

Are you sure you were checking the proper field in the structure --
wki100_langroup? Are you sure you are in a domain?

If you have plenty of privileges, you can also try asking the LSA for
the domains which are trusted by your computer --
http://www.mvps.org/win32/lsa/, look for the link to the
LsaEnumerateTrustedDomains() sample.

-----[snip]-----
#include <windows.h>
#include <lm.h>
#include <stdio.h>
#include <stdlib.h>
#pragma hdrstop

#define MAXLEN 256

int main( int argc, char *argv[] )
{

        DWORD rc;
        WKSTA_INFO_100 *buf;
        wchar_t server[MAXLEN];

        if ( argc > 2 )
        {
                puts( "usage: nwgi [\\\\server]" );
                return 1;
        }

        if ( argc >= 2 )
                mbstowcs( server, argv[1], MAXLEN );
        else
                server[0] = L'\0';

        buf = NULL;
        rc = NetWkstaGetInfo( (char *) server, 100, (BYTE **) &buf );

        if ( rc != ERROR_SUCCESS )
                printf( "NWGI() returned %lu\n", rc );
        else
        {
                printf( "Computer name: \"%S\"\n", buf->wki100_computername );
                printf( "LAN group:     \"%S\"\n", buf->wki100_langroup );

                if ( buf != NULL )
                        NetApiBufferFree( buf );
        }

        return 0;

Quote:}

-----[snip]-----

Cheers,
Felix.

--
If you post a reply, kindly refrain from emailing it, too.
I have killfiled hotmail.com and yahoo.com. If you are legit,
come forth and be recognized -- with a *real* email address.

 
 
 

Getting Domain name of current computer

Post by Dave Navar » Thu, 04 Jun 1998 04:00:00



Quote:> Dave,

> The code below works fine here:

>    E:\samples> nwgi
>    Computer name: "BAR"
>    LAN group:     "FOO"

>    E:\samples> nwgi \\bar
>    Computer name: "BAR"
>    LAN group:     "FOO"

> Are you sure you were checking the proper field in the structure --
> wki100_langroup? Are you sure you are in a domain?

Thanks. I misunderstood what "langroup" was and wasn't checking it.  

But I did find the undocumented WKSTA_USER_INFO_1 with the wkui_logon_domain
member in the meantime.

Quote:> If you have plenty of privileges, you can also try asking the LSA for
> the domains which are trusted by your computer --
> http://www.mvps.org/win32/lsa/, look for the link to the
> LsaEnumerateTrustedDomains() sample.

Many Thanks!

--Dave

 
 
 

Getting Domain name of current computer

Post by Bob Sterlin » Fri, 12 Jun 1998 04:00:00


Now, how do you do this on 95 where you can't use the netGetWkInfo.



>> Dave,

>> The code below works fine here:

>> E:\samples> nwgi
>> Computer name: "BAR"
>> LAN group:     "FOO"

>> E:\samples> nwgi \\bar
>> Computer name: "BAR"
>> LAN group:     "FOO"

>> Are you sure you were checking the proper field in the structure --
>> wki100_langroup? Are you sure you are in a domain?

>Thanks. I misunderstood what "langroup" was and wasn't checking it.

>But I did find the undocumented WKSTA_USER_INFO_1 with the
wkui_logon_domain
>member in the meantime.

>> If you have plenty of privileges, you can also try asking the LSA for
>> the domains which are trusted by your computer --
>> http://www.mvps.org/win32/lsa/, look for the link to the
>> LsaEnumerateTrustedDomains() sample.

>Many Thanks!

>--Dave

 
 
 

Getting Domain name of current computer

Post by Felix Kasza [MV » Fri, 12 Jun 1998 04:00:00


Bob,

 > Now, how do you do this on 95 where you can't use the netGetWkInfo.

Fix 1: Upgrade to NT (my preferred solution)

Fix 2: thunk down to the 16bit netapi.dll

Cheers,
Felix.

--
If you post a reply, kindly refrain from emailing it, too.
I have killfiled hotmail.com and yahoo.com. If you are legit,
come forth and be recognized -- with a *real* email address.

 
 
 

Getting Domain name of current computer

Post by Dave Navar » Fri, 26 Jun 1998 04:00:00



says...

Quote:> Now, how do you do this on 95 where you can't use the netGetWkInfo.

Sorry, but I don't do any programming in or for Win95 any more.  We're
strictly an NT shop here now.

--Dave