• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Get Current Domain for computer via software

I need to be able to query a computer running my J++ application what domain it is currently set to.  I'm guessing there is an API to do this, but I can't seem to find it, and also I have to be able to do it via java (MS-J++ 6.0) application.
0
mdlilly
Asked:
mdlilly
  • 2
  • 2
  • 2
1 Solution
 
jhanceCommented:
I assume you are talking about the NT Domain and not TCPIP domain.  If I'm wrong let me know and I'll post that information instead.

I can't speak specifially how to do it in JAVA (I don't know much about it) but here is how to do it using the Windows NT API:

http://support.microsoft.com/support/kb/articles/q170/6/20.asp
0
 
mdlillyAuthor Commented:
Could you give me a trimmed down example that just returns the name of the domain as a char* or something, I don't have the time to sort through that code right now, I also bumped the points to 550 for you
0
 
jkrCommented:
I'm sorry, but this is overkill for this task. The domain name is stored in an environment variable called 'USERDOMAIN', and the value actually is the current domain name...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jhanceCommented:
Here's a snippet of some code I've used in the past that does this.

      WKSTA_INFO_100 **ppwksta, *pwksta;

      ppwksta = &pwksta;


      NET_API_STATUS stat = NetWkstaGetInfo(NULL, 100, (LPBYTE *)ppwksta);
      if(stat == NERR_Success){
            CString buf;
            UNI2ASC((BYTE *)pwksta->wki100_computername, buf);
            SetDlgItemText(IDC_COMPUTERNAME, buf);
            UNI2ASC((BYTE *)pwksta->wki100_langroup, buf);
            SetDlgItemText(IDC_LANGROUP, buf);
      }
      else{
            AfxMessageBox(_T("NetWkstaGetInfo returned an ERROR"), MB_OK);
      }

void ASC2UNI(BYTE **p, CString &r)
{

      *p = new BYTE[r.GetLength()*2];
      memset(*p, 0, r.GetLength()*2);
      for(int i=0; i<r.GetLength(); i++){
            *(*p+(i*2)) = r.GetAt(i);
      }
}
0
 
mdlillyAuthor Commented:
sorry I'm going to have to go with JKR's answer it is way easier.
0
 
jkrCommented:
>>sorry I'm going to have to go with JKR's answer it is way
>>easier.

Take this as an 'invitation' to 'answer'.

Fine that it works for you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now