Connecting wmi with php to get DNS records
Posted: Wed Oct 14, 2009 4:27 am
Hi all,
I am trying to make a wmi connection to a machiene and get the DNS record, using the following but it gives me the following error,
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `winmgmts:{impersonationLevel=impersonate}//./root/MicrosoftDNS': ' in C:\Inetpub\wwwroot\reports\process_check.php:3 Stack trace: #0 C:\Inetpub\wwwroot\reports\process_check.php(3): com->com('winmgmts:{imper...') #1 {main} thrown in C:\Inetpub\wwwroot\reports\process_check.php on line 3
I am using the following code,
<? define ( 'CPU_NAME', '.' );
$check = 'explorer.exe'; // the process to check
$obj = new COM ( 'winmgmts:{impersonationLevel=impersonate}//' . CPU_NAME . '/root/cimv2' );
if ( is_object ( $obj ) )
{ $process = $obj->execquery ( "SELECT * FROM Win32_Process WHERE Name = '" . $check . "'" );
if ( $process->count > 0 )
{ echo 'explorer is running';
But the problem is in line three where I am trying to get access to the MicrosoftDNS class to get the DNS reocrds.
Can any one please help out with it? Or reffer any other help full link.
Regards,
Sameer.
I am trying to make a wmi connection to a machiene and get the DNS record, using the following but it gives me the following error,
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `winmgmts:{impersonationLevel=impersonate}//./root/MicrosoftDNS': ' in C:\Inetpub\wwwroot\reports\process_check.php:3 Stack trace: #0 C:\Inetpub\wwwroot\reports\process_check.php(3): com->com('winmgmts:{imper...') #1 {main} thrown in C:\Inetpub\wwwroot\reports\process_check.php on line 3
I am using the following code,
<? define ( 'CPU_NAME', '.' );
$check = 'explorer.exe'; // the process to check
$obj = new COM ( 'winmgmts:{impersonationLevel=impersonate}//' . CPU_NAME . '/root/cimv2' );
if ( is_object ( $obj ) )
{ $process = $obj->execquery ( "SELECT * FROM Win32_Process WHERE Name = '" . $check . "'" );
if ( $process->count > 0 )
{ echo 'explorer is running';
But the problem is in line three where I am trying to get access to the MicrosoftDNS class to get the DNS reocrds.
Can any one please help out with it? Or reffer any other help full link.
Regards,
Sameer.