Solved

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

Posted on 2011-09-28
6
891 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 110

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
Technology Partners: 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!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 35
SQL querys that gives me from one table into another. 2 38
PHP mail() function not working... 8 32
Php logic to add to date card 9 38
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

740 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