Hello everybody, well i've been going at this for days and i'm about to pull all my hair out so if anybody could help me at all that would be great.

So the goal is to use WMI to connect to remote machines to pull the event logs from them.


$host = "a_remote_pc";
$user = "administrator_user";
$pass = "password";

$wmiLocator = new COM("WbemScripting.SWbemLocator");
$objWMIService = $wmiLocator->ConnectServer($host, "root\cimv2", $user, $pass);
$oQuery = $objWMIService->ExecQuery("Select * from Win32_NTLogEvent");

and then here is all the stuff to display it, which is not important right now.

--------------------------------------------------------------------------
so here is the error that i get:

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> SWbemLocator<br/><b>Description:</b> Access is denied. ' in c:\Inetpub\wwwroot\wmi\test.php:7 Stack trace: #0 c:\Inetpub\wwwroot\wmi\test.php(7): com->ConnectServer('10.xxx.xxx.xxx', 'root\cimv2', 'administrator_user, 'password') #1 {main} thrown in c:\Inetpub\wwwroot\wmi\test.php on line 7


Line 7 that i refers to is: $objWMIService = $wmiLocator->ConnectServer($host, "root\cimv2", $user, $pass);

and well i'm stuck here.

Also, i created a perl script and it works using perl.... but i need it to work with PHP.

Any help would be appreciated.

Thanks in advance.

    you have to check you
    connecting variables: $host, "root\cimv2", $user, $pass
    because you cant connect with those values you submit

      The username, passoword exist on the remote pc and the root/cimv2 is the proper directory. But is the script correct? Is that written properlly? or do i need to do somehting else?

      Thanks for the help

        Still it says:
        Access is denied.
        com->ConnectServer('10.xxx.xxx.xxx', 'root\cimv2', 'administrator_user, 'password')

        I would check if there is some other way to write the path:
        'root\cimv2'
        Also if maybe you need to tell port number:
        '10.xxx.xxx.xxx:56'

          so in case anybody's interested i got it to work by using:

          $objWMIService = $wmiLocator->ConnectServer($host, "root\cimv2", "$host\$user", $pass);
          

          Thanks for the help halojoy

            Write a Reply...