从Windows 10中运行进程获取路径

时间:2016-11-28 17:43:10

标签: delphi process

我试图从Windows 10中运行进程获取路径但没有成功。这是我正在使用的代码:

$rows = [
    ['k'=>1, 'dop1'=>'take', 'dop2' => 'a', 'dat' => '25-11-2016'],
    ['k'=>2, 'dop1'=>'make', 'dop2' => 'b', 'dat' => '26-11-2016'],
    ['k'=>3, 'dop1'=>'sake', 'dop2' => 'c', 'dat' => '27-11-2016'],
    ['k'=>4, 'dop1'=>'bake', 'dop2' => 'd', 'dat' => '28-11-2016'],
    ['k'=>5, 'dop1'=>'dake', 'dop2' => 'e', 'dat' => '29-11-2016'],
    ['k'=>6, 'dop1'=>'jake', 'dop2' => 'f', 'dat' => '30-11-2016'],
    ['k'=>7, 'dop1'=>'ake', 'dop2' => 'g', 'dat' => '24-11-2016']
];

$filters = [
    ['dat', '=', '27-11-2016'],
    ['dop1', '=', "bake"],
    ['dop1', '=', "sake"],
    ['dop1', '=', "take"],
];


function marrfilter($filters_arr, $rows)
{
    /*
     * Building filters to eval
     */
    $buildFilter = function($op, $val)
    {
        return function($data) use ($val, $op)
        {
            switch($op)
            {
                case '=':
                case '==':
                    return ($data == $val);
                case '===':
                    return ($data === $val);

                case '!=':
                    return ($data != $val);
                case '!==':
                    return ($data !== $val);

                case '>':
                    return ($data > $val);
                case '>=':
                    return ($data >= $val);

                case '<':
                    return ($data < $val);
                case '<=':
                    return ($data <= $val);

                default:
                    throw new Exception('Unknown operand ' . $op);
            }
        };
    };

    $filters = array();
    foreach($filters_arr as $k => $v)
    {
        list($key, $op, $val) = $v;

        if( !isset($filters[$key]) )
        {
            $filters[$key] = $buildFilter($op, $val);
        }
        else
        {
            if( !is_array($filters[$key]) )
            {
                $filters[$key] = array($filters[$key]);
            }

            $filters[$key][] = $buildFilter($op, $val);
        }
    }

    /*
     * Filter function
     */
    $applyFilter = function($row, $fk, $fv)
    {
        // Key not found in row
        if( !array_key_exists($fk, $row) )
        {
            return false;
        }

        // Get row[key] value
        $val = $row[$fk];

        // if we have multiple tests for the filter it's an OR
        if( is_array($fv) )
        {
            foreach($fv as $ft)
            {
                if( $ft($val) === true ) return true; // return true if filter passed

                // or continue if not
            }
        }
        else
        {
            if( $fv($val) === true ) return true; // return true if filter passed
        }

        // if no filter passed, return false
        return false;
    };

    /*
     * Filtering
     */
    $result = array();
    foreach($rows as $row)
    {
        $r = array();
        foreach($filters as $fk => $fv)
        {
            $r[] = $applyFilter($row, $fk, $fv);
        }

        $r = array_filter($r);

        if( count($r) == count($filters) )
        {
            $result[] = $row;
        }
    }

    return $result;
}

我的应用程序要求提升权限,我已经尝试在OpenProcess中使用PROCESS_QUERY_LIMITED_INFORMATION($ 1000),但问题是一样的。

它没有给我任何错误,但是在Windows 10中列表为空。在Windows 7中它没有问题...

拜托,有谁知道发生了什么事?谢谢!

1 个答案:

答案 0 :(得分:0)

如果遵循MSDN documentation,它会告诉您需要初始化PROCESSENTRY和MODULEENTRY结构的dwSize成员变量。

您可以轻松做到:

moduleEntry32.dwSize = sizeof(MODULEENTRY32);

这将解决您的问题