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.
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
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_computern ame, buf);
SetDlgItemText(IDC_COMPUTE RNAME, buf);
UNI2ASC((BYTE *)pwksta->wki100_langroup, buf);
SetDlgItemText(IDC_LANGROU P, buf);
}
else{
AfxMessageBox(_T("NetWksta GetInfo 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);
}
}
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_computern
SetDlgItemText(IDC_COMPUTE
UNI2ASC((BYTE *)pwksta->wki100_langroup,
SetDlgItemText(IDC_LANGROU
}
else{
AfxMessageBox(_T("NetWksta
}
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);
}
}
ASKER
sorry I'm going to have to go with JKR's answer it is way easier.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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