Software Archive
Read-only legacy content
17060 Discussions

checking NT-domain

Intel_C_Intel
Employee
369 Views
Hello,

I have an application that has to behave differently at different branches of our company. Someone suggested to check on the NT-domain name to find out where the program is running, but I have no idea how to accomplish this. Does any one have an idea how to do this? Or perhaps there is a better method to check where the program is running?
I prefer not to check on the presence of specific files at certain locations etc.

Thanks,

Walter Kramer
0 Kudos
6 Replies
Steven_L_Intel1
Employee
369 Views
See if the GetComputerName Win32 API routine does what you want.

Steve
0 Kudos
Intel_C_Intel
Employee
369 Views
GetComputerName doesn't do exactly what I wanted, but it got me on the right track.
I use the following approach:

  
USE NETAPI32  
USE DFNLS  
character(MAX_COMPUTERNAME_LENGTH+1) DomainName  
integer(2), dimension($MAXPATH) :: UniStr1  
integer(2), dimension($MAXPATH) :: UniStr2  
POINTER        (P,UniStr2)  
!  
! Check if valid domain name  
!  
 DomainName='FLIPFLOP'C  
 iret=MBConvertMBToUnicode(DomainName,UniStr1)  
 if (.NOT.NetGetAnyDCName(0,LOC(UnisStr1),LOC(P))) then  
   iret=MBConvertUnicodeToMB(UNISTR2,DOMAINNAME)  
   iret=NetApiBufferFree(P)  
 endif  


The NETAPI32 module is defined as follows:

  
!  
!DEC$ IF .NOT. DEFINED (NETAPI32_ )  
!DEC$ DEFINE NETAPI32_    
!  
module netapi32  
use dfwinty  
!DEC$OBJCOMMENT LIB:"NETAPI32.LIB"  
  
interface !lib=netapi32.lib  
integer function  NetGetDCName (servername,domainname,bufptr)   
!DEC$ ATTRIBUTES DEFAULT :: NetGetDCName  
!DEC$ IF DEFINED(_X86_)  
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_NetGetDCName@12' :: NetGetDCName  
!DEC$ ELSE  
!DEC$ ATTRIBUTES STDCALL, ALIAS :  'NetGetDCName'   :: NetGetDCName  
!DEC$ ENDIF  
integer   servername  
integer   domainname  
integer         bufptr  
end function NetGetDCName  
end interface  
  
interface !lib=netapi32.lib  
integer function  NetGetAnyDCName (servername,domainname,bufptr)   
!DEC$ ATTRIBUTES DEFAULT :: NetGetAnyDCName  
!DEC$ IF DEFINED(_X86_)  
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_NetGetAnyDCName@12' :: NetGetAnyDCName  
!DEC$ ELSE  
!DEC$ ATTRIBUTES STDCALL, ALIAS :  'NetGetAnyDCName'   :: NetGetAnyDCName  
!DEC$ ENDIF  
integer   servername  
integer   domainname  
integer         bufptr  
end function NetGetAnyDCName  
end interface  
  
interface !lib=netapi32.lib  
integer function  NetApiBufferFree (Buffer)  
!DEC$ ATTRIBUTES DEFAULT :: NetApiBufferFree  
!DEC$ IF DEFINED(_X86_)  
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_NetApiBufferFree@4' :: NetApiBufferFree  
!DEC$ ELSE  
!DEC$ ATTRIBUTES STDCALL, ALIAS :  'NetApiBufferFree'   :: NetApiBufferFree  
!DEC$ ENDIF  
integer         buffer  
end function NetApiBufferFree  
end interface  
  
end module  
!DEC$ ENDIF ! /* NETAPI32_ */  


Perhaps a bit elaborate, but it works.

Walter
0 Kudos
Intel_C_Intel
Employee
369 Views
The checking of the NT-domain works, but now there is a new problem. The program won't run on a computer that isn't attached to a network.
I get the following messages:

"The file fluppy is linked to missing output NETAPI32.DLL: NetApiBufferFree"

and

"Could not execute: A device attached to the system doesn't work (Win32 error 31)"

(I translated from Dutch, so the exact text might be a bit different in English)

I was hoping (although deep down I know better) that I could cope with one version of the program.

Is there a way to solve this, or do I have to create different versions of the program through conditional compilation?

Walter
0 Kudos
Intel_C_Intel
Employee
369 Views
The documentation for NetGetAnyDCName is a bit terse, but from reading it a bit, it doesn't seem unusual to get an error on a non-networked PC, especially given a non-nulll domainname - although I don't know much about the Dutch translation of the errors you got. ;) One note you probably already know, the function isn't supported on Win9x.

If it were me, I'd look at NetWkstaUserGetInfo with level equal to 1 - using the WKSTA_USER_INFO_1 struct. For broadest coverage, including server threads running under impersonation (and a link to a Win9x solution) check MS KB article Q111544.

Good luck,
John
0 Kudos
Intel_C_Intel
Employee
369 Views
I am afraid NetWkstaUserGetInfo gives exactly the same error messages. It seems that all netapi32.dll routines generate an error on a non-networked PC.

Thanks for the input,

Walter
0 Kudos
Intel_C_Intel
Employee
369 Views
Are you sure that the non-networked PC isn't a Win95 machine? The error messages appear as though netapi32.dll isn't there. But I'm fairly sure that netapi32.dll is installed on NT4 even if networking is not installed at system installation.

The translated error messages also make me think that this may be the case.

The .EXE file is linked to missing export NETAPI32.DLL:NetApiBufferFree
A device attached to the system is not functioning (Win32 error 31)

For example, see MS KB article Q134590.

If it is a Win9x machine, then the prior posted article (Q111544 with the link to Q155698) most likely contains the only general solution.

Other than that, I'm out of suggestions.

-John
0 Kudos
Reply