http://stackoverflow.com/questions/10383281/rename-computer-and-join-domain-with-one-reboot-in-c-sharp
//已加入的工作组
LPWSTR lpDomainName = NULL;
NETSETUP_JOIN_STATUS njs = NetSetupUnknownStatus ;
::NetGetJoinInformation(NULL,&lpDomainName,&njs);
int joinGroupLen = WideCharToMultiByte(CP_ACP,0,lpDomainName,-1,NULL,0,NULL,NULL);
char *joinGroup = new char[joinGroupLen+1];
WideCharToMultiByte(CP_ACP,0,lpDomainName,-1,joinGroup,joinGroupLen,NULL,NULL);
joinGroup[joinGroupLen]='\0';
printf(joinGroup);
printf("\n");
delete[] joinGroup;
if (njs == NetSetupUnknownStatus )
{
printf("The status is unknown.\n");
}
else if (njs == NetSetupUnjoined)
{
printf("The computer is not joined.\n");
}
else if (njs == NetSetupWorkgroupName)
{
printf("The computer is joined to a workgroup.\n");
}
else if (njs == NetSetupDomainName)
{
printf("The computer is joined to a domain.\n");
}
else
{
printf("系统异常\n");
}
if (lpDomainName != NULL)
{
NetApiBufferFree(lpDomainName);
lpDomainName=NULL;
}