Link to home
Start Free TrialLog in
Avatar of mdlilly
mdlilly

asked on

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.
Avatar of jhance
jhance

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
Avatar of mdlilly

ASKER

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
Avatar of jkr
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...
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);
      }
}
Avatar of mdlilly

ASKER

sorry I'm going to have to go with JKR's answer it is way easier.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial