IFEX %&CurFile%.LOG, LOGS --2 * %&CurFile%.LOG
//DOC: https://blog.csdn.net/qq_36533978/article/details/111196377
ENVI^ ENVIMODE=1
ENVI^ ForceLocal=1
SET$ NL=0d 0a
SET &vMsg=
LOCK .com**  //多线程   //.ole为单线程
//SOCK --BSTR   //仅初始化需要 DLL
//SET &COINIT_MULTITHREADED=0
//CALL $--qd Ole32.dll,CoInitializeEx,#0,#%&COINIT_MULTITHREADED%
//--MESS. CoInitializeExRet:%&Error%

//SET &RPC_C_AUTHN_LEVEL_DEFAULT=0
//SET &RPC_C_IMP_LEVEL_IMPERSONATE=3
//SET &EOAC_NONE=0
//CALL $--qd Ole32.dll,CoInitializeSecurity,#0,#-1,#0,#0,#%&RPC_C_AUTHN_LEVEL_DEFAULT%,#%&RPC_C_IMP_LEVEL_IMPERSONATE%,#0,#%&EOAC_NONE%,#0
//--MESS. CoInitializeSecurityRet:%&Error%

//CALL $--ret:&&hwbemuuid  --nrcd ,-LoadLibrary,^wbemuuid.dll  //加载DLL得到句柄 ^自释放

SET#$$ &CLSID_WbemLocator=4590f811 1d3a 11d0 89 1f 00 aa 00 4b 2e 24 //UUID("4590f811-1d3a-11d0-891f-00aa004b2e24")
SET#$$ &IID_IWbemLocator=dc12a687 737f 11cf 88 4d 00 aa 00 4b 2e 24  //INTERFACE("dc12a687-737f-11cf-884d-00aa004b2e24")
SET &CLSCTX_INPROC_SERVER=0x1
SET  &vMsg=
{
    SOCK --unknown &&pLoc  //自动释放  IWbemLocator*
    SOCK --unknown &&pSvc  //自动释放  IWbemServices*
    CALL $--qd --16  OLE32.DLL,CoCreateInstance,*&CLSID_WbemLocator,#0,#%&CLSCTX_INPROC_SERVER%,*&IID_IWbemLocator,*&pLoc
    ----pLoc:%&pLoc?ptr%

    //CALL SetupWBEM &pLoc  &pSvc
//}


//void SetupWBEM(IWbemLocator*& pLoc, IWbemServices*& pSvc)
//_SUB SetupWBEM
    //VARIANT结构体，x64----24b     x86----16b
    SET &stVARIANT=vt:int64 dat:ptr

    SET &iConnectServer=3
    CALL $--16 --qd  #,*&pLoc.%&iConnectServer%,$ROOT\CIMV2,#0,#0,#0,#0,#0,#0,*&pSvc
    SET &vpSvc=%&pSvc?ptr%
    IFEX #%&pSvc?ptr%=0, EXIT -

    SET &RPC_C_AUTHN_WINNT=10
    SET &RPC_C_AUTHZ_NONE=0
    SET &RPC_C_AUTHN_LEVEL_CALL=3
    CALL $--qd Ole32.dll,CoSetProxyBlanket,#%vpSvc%,#%&RPC_C_AUTHN_WINNT%,#%&RPC_C_AUTHZ_NONE%,#0,#%&RPC_C_AUTHN_LEVEL_CALL%,#%&RPC_C_IMP_LEVEL_IMPERSONATE%,#0,#%&EOAC_NONE%
--MESS. CoSetProxyBlanket:%&Error%
//_END

//void BuryPoint_GetDiskMediaType(QStringList& disk_media_type)


    SOCK --unknown &&storageEnumerator  //自动释放  IEnumWbemClassObject*
    SET &selcmd=SELECT * FROM Win32_OperatingSystem
    
    SET &WBEM_FLAG_FORWARD_ONLY=0x20
    SET &WBEM_FLAG_RETURN_IMMEDIATELY=0x10
    CALC -base=16 #&&wbe=%&WBEM_FLAG_FORWARD_ONLY% | %&WBEM_FLAG_RETURN_IMMEDIATELY%
    SET &iExecQuery=20

    CALL $--16 --ret:&&hr --qd  #,*&pSvc.%&iExecQuery%,$WQL,*&selcmd,#%&wbe%,#0,*&storageEnumerator
    ENVI?ptr &storageEnumerator=&&istorageEnumerator
--MESS. storageEnumerator:[%&storageEnumerator?ptr%] [%&istorageEnumerator%]
    IFEX #%&storageEnumerator?ptr%=0, EXIT -


    SET#$ &puReturn=*8 0 //ULONG
    SET &WBEM_INFINITE=0xffffffff
    SOCK --BSTR &&bstrName,,Version  //自动释放
    SET &iIWbemClassObject_Get=4
    SET &iIEnumWbemClassObject_Next=4
    SET &WBEM_S_NO_ERROR=0
    SET &WBEM_S_FALSE=1  //END
    SET &i=0

    LOOP #[ %&i%<5 ],
    {   CALC &i=%&i% + 1
        SOCK --unknown &&storageWbemObject  //自动释放  IWbemClassObject*
        --MESS. storageWbemObject:%&storageWbemObject?ptr%
        CALL $--16 --qd  #,*&storageEnumerator.%&iIEnumWbemClassObject_Next%,#%&WBEM_INFINITE%,#1,*&storageWbemObject,*&puReturn
---MESS uReturn=%&puReturn?long% err=%&Error%
        SET#$ &vName=*24 0 //VARIANT
        CALL $--16 --ret:&&hr --qd  #,*&storageWbemObject.%&iIWbemClassObject_Get%,#%&bstrName%,#0,*&vName,#0,#0
        SET &pName=%&vName?ptr:8% //uintVal;
        SET &sDeviceId=
        IFEX #%pName%=0, SET< vMsg=Version:%NL%
        IFEX #%pName%<>0,
        {   ENVI-mkfixdummy &&str1=%&pName%
            SET< vMsg=Version:%&str1%%NL%
            SOCK --BSTR &&bstrTmp,%&pName%  //自动释放 %&pName%
        }
        IFEX #%&puReturn?long%<>%WBEM_S_NO_ERROR%, EXIT
    }
}
//CALL $ Ole32.dll,CoUninitialize
MESS. %&vMsg%


