?
Solved

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

Posted on 2011-09-28
6
Medium Priority
?
922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 111

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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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