oriceon/wmi
Composer 安装命令:
composer require oriceon/wmi
包简介
A package for WMI manipulation using PHP and COM.
README 文档
README
Requirements
To use WMI, your server must meet the following requirements:
- Windows OS
- PHP 5.4 or Greater
- PHP COM extension enabled
Installation
Insert WMI into your composer.json:
"oriceon/wmi": "^1.0"
Now run composer update.
You're all set!
Usage
Connecting
To use WMI, you must create a new WMI instance. To interact with the current computer, just create a WMI instance:
use Oriceon\Wmi\Wmi;
$wmi = new Wmi();
To interact with a PC on your network, you'll need to enter a host name, and a username and password if needed:
$wmi = new Wmi($host = 'GUEST-PC', $username = 'guest', $password = 'password');
Now we can connect to it, but you'll need to specify the namespace you're looking to connect to:
$wmi->connect('root\\cimv2');
The connect() method will return true or false if the connection was successful:
if ($connection = $wmi->connect('root\\cimv2'))
{
echo "Cool! We're connected.";
$query = $connection->newQuery();
}
else {
echo "Uh oh, looks like we couldn't connect.";
}
Querying
CAUTION: Before we get started with queries, you should know that NO VALUES are escaped besides quotes inside any query method. This package is not meant to handle user input, and you should not allow users to query computers on your network.
Raw Queries
Once you've connected to the computer, you can execute queries on it with its connection. To execute a raw query, use:
$connection = $wmi->getConnection();
$results = $connection->query('SELECT * FROM Win32_LogicalDisk');
foreach($results as $disk)
{
$disk->Size;
}
Query Builder
WMI Comes with a WQL query builder so you're able to easily build statements. To create a new Builder use the newQuery()
method on the WMI connection instance like so:
$query = $wmi->getConnection()->newQuery();
Once you have the query, we can start building:
$results = $query->select('*')
->from('Win32_LogicalDisk')
->where('Size', '>=', '150000')
->get();
Select
The select method accepts a string or an array to insert selects onto the current query. For example:
// Select All
$query->select('*');
// Select Specific
$query->select(['Name', 'Disk', 'Size']);
// Select Specific (string)
$query->select('Name, Disk, Size');
If you don't use the select method, that's fine too. The Builder will assume you're meaning to select all columns, so you're able to perform:
$query->from('Win32_LogicalDisk')->get();
// Query Executed
SELECT * FROM Win32_LogicalDisk
From
The from method accepts a string that is a WMI class name. For example:
$query->from('Win32_DiskDrive')->get();
// Or
$query->from('Win32_BIOS')->get();
For more information on WMI classes, visit: https://msdn.microsoft.com/en-us/library/aa394132(v=vs.85).aspx
Where
The where method accepts a field, operator and value. This is useful for retrieving data with a specific set of requirements.
The method:
$query->where($field, $operator, $value);
Example:
$query->where('Size', '>', 15000)->from('Win32_LogicalDisk')->get();
The field parameter needs to be an attribute in the from class, otherwise you will not receive the correct results.
Original code fwork from: stevebauman/wmi
oriceon/wmi 适用场景与选型建议
oriceon/wmi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 oriceon/wmi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oriceon/wmi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-26