Solved

Trying to use username and password for WMI look up in PHP code

Posted on 2011-09-28
6
862 Views
Last Modified: 2012-05-12
I am trying to add a username and password to my WMI lookup in my PHP page, can anyone help me with this? Thanks
<?php
			$displayasset = $row['asset'];
			$user = "username";
			$pass = "password";
			
    //$obj = new COM ( 'winmgmts://'. $displayasset .'/root/CIMV2' );
	$wmiLocator = new COM("WbemScripting.SWbemLocator");
	$obj = $wmiLocator->ConnectServer($displayasset, "root\cimv2", "$displayasset\$user", $pass);
	
   // $fso = new COM ( "Scripting.FileSystemObject" );   
    $wmi_computersystem    =    $obj->ExecQuery("Select * from Win32_ComputerSystem");
    $wmi_bios              =    $obj->ExecQuery("Select * from Win32_BIOS");
    $processor             =    $obj->ExecQuery("Select * from Win32_Processor");
    $PhysicalMemory        =    $obj->ExecQuery("Select * from Win32_PhysicalMemory");
    $BaseBoard             =    $obj->ExecQuery("Select * from Win32_BaseBoard"); 
    $LogicalDisk           =    $obj->ExecQuery("SELECT * From Win32_LogicalDisk WHERE DeviceID='C:'");
    $software			   =	$obj->ExecQuery("SELECT * From Win32_Product");
	
    foreach ( $wmi_computersystem as $wmi_call )
    {
        $model = $wmi_call->Model;
		$username = $wmi_call->UserName;
    }

    foreach ( $wmi_bios as $wmi_call )
    {
        $serial = $wmi_call->SerialNumber;
        $bios_version = $wmi_call->SMBIOSBIOSVersion;
    }
	

    foreach ( $processor as $wmi_processor )
    {
        $procname = $wmi_processor->Name;
    }
    foreach ( $PhysicalMemory as $wmi_PhysicalMemory )
    {
        $Capacity = $wmi_PhysicalMemory->Capacity;
		$Capacity = $Capacity /1024/1024+1 . " MB";;
    }

    foreach ( $BaseBoard as $wmi_BaseBoard )
    {
        $SerialNumber = $wmi_BaseBoard->SerialNumber;

    }
    foreach ( $LogicalDisk as $wmi_LogicalDisk )
    {
        $size = $wmi_LogicalDisk->Size;
		$size = $size /1024/1024/1024+1 . " GB";
        $freespace = $wmi_LogicalDisk->FreeSpace;
		$freespace = $freespace /1024/1024/1024+1 . " GB";

    }


    echo "Bios version   : ".$bios_version."<br/>
          Serial number of bios  : ".$serial."<br/>
          Hardware Model : ".$model."<br/>
		  Username : ".$username."<br/>
          Processor : ".$procname."<br/>
          Total Ram : ".$Capacity."<br/>
          Total Disk : ".$size."<br>
		  Free Space : ".$freespace."<br>
		  <br>
		  <b>Software:</b>
		  <br>
          ";
	foreach ( $software as $wmi_software )
	{
		$softwarelist = $wmi_software->Name;
		echo $softwarelist . "<br>";
	}
?>

Open in new window

0
Comment
Question by:maximus81
  • 3
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36718769
Do you mean that you want to add an authentication step to password protect your script?
0
 

Author Comment

by:maximus81
ID: 36718778
The issue I am having is when I search for a computer the script runs and it comes back as access denied.
0
 

Accepted Solution

by:
maximus81 earned 0 total points
ID: 36718860
I figured it out:

                  $host = $row['asset'];
                  $user = "domain\administrator";
                  $pass = "pass";
                  
      $wmiLocator = new COM('WbemScripting.SWbemLocator');
      $obj = $wmiLocator->ConnectServer($host, 'root\cimv2', $user, $pass);
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Closing Comment

by:maximus81
ID: 36902265
I figured it out.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36718878
Try this:

   $displayasset = $row['asset'];
   $user = "username";
   $pass = "password";

   $wmiLocator = new COM('WbemScripting.winmgmts:{impersonationLevel=impersonate}');
   $obj = $wmiLocator->ConnectServer($displayasset, "root\cimv2", "$displayasset\$user", $pass);
//or
   $obj = $wmiLocator->ConnectServer($displayasset, "root\cimv2", $user, $pass);

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36718880
oh, too late.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now