{"id":16308727,"url":"https://github.com/corion/dbd-wmi","last_synced_at":"2025-04-13T03:14:47.951Z","repository":{"id":25821014,"uuid":"29260210","full_name":"Corion/dbd-wmi","owner":"Corion","description":"interface to the Windows WMI","archived":false,"fork":false,"pushed_at":"2019-03-10T10:58:08.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T03:14:45.155Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Corion.png","metadata":{"files":{"readme":"README.mkdn","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-14T18:56:07.000Z","updated_at":"2019-03-10T10:58:10.000Z","dependencies_parsed_at":"2022-07-25T15:02:27.401Z","dependency_job_id":null,"html_url":"https://github.com/Corion/dbd-wmi","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corion%2Fdbd-wmi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corion%2Fdbd-wmi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corion%2Fdbd-wmi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corion%2Fdbd-wmi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Corion","download_url":"https://codeload.github.com/Corion/dbd-wmi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657919,"owners_count":21140846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T21:18:32.340Z","updated_at":"2025-04-13T03:14:47.933Z","avatar_url":"https://github.com/Corion.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.org/Corion/dbd-wmi.svg?branch=master)](https://github.com/Corion/dbd-wmi)\n\n# NAME\n\nDBD::WMI - interface to the Windows WMI\n\n# ABSTRACT\n\nThis module allows you to issue WQL queries\nthrough the DBI.\n\n# SYNOPSIS\n\n    use DBI;\n    my $dbh = DBI-\u003econnect('dbi:WMI:');\n\n    my $sth = $dbh-\u003eprepare(\u003c\u003cWQL);\n      SELECT * FROM Win32_Process\n    WQL\n\n    $sth-\u003eexecute();\n    while (my @row = $sth-\u003efetchrow) {\n      my $proc = $row[0];\n      print join \"\\t\", $proc-\u003e{Caption}, $proc-\u003e{ExecutablePath} || \"\u003csystem\u003e\";\n      # $proc-\u003eTerminate();\n      print \"\\n\";\n    }\n\nThe WMI\nallows you to query various tables (\"namespaces\"), like the filesystem,\ncurrently active processes and events:\n\n    SELECT * FROM Win32_Process\n\nThe driver/WMI implements two kinds of queries, finite queries like the\nquery above and potentially infinite queries for events as they occur in\nthe system:\n\n    my $query = q{\n    \n     SELECT * FROM __instanceoperationevent\n     WITHIN 1\n     WHERE TargetInstance ISA 'Win32_DiskDrive'\n     \n    }\n\nThis query returns one row (via -\u003efetchrow\\_arrayref() ) whenever a disk\ndrive gets added to or removed from the system (think of an USB stick).\n\nThere is currently no support for selecting specific\ncolumns instead of `*`. Support for selecting columns that\nthen get returned as plain Perl scalars is planned.\n\n## `DBD::WMI::db::parse_columns STATEMENT`\n\nThis routine parses out the requested columns\nfrom the WQL statement and returns an array reference\nwith the names of the columns.\n\nCurrently, this only works for `SELECT` statements.\nAll other statements get an implicit column\nof `*`, meaning that the Win32::OLE objects\nwill be returned.\n\n# HANDLING OF QUERY COLUMNS\n\nThe WMI and WQL return full objects instead of single columns. The specification\nof columns is merely a hint to the object what properties to preload. The\nDBD interface deviates from that approach in that it returns objects\nfor queries of the form `SELECT *` and the values of the object\nproperties when columns are specified. These columns are then case sensitive.\n\n# FUN QUERIES\n\n## List all printers\n\n    SELECT * FROM Win32_Printer\n\n## List all print jobs on a printer\n\n    SELECT * FROM Win32_PrintJob\n      WHERE DriverName = 'HP Deskjet 6122'\n\n## Return a new row whenever a new print job is started\n\n    SELECT * FROM __InstanceCreationEvent\n      WITHIN 10\n      WHERE\n        TargetInstance ISA 'Win32_PrintJob'\n\n## Finding the default printer\n\n    SELECT * FROM Win32_Printer\n      WHERE Default = TRUE\n\n## Setting the default printer (untested, WinXP, Win2003)\n\n    use DBI;\n    my $dbh = DBI-\u003econnect('dbi:WMI:');\n    my $sth = $dbh-\u003eprepare(\u003c\u003cWQL);\n        SELECT * FROM Win32_Printer\n    WQL\n\n    $sth-\u003eexecute;\n    while (my @row = $sth-\u003efetchrow) {\n        # We get Win32::OLE objects back:\n        my $printer = $row[0];\n        printf \"Making %s the default printer\\n\", $printer-\u003e{Name};\n        $printer-\u003eSetDefaultPrinter;\n    };\n\n## Find all network adapters with IP enabled\n\n    SELECT * from Win32_NetworkAdapterConfiguration\n      WHERE IPEnabled = True\n\n## Find files in a directory\n\n    ASSOCIATORS OF {Win32_Directory.Name='C:\\WINNT'}\n      WHERE ResultClass = CIM_DataFile\n\n## Find printers on a remote machine\n\n    use DBI;\n    my $machine = 'dawn';\n    my $dbh = DBI-\u003econnect('dbi:WMI:'.$machine);\n    my $sth = $dbh-\u003eprepare(\u003c\u003cWQL);\n        SELECT * FROM Win32_Printer\n    WQL\n\n    $sth-\u003eexecute;\n    while (my @row = $sth-\u003efetchrow) {\n        my $printer = $row[0];\n        printf \"Making %s the default printer on %s\\n\", $printer-\u003e{Name}, $machine;\n        $printer-\u003eSetDefaultPrinter;\n    };\n\n## Get method names of objects\n\n    use Win32::OLE qw(in);\n    ...\n\n    SELECT * FROM Win32_Process\n\n    $sth-\u003eexecute;\n\n    while (my @row = $sth-\u003efetchrow) {\n        for my $method (in $row[0]-\u003eMethods_) {\n            print \"Can call $method() on the object\\n\"\n        };\n    };\n\n# TODO\n\n- Implement placeholders and proper interpolation of values\n- Need to implement DSN parameters for remote computers, credentials\n\n# SEE ALSO\n\nWMI is Microsofts implementation of the WBEM standard ([http://www.dmtf.org/standards/wbem/](http://www.dmtf.org/standards/wbem/)) except that it uses DCOM and not CIM-XML as the transport medium.\n\nThe MS WMI main page at [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi\\_start\\_page.asp](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_start_page.asp)\n\nThe WQL documentation at [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wql\\_sql\\_for\\_wmi.asp](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wql_sql_for_wmi.asp)\n\nThe \"Hey Scripting Guy\" column at [http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspx](http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspx)\n\nWikipedia on WMI at [http://en.wikipedia.org/wiki/Windows\\_Management\\_Instrumentation](http://en.wikipedia.org/wiki/Windows_Management_Instrumentation)\n\nList of available Win32 WMI classes at [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32\\_classes.asp](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp)\n\n# REPOSITORY\n\nThe public repository of this module is\n[https://github.com/Corion/dbd-wmi](https://github.com/Corion/dbd-wmi).\n\n# SUPPORT\n\nThe public support forum of this module is\n[https://perlmonks.org/](https://perlmonks.org/).\n\n# BUG TRACKER\n\nPlease report bugs in this module via the RT CPAN bug queue at\n[https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-WMI](https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-WMI)\nor via mail to [dbd-wmi-Bugs@rt.cpan.org](https://metacpan.org/pod/dbd-wmi-Bugs@rt.cpan.org).\n\n# AUTHOR\n\nMax Maischein `corion@cpan.org`\n\n# COPYRIGHT (c)\n\nCopyright 2009-2018 by Max Maischein `corion@cpan.org`.\n\n# LICENSE\n\nThis module is released under the same terms as Perl itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorion%2Fdbd-wmi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorion%2Fdbd-wmi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorion%2Fdbd-wmi/lists"}