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.
LVL 1
mdlillyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.