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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.