ENVI^ ForceLocal=1

_SUB IsOnLine //\\.\PhysicalDeive0 &sRet
    //#define IOCTL_DISK_GET_DISK_ATTRIBUTES      CTL_CODE(IOCTL_DISK_BASE, 0x003c, METHOD_BUFFERED, FILE_ANY_ACCESS)
    //                                CTL_CODE(0x00000007,0x003c,0,0) =(0x00000007 << 16) | (0 << 14) | ((0x003c) << 2) | 0=
    //CTL_CODE( DeviceType, Function, Method, Access )    ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) 
    CALC -base=16 #&&IOCTL_DISK_GET_DISK_ATTRIBUTES=shl(0x00000007,16) | shl(0,14) | shl(0x003c ,2) | 0   //0x70000|0|0xF0|0=0x700F0
    SET &DISK_ATTRIBUTE_OFFLINE=0x0000000000000001
    CALL  $--qd --ret:&&h Kernel32,CreateFileW,$%~1,#0,#0,#0,#3,#0,#0
    SET#$ nret=*8 0
    SET#$ buf=10 *16 0
    SET &sz=16
    CALL  $--qd --ret:&&r Kernel32,DeviceIoControl,#%&h%,#%&IOCTL_DISK_GET_DISK_ATTRIBUTES%,#0,#0,*&buf,#%&sz%,*&nRet,#0
    CALL  $--qd --bool Kernel32,CloseHandle,#%&h%

    SET &Attr=%&buf?int64:8%
    CALC #&&offline=%&DISK_ATTRIBUTE_OFFLINE% & %&Attr%
    IFEX #%offline%>0, SET &sRet=OffLine! SET &sRet=OnLine
    ENVI-ret %~2=%&sRet%
    MESS. %&sRet% [%&h% %&r% Attr=%&Attr%  %&nret?long% %&IOCTL_DISK_GET_DISK_ATTRIBUTES%] DEBUG
_END
IsOnLine \\.\PhysicalDrive1 &sRet
MESS. %&sRet%


