获取Windows Cluster IP的VBS脚本和命令(无powershell)

来源:互联网 发布:如何在C语言中用开根 编辑:程序博客网 时间:2024/05/29 12:08

strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  Set IPConfigSet = objWMIService.ExecQuery _     ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")   For Each IPConfig in IPConfigSet     If Not IsNull(IPConfig.IPAddress) Then          For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)             WScript.Echo IPConfig.IPAddress(i)         Next     End If Next用这个命令也行:nbtstat -a <cluster name>cluster res "Cluster IP Address" /priv/////////////////////////////////////////////////////
vector<wstring> GetCoreClusterIPAddresses(){    vector<wstring> coreIPAddresses;    wstring coreGroup = GetCoreClusterGroup();    HCLUSTER hCluster = OpenCluster(NULL);    if(hCluster)    {        HGROUP hCoreGroup = OpenClusterGroup(hCluster, coreGroup.c_str());        if(hCoreGroup)        {            DWORD index = 0, type = 0, nameSize = MAX_PATH;            wstring resourceName;            resourceName.resize(MAX_PATH);            HGROUPENUM hGroupEnum = ClusterGroupOpenEnum(hCoreGroup, CLUSTER_GROUP_ENUM_CONTAINS);            if(hGroupEnum)            {                DWORD status = ClusterGroupEnum(hGroupEnum, index, &type, &resourceName[0], &nameSize);                while(ERROR_SUCCESS == status)                {                    HRESOURCE hResource = OpenClusterResource(hCluster, &resourceName[0]);                                        if(hResource)                    {                        wstring resourceType;                        resourceType.resize(MAX_PATH);                        DWORD resourceTypeSize = MAX_PATH;                                                if(ERROR_SUCCESS == ClusterResourceControl(hResource, NULL, CLUSCTL_RESOURCE_GET_RESOURCE_TYPE, NULL, NULL, &resourceType[0], MAX_PATH, &resourceTypeSize))                        {                            if(_wcsicmp (resourceType.c_str(), L"IP Address") == 0 || _wcsicmp (resourceType.c_str(), L"IPv6 Address") == 0 )                            {                                wstring privProperties;                                privProperties.resize(4096);                                DWORD propSize;                                if(ERROR_SUCCESS == ClusterResourceControl(hResource, NULL, CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES, NULL, NULL, &privProperties[0], 4096, &propSize))                                {                                    LPWSTR pPropValue = 0;                                     ResUtilFindSzProperty(&privProperties[0], propSize, L"Address", &pPropValue);                                    coreIPAddresses.push_back(pPropValue);                                    if(pPropValue)                                        LocalFree(pPropValue);                                }                            }                                                  }                        CloseClusterResource(hResource);                    }                    index++;                    nameSize = MAX_PATH;                    resourceName.resize(MAX_PATH);                    status = ClusterGroupEnum(hGroupEnum, index, &type, &resourceName[0], &nameSize);                }                ClusterGroupCloseEnum(hGroupEnum);            }            CloseClusterGroup(hCoreGroup);        }        CloseCluster(hCluster);    }    return coreIPAddresses;}wstring GetCoreClusterGroup(){    wstring coreGroup;    HCLUSTER hCluster = OpenCluster(NULL);    if(hCluster)    {        HRESOURCE hClusterName = NULL, hClusterIPAddress = NULL, hClusterQuorum = NULL;        if(ERROR_SUCCESS == ResUtilGetCoreClusterResources(hCluster, &hClusterName, &hClusterIPAddress, &hClusterQuorum))        {           coreGroup.resize(MAX_PATH);           DWORD groupSize = MAX_PATH;                      GetClusterResourceState(hClusterName, NULL, NULL, &coreGroup[0], &groupSize);                     if(hClusterName)                CloseClusterResource(hClusterName);            if(hClusterIPAddress)                CloseClusterResource(hClusterIPAddress);            if(hClusterQuorum)                CloseClusterResource(hClusterQuorum);        }        CloseCluster(hCluster);    }        return coreGroup;}

原创粉丝点击