Getting Started
REQUIREMENTS
>= PHP 7.1
Windows and the com_dotnet
extension enabled (available in every Windows PHP
release).
Install
composer require phpwintools/wmi-scripting
Basic Configuration
There isn't much configuration that needs to be done to get started with this library. You only need to set the connections before using this in your own application.
Local Connection
// Returns a ModelCollection of LoggedOnUser models from the local machine
$local = LoggedOnUser::query()->get();
$scripting = new Scripting;
// Same as above
$local = $scripting->query()->loggedOnUser()->get();
2
3
4
5
6
If no configuration is provided, the library's default connection is localhost.
Static call on Win32Model class
$connection = Connection::simple('computer-one', 'admin', 'password');
// Returns an instance of Query\Builder
$builder = LoggedOnUser::query($connection);
// Returns a ModelCollection of Models\LoggedOnUsers
$loggedOnUsers = $builder->get();
2
3
4
5
6
7
A connection defined in this way will not be stored in the Config
container. This is useful when you need to reference
many connections in an array to poll many computers across your network.
$username = 'admin';
$password = 'password';
$computers = ['computer_one', 'computer_two'];
$results = [];
foreach ($computers as $computer) {
// $results becomes an array of ModelCollections
$results[] = LoggedOnUser::query(Connection::simple($computer, $user $password));
}
2
3
4
5
6
7
8
9
10
Scripting
Class
With $scripting = new Scripting(Connection::simple('computer-one', 'admin', 'password));
// Returns and instance of Query\Builder (same as above)
$builder = $scripting->query()->loggedOnUser();
2
3
4
This will set the given connection as the default connection. All models queried without a given connection will use this connection.
$scripting = new Scripting;
$scripting->addConnection(
'computer-one',
Connection::simple('computer-one', 'admin', 'password')
);
$builder = $scripting->query('computer-one)->loggedOnUser();
// This connection is also available to the Models
$builder = LoggedOnUser::query('computer-one');
2
3
4
5
6
7
8
9
10
Adding a connection in this way will store the connection for later and repeated use.
Scripting
should only be instantiated once. If it is instantiated more than once then the last configuration options
will be used.