添加电脑到域

来源:互联网 发布:java中配置文件是什么 编辑:程序博客网 时间:2024/06/01 07:48

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;
    }


0 0