Jump to content

PHP and querying remote registry in WMI


lonewolf217

Recommended Posts

I have two php scripts, one which queries WMI on the root\cimv2 namespace which works without a problem on remote systems.  I have another I am trying to use to query the root\default namespace to parse the registry and this one isn't working properly

 

Does anyone have any examples of how to do something like this ?  Google has been rather sparce on how to do this.  I would do this in powershell but unfortunetly the remote machines are across multiple domains and authentication can't be scripted in powershell  :facewall:

 

This is the error I cannot get around

[15-Aug-2009 00:25:58] PHP Fatal error:  Call to a member function EnumKey() on a non-object in D:\EXKB\testfiles\wmireg.php on line 25

 

<?php
//initialize the object

$hostname = "machine";
$strUser = "admin";
$strPass = "password";
try {
	$rpc = new COM('WbemScripting.winmgmts:{impersonationLevel=impersonate}');
	//$wshShell = new COM("winmgmts:{impersonationLevel=impersonate}//{$hostname}/root/default:StdRegProv");
	$wmi = $rpc->ConnectServer($hostname, 'Root\default:StdRegProv',$strUser,$strPass);
}
catch(Exception $e) {
	echo "Failure to connect: " . $e;

}

define('HKLM',0x80000002);
$keyPaths = array("SOFTWARE\Microsoft\Exchange","SOFTWARE\Wow6432Node\Microsoft");
$keys = new VARIANT(array());

try {
	foreach($keyPaths as $keyPath) {
		echo "attempting path: " . $keyPath."<br>";
		$wmikey = $wmi->EnumKey(HKLM,$keyPath,&$keys) or die("ERROR");  //THIS IS LINE 25
		echo $wmikey."<br>";
		foreach($keys as $subkey) {
			print_r($subkey);
		}
	}
}
catch(Exception $e) {
	echo $e;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/170358-php-and-querying-remote-registry-in-wmi/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.