List Info

Thread: RE: Not every PC is in a named domain




RE: Not every PC is in a named domain
user name
2007-09-18 01:41:02
On Mon, 17 Sep 2007, Jerry D. Hedden wrote:
> Jan Dubois wrote:
> > That is weird, why does the test fail then. 
Doesn't Win32:omainNam
e()
> > on that machine return "MSHOME"?  When I
run it on an XP (SP2) machine
> > that is not part of the domain, I get the
workgroup name:
> >
> >     C:>perl -MWin32 -e "print Win32:omainNam
e"
> >     WORKGROUP
> 
> It prints out nothing on my PC.  So it appears to be
returning an empty
> string.

I've attached a small C program that executes the same code
as
Win32:omainNam
e(), but adds some debugging output.  Could you
please compile and run the program:


    d:tmp>cl -nologo domainname.c 
    domainname.c

    d:tmp>domainname
    module=5B860000
    NetApiBufferFree=5B867750 NetWkstaGetInfo=5B869A3A
    NetWkstaGetInfo returned 0
    domain is 'WORKGROUP'

Cheers,
-Jan

/* domainname.c */

#include <windows.h>

#define GETPROC(fn) pfn##fn =
(PFN##fn)GetProcAddress(module, #fn)

typedef DWORD (__stdcall *PFNNetApiBufferFree)(void*);
typedef DWORD (__stdcall *PFNNetWkstaGetInfo)(LPWSTR, DWORD,
void*);

int main(void)
{
    DWORD retval;
    char dname[256];
    DWORD dnamelen = sizeof(dname);
    struct {
        DWORD   wki100_platform_id;
        LPWSTR  wki100_computername;
        LPWSTR  wki100_langroup;
        DWORD   wki100_ver_major;
        DWORD   wki100_ver_minor;
    } *pwi;

    PFNNetApiBufferFree pfnNetApiBufferFree;
    PFNNetWkstaGetInfo pfnNetWkstaGetInfo;

    HMODULE module = LoadLibrary("netapi32.dll");
    printf("module=%pn", module);
    if (!module)
        return 1;

    GETPROC(NetApiBufferFree);
    GETPROC(NetWkstaGetInfo);
    printf("NetApiBufferFree=%p
NetWkstaGetInfo=%pn",
           pfnNetApiBufferFree, pfnNetWkstaGetInfo);

    if (!pfnNetApiBufferFree || !pfnNetWkstaGetInfo)
        return 1;

    retval = pfnNetWkstaGetInfo(NULL, 100, &pwi);
    printf("NetWkstaGetInfo returned %ldn",
retval);
    if (retval)
        return 1;

    if (pwi->wki100_langroup &&
*(pwi->wki100_langroup)) {
        WideCharToMultiByte(CP_ACP, 0,
pwi->wki100_langroup,
                            -1, (LPSTR)dname, dnamelen,
NULL, NULL);
        printf("domain is '%s'n", dname);
    }
    else {
        WideCharToMultiByte(CP_ACP, 0,
pwi->wki100_computername,
                            -1, (LPSTR)dname, dnamelen,
NULL, NULL);
        printf("computer is '%s'n", dname);
    }
    return 0;
}
/* the end */



[1]

about | contact  Other archives ( Real Estate discussion Medical topics )