' com_wmi.pb — WMI query simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL wmiConnected AS LONG
    LOCAL classIDs(20) AS LONG
    LOCAL numClasses AS LONG
    LOCAL propertyNameIDs(50) AS LONG
    LOCAL propertyValues(50) AS LONG
    LOCAL numProperties AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL queryID AS LONG
    LOCAL resultCount AS LONG
    LOCAL iter AS LONG
    LOCAL classID AS LONG
    LOCAL propVal AS LONG
    LOCAL nameID AS LONG
    LOCAL nameStr AS STRING

    PRINT "=== WMI Query Simulation ==="

    wmiConnected = 1
    IF wmiConnected = 1 THEN
        PRINT "Connected to root\cimv2"
    END IF

    classIDs(0) = 0
    classIDs(1) = 1
    classIDs(2) = 2
    classIDs(3) = 3
    classIDs(4) = 4
    numClasses = 5

    FOR queryID = 1 TO 6
        classID = queryID MOD numClasses

        IF classID = 0 THEN PRINT "  Query: SELECT * FROM Win32_Processor"
        IF classID = 1 THEN PRINT "  Query: SELECT * FROM Win32_LogicalDisk"
        IF classID = 2 THEN PRINT "  Query: SELECT * FROM Win32_OperatingSystem"
        IF classID = 3 THEN PRINT "  Query: SELECT * FROM Win32_Process"
        IF classID = 4 THEN PRINT "  Query: SELECT * FROM Win32_Service"

        IF classID = 0 THEN numProperties = 4
        IF classID = 1 THEN numProperties = 4
        IF classID = 2 THEN numProperties = 3
        IF classID = 3 THEN numProperties = 3
        IF classID = 4 THEN numProperties = 3

        PRINT "    Results: " + STR$(numProperties) + " properties"

        IF classID = 0 THEN
            propertyNameIDs(0) = 1
            propertyValues(0) = 1
            propertyNameIDs(1) = 2
            propertyValues(1) = 4
            propertyNameIDs(2) = 3
            propertyValues(2) = 3200
            propertyNameIDs(3) = 4
            propertyValues(3) = 9
        END IF

        IF classID = 1 THEN
            propertyNameIDs(0) = 5
            propertyValues(0) = 67
            propertyNameIDs(1) = 6
            propertyValues(1) = 512000
            propertyNameIDs(2) = 7
            propertyValues(2) = 204800
            propertyNameIDs(3) = 8
            propertyValues(3) = 1
        END IF

        IF classID = 2 THEN
            propertyNameIDs(0) = 9
            propertyValues(0) = 1
            propertyNameIDs(1) = 10
            propertyValues(1) = 100
            propertyNameIDs(2) = 11
            propertyValues(2) = 19045
        END IF

        IF classID = 3 THEN
            propertyNameIDs(0) = 12
            propertyValues(0) = 1
            propertyNameIDs(1) = 13
            propertyValues(1) = 100 + queryID
            propertyNameIDs(2) = 14
            propertyValues(2) = 8
        END IF

        IF classID = 4 THEN
            propertyNameIDs(0) = 15
            propertyValues(0) = 1
            propertyNameIDs(1) = 16
            propertyValues(1) = 4
            propertyNameIDs(2) = 17
            propertyValues(2) = 2
        END IF

        FOR i = 0 TO numProperties - 1
            nameID = propertyNameIDs(i)
            propVal = propertyValues(i)
            IF nameID = 1 THEN nameStr = "Name"
            IF nameID = 2 THEN nameStr = "NumberOfCores"
            IF nameID = 3 THEN nameStr = "MaxClockSpeed"
            IF nameID = 4 THEN nameStr = "Architecture"
            IF nameID = 5 THEN nameStr = "DeviceID"
            IF nameID = 6 THEN nameStr = "Size"
            IF nameID = 7 THEN nameStr = "FreeSpace"
            IF nameID = 8 THEN nameStr = "FileSystem"
            IF nameID = 9 THEN nameStr = "Caption"
            IF nameID = 10 THEN nameStr = "Version"
            IF nameID = 11 THEN nameStr = "BuildNumber"
            IF nameID = 12 THEN nameStr = "Name"
            IF nameID = 13 THEN nameStr = "ProcessId"
            IF nameID = 14 THEN nameStr = "ThreadCount"
            IF nameID = 15 THEN nameStr = "DisplayName"
            IF nameID = 16 THEN nameStr = "State"
            IF nameID = 17 THEN nameStr = "StartMode"
            PRINT "      " + nameStr + " = " + STR$(propVal)
        NEXT i
        resultCount = resultCount + 1
    NEXT queryID

    PRINT "Total queries: " + STR$(resultCount)
    PRINT "=== End WMI ==="
    FUNCTION = 0
END FUNCTION
