WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Find Domain for a Computer

Keywords: 	  find domain for a computer wntGetDc  wntAcctInfo  wntServerList

Question:

Background:

I'm in a environment with a lot of different domains. And the trust-relations between the domains are different from domain to domain. I have a list over computers I want to connect to and make some changes on the machine. But the connect as account information differs between the domains

My problem:

Is there any function ex. wntServerInfo that could return the domain the machine belongs to. Similar to W2k's "find computer". I fully understand that this will be from the browser-list but that's enough for me.

I can't read any reg-value on the machine as i don't have any way to connect to it with a correct username/pwd before i know what domain it belongs to.

Today I use a cmd-file which does a nbtstat and then search for the domain entry.

I have a list containing maybe 100 different machine names.

For every machine in the list i want to resolve what domain it belongs to.

Ex: Running a script on \\SERVER123 and want to find out witch domain \\FILESERVER222 belongs to.

One solution would be to do some looping with wntResources and then make a list over all machines on the network and then search that list. But that's doesn't seem like a nice/quick(=long time to execute the script) solution.

More Background:

LgAdminSid = "S-1-5-32-544"

GroupName = wntAcctInfo( "\\JUMBO", LgAdminSid, 2)
AccountDomain = wntAcctInfo("\\JUMBO", AccountDomain, 0)
This only returns BUILTIN and that's logical. But without knowing the domain the computer belongs to (so i can do a "connect as" with a valid account) "connecting" to the computer doing these things is a problem.

The environment (I'm here to clean it up) are aprox. 90 NT-domains. The trust-environment is a nightmare. And on the bigger part of these domains i have a account that's a memeber of the domain admins group. But the password and username differs between the domains so depending on which domain the machine belongs to I'm forced to use different username and password BEFORE i do any work on the machine. Windows "Find Computer"-box does the job but i want to automate the process.

Answer:

This is a real "catch 22" situation. You need to know the domain of the workstation/server in order to login using the proper credentials to have administrator accesss. However, you cannot directly get this information from any particular system unless you already have administrator access.

There is actually no easy way to do what you want to do. The problem is that if you work based on the assumption that you don't have valid credentials to access the desired computer as an administrator then you cannot directly ask it what domain it belongs to. Likewise, if you lack domain administrator credentials then you cannot directly interrogate a DC for a domain to list all of its computer accounts that it has for member computers, etc...

The only thing that is guaranteed to work is that you need to have a list of domains for which you can call wntServerList(), and then you can search the list of computers in a domain to see if the desired computer is in the list of members for any given domain that you've done this for.

I did find one Win32 API Function, NetWkstaGetInfo(), which can return this information, but you must have Administrators group membership or Print/Server operator privilege. Again, this means that you have to be logged in using a specific account to get this information. It appears that there's no NT extender function that wraps around this Win32 API function, but it could be added in the future as one of the items of information returned by wntServerInfo().

W/o going through a rigorous review of the exact permissions required by the underlying Win32 API functions used by the NT extender, I cannot say for certain whether or not this snippet of code will work for you in your rather complex environment. However, give it a try and see what happens...

AddExtender('WWWNT34I.DLL')

ServerSpec = '\\workstation' ; fill in a valid computer name
DomainSpec = ''
Flag = 0

ErrorMode(@OFF)
DCSpec = wntGetDc(ServerSpec,DomainSpec,Flag)
RC = LastError()
ErrorMode(@CANCEL)

ComputerAccount = StrCat(StrSub(ServerSpec,3,-1),'$')

ErrorMode(@OFF)
ComputerDomain = wntAcctInfo(DCSpec,ComputerAccount,0,0)
RC = LastError()
ErrorMode(@CANCEL)
It runs OK when I execute it on my development system [workgroup node] and I ask it to find the domain of another workstation on the network that is a member of a domain. However, the user account that I'm logged on with locally on my development system also exists on these other computers [with the same password] so I'm probably being implicitly trusted by the remote systems [due to the same credentials existing in all of their SAM databases].

You might also want to check out the WMI code that should work. http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/WMI+Obtain~the~Name~of~the~Domain~to~which~the~Computer~Belongs.txt


Article ID:   W15194
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38