|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpWinTools\WmiScripting\Support\ApiObjects; |
|
4
|
|
|
|
|
5
|
|
|
use PhpWinTools\Support\COM\ComVariantWrapper; |
|
6
|
|
|
use function PhpWinTools\WmiScripting\Support\resolve; |
|
7
|
|
|
use PhpWinTools\WmiScripting\Connections\ComConnection; |
|
8
|
|
|
use function PhpWinTools\WmiScripting\Support\connection; |
|
9
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Locator; |
|
10
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Services; |
|
11
|
|
|
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\LocatorVariant; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemlocator |
|
15
|
|
|
*/ |
|
16
|
|
|
class SWbemLocator extends AbstractWbemObject implements Locator |
|
17
|
|
|
{ |
|
18
|
|
|
const SCRIPTING = 'WbemScripting'; |
|
19
|
|
|
|
|
20
|
|
|
/** @var ComVariantWrapper|LocatorVariant */ |
|
21
|
|
|
protected $object; |
|
22
|
|
|
|
|
23
|
2 |
|
public function __construct(ComVariantWrapper $object = null) |
|
24
|
|
|
{ |
|
25
|
2 |
|
$object = $object ?? resolve()->comWrapper(resolve()->comClass(self::SCRIPTING . '.SWbemLocator')); |
|
26
|
|
|
|
|
27
|
2 |
|
parent::__construct($object); |
|
28
|
2 |
|
} |
|
29
|
|
|
|
|
30
|
2 |
|
public function connectServer(ComConnection $connection = null): Services |
|
31
|
|
|
{ |
|
32
|
2 |
|
$connection = connection($connection); |
|
33
|
|
|
|
|
34
|
2 |
|
return resolve()->services( |
|
35
|
2 |
|
$this->object->ConnectServer( |
|
|
|
|
|
|
36
|
2 |
|
$connection->getServer(), |
|
37
|
2 |
|
$connection->getNamespace(), |
|
38
|
2 |
|
$connection->getUser(), |
|
39
|
2 |
|
$connection->getPassword(), |
|
40
|
2 |
|
$connection->getLocale(), |
|
41
|
2 |
|
$connection->getAuthority(), |
|
|
|
|
|
|
42
|
2 |
|
$connection->getSecurityFlags() |
|
|
|
|
|
|
43
|
|
|
), |
|
44
|
2 |
|
$connection |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|