Windows API - Getting the NT domain

NickA

Member
Anyone know how to get the current NT domain in ProgressV8/V9 GUI? (Need something to cover Win95/98/NT/2000).

Presumably a particular API call?
 

jamesmc

Member
I found it in HKLM\System\CurrentControlSet\Services\MSNP32\NetworkProvider\AuthenticatingAgent.

This was on a Win95 box.

HTH,

James.
 

NickA

Member
There's no simple API call for this?

Thanks for the info guys.

There's no simple API call I can make for this?

I checked a few computers running different flavours of Windows. Our domain name can be found in more than on place in the registry, and never seems to be in the same place between Win95/98 and NT/2000... so I'm a bit worried that if I start messing around in the registry that I might be getting the domain from the wrong place.
 

muthu

New Member
How to find NT domain thru progress

define var outval as char format "x(50)".
define var inifile as char init "c:\winnt\win.ini".
load inifile.
use inifile.
get-key-value section "winlogon" key "cacheprimarydomain" value outval.
unload inifile.

if outval = ?
then message "Error" outval view-as alert-box error buttons ok.
else message outval view-as alert-box info buttons ok.
 
U

Unregistered

Guest
But I haven't got a 'winlogon' section?!

Neither my Win98 or 2000 PCs have a section called [winlogon] in their WIN.INI, or anything referring to our domain name.
 

Chris Kelleher

Administrator
Staff member
Here's a program written by Todd Nist to get the NT domain using the Windows API:

The call which I think you are looking for is NetServerEnum.

Below is a the general code which shows how to use it. I believe that I
have posted an example of the to http://www.global-shared.com/.

HTH.

Regards,

Todd G. Nist

Code:
/*--------------------------------------------------------------------------
---
  Constants for type of computer
----------------------------------------------------------------------------
--*/
&GLOB SV_TYPE_WORKSTATION                1
&GLOB SV_TYPE_SERVER                     2
&GLOB SV_TYPE_SQLSERVER                  4
&GLOB SV_TYPE_DOMAIN_CTRL                8
&GLOB SV_TYPE_DOMAIN_BAKCTRL            16
&GLOB SV_TYPE_TIME_SOURCE               32
&GLOB SV_TYPE_AFP                       64
&GLOB SV_TYPE_NOVELL                   128
&GLOB SV_TYPE_DOMAIN_MEMBER            256
&GLOB SV_TYPE_PRINTQ_SERVER            512
&GLOB SV_TYPE_DIALIN_SERVER           1024
&GLOB SV_TYPE_XENIX_SERVER            2048
&GLOB SV_TYPE_SERVER_UNIX             2048
&GLOB SV_TYPE_NT                      4096
&GLOB SV_TYPE_WFW                     8192
&GLOB SV_TYPE_SERVER_MFPN            16384
&GLOB SV_TYPE_SERVER_NT              32768
&GLOB SV_TYPE_POTENTIAL_BROWSER      65536
&GLOB SV_TYPE_BACKUP_BROWSER        131072
&GLOB SV_TYPE_MASTER_BROWSER        262144
&GLOB SV_TYPE_DOMAIN_MASTER         524288
&GLOB SV_TYPE_SERVER_OSF           1048576
&GLOB SV_TYPE_SERVER_VMS           2097152
&GLOB SV_TYPE_WINDOWS              4194304
&GLOB SV_TYPE_ALTERNATE_XPORT    536870912
&GLOB SV_TYPE_LOCAL_LIST_ONLY   1073741824
&GLOB SV_TYPE_DOMAIN_ENUM       2147483648
&GLOB SV_TYPE_ALL                    65535

/* ------------------------------------------------
  Structured used by NetServerEnum
--------------------------------------------------*/
/**********************************
Private Type SERVER_INFO_101
    wki101_platform_id As Long
    wki101_servername As Long
    wki101_langroup As Long
    wki101_ver_major As Long
    wki101_ver_minor As Long
    wki101_lanroot As Long
End Type
*******************************/

/*------------------------------------------------ 
   Network API declarations 
------------------------------------------------*/
PROCEDURE NetServerEnum EXTERNAL "Netapi32.dll":
  define input  parameter lpServerName   as  long.  /* pointer to string
containing the name of the remote server */
  define input  parameter dwLevel        as  long.  /* Specifis the
information level of the data. */
  define output parameter lpServerInfo   as  long.  /* pointer to a buffer
which contains the SERVER_INFO, level (100 or 101) */
  define input  parameter dwPrefMaxLen   as  long.  /* Perfered max len of
returned data.  If this is max_perfered_length,
the function will allocate the amount of memory needed for the data */
  define output parameter dwEntriesRead  as  long.  /* pointer to dword
value that receives the number of entries read */
  define output parameter dwTotalEntries as  long.  /* pointer to a dword
value that receives the total number of visible
servers and workstations on the network */
  define input  parameter dwServerType   as  long.  /* server type */
  define input  parameter lpDomain       as  long.  /* pointer to string
containing domain */
  define input  parameter ResumeHandle   as  long.  /* reserved, must be 0.
*/
  define return parameter iRetCode       as  long.  /* non 0 on success */
END.

PROCEDURE NetApiBufferFree EXTERNAL "Netapi32.dll":U:
  define input  parameter lpServerInfo   as  long.  /* pointer to a buffer
that was previously returned by another network
mamagement function. */
  define return parameter iRetCode       as  long.  
END.

PROCEDURE GetComputerNameA EXTERNAL "kernel32.dll":U:
  define output       parameter lpBuffer AS char.
  define input-output parameter nSize    AS LONG.
  define return       parameter intResult AS SHORT.
END PROCEDURE.

PROCEDURE WideCharToMultiByte   EXTERNAL "KERNEL32.dll":
  define input  parameter uCodePage         as long.  /* code page
*/
  define input  parameter dwFlags           as long.  /* performance and
mapping flags     */
  define input  parameter lpWideCharStr     as long.  /* address of
wide-character string  */
  define input  parameter cbWideChar        as long.  /* number of
characters in string, if -1 is calculated on the fly */
  define input  parameter lpMultiByteStr    as long.  /* address of buffer
for new string */
  define input  parameter cbMultiByte       as long.  /* size of buffer */
  define input  parameter lpDefaultChar     as long.  /* address of default
for unmappable characters */
  define input  parameter lpUsedDefaultChar as long.  /* address of flag set
when default char is used */
  define return parameter iRetCode          as long.  /* if successful,
number of bytes written to the lpMultiByteStr buffer, else 0 */
END.

Function GetComputerName()
RETURNS CHARACTER
  ( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------

  Function:    GetComputerName

  Description: Returns a character string of the computer name.

  History: 
          
------------------------------------------------------------------------*/
  &SCOPE MAX_COMPUTERNAME_LENGTH 16

  def var iResult       as integer  no-undo.
  def var iBufferSize   as integer  no-undo init {&MAX_COMPUTERNAME_LENGTH}.

  def var iBuffer       as integer  no-undo.
  def var cComputerName as char     no-undo.
  
  cComputerName = fill(' ', {&MAX_COMPUTERNAME_LENGTH}).

  run GetComputerNameA (output       cComputerName,
                        input-output iBufferSize,
                        output       iResult).

  if iResult <> 1 then
  do:
    message 'Unable to determine local computer name.':T70 view-as alert-box
error.
    return "":U.
  end.

  return ( cComputerName ).

END FUNCTION.


define variable cLocalComputerName  as  char    no-undo.
define variable iRetCode            as  integer no-undo.
define variable iOffset             as  integer no-undo.
define variable i                   as  integer no-undo.
define variable iTotalEntries       as  integer no-undo.
define variable iEntriesRead        as  integer no-undo.
define variable iServerInfo         as  integer no-undo.
define variable lpServerInfo        as  memptr  no-undo.
define variable lpServerName        as  memptr  no-undo.


cLocalComputerName = GetComputerName().

RUN NetServerEnum( input 0,                                 /* pointer to
string containing the server name to execute this function on */
                     input 101,                               /* SERVER_INFO
to return, 100 or 101 */
                     output iServerInfo,                      /* pointer to
the SERVER_INFO Structure base on 100 or 101 */
                     input {&MAX_PREFERRED_LENGTH},           /* max
perfered lenth, if set to -1 it will allocate necessary space */
                     output iEntriesRead,                     /* total
number of entries returned     */
                     output iTotalEntries,                    /* total
number of entries              */
                     input {&SV_TYPE_DOMAIN_CTRL},            /* server type
to enumerate */
                     /* {&SV_TYPE_ALL}, */                    /* list all
machines on network */
                     input 0,                                 /* ptr to
string containing Domain Name */
                     input 0,                                 /* reserved,
must be 0 */
                     output iRetCode).                        /* non 0 on
success */
  
  set-pointer-value(lpServerInfo) = iServerInfo.
               
  iOffSet = 1.

  set-size(lpServerName) = 0.
  set-size(lpServerName) = 512.
  
  do i = 1 to iEntriesRead:

    run WideCharToMultiByte( input 0,             /* use ANSI code page */
                             input 0,             /* flags that specify the
handling of unmapped characters */
                             input get-long(lpServerInfo, iOffset + 4), /*
pointer to wide-character string (unicode) */
                             input -1,            /* count of bytes of the
wide-character string, if -1 calculate on the fly */
                             input get-pointer-value(lpServerName), /*
address of buffer for new string */
                             input get-size(lpServerName),
                             input 0,
                             input 0,
                             output iRetCode).

    if iRetCode <> 0 then
      phSelectionList:ADD-LAST(get-string(lpServerName,1) + (if
cLocalComputerName = get-string(lpServerName,1) then ' (Local)':U else
'':U)).
    iOffset = iOffset + 24.

  end.

  RUN NetApiBufferFree( input get-pointer-value(lpServerInfo),
                        output iRetCode ).
                        
  set-size(lpServerName) = 0.
 

muthu

New Member
Getting details from WIN2000

The Win.ini is loaded basically to overcome the normal progress.ini or any initialisation file which you have written for progress.

if you use the command get-key-value from the section "WINLOGON" (for your kind info it is very well available in WIN2000 registry HKEY_LOCAL_MACHINE/software/microsoft/WINNT/currentversion/winlogon. In this hive you can find cachedomain, defaultusername, defaultdomainname. I think it is better for the people to check this in their registry). I think you can try the code i sent earlier.

thanks and regards

Muthu
 

MurrayH

Member
Look in the registry here on NT:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters

Look in here at DHCPDomain and Hostname

Murray
 

NickA

Member
Thanks everybody

Thanks for all the responses :)

To summarise, I've the following choices...

1. Pick the domain from the registry. Win95 flavours hold the info in a different place to NT/2000. I'd hoped to avoid doing this as I was initially _sure_ there'd be a simple API call for it.

2. Get the domain from a section called [winlogon] in win.ini. Unfortunately there is nothing in my win.ini remotely like that, so I can't assume that it will always be there.

3. API call:NetServerEnum. Sounds great, but it's NT/2000 specific: It'll never work on 95/98/Me.

I don't think I've got much choice but to take option (1) - poke about in the registry. Ah well.

Thanks for all the help.
 
Top