You need to create an intermediary WbemScripting.SWbemLocator object, something like this:
$loc = new COM( "WbemScripting.SWbemLocator" );
$obj = $loc->ConnectServer( "hostname", "rootcimv2", "user", "password" );
質問
$obj = new COM ( 'winmgmts://localhost/root/CIMV2' );
$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");
foreach ( $wmi_computersystem as $wmi_call )
{
$model = $wmi_call->Model;
}
foreach ( $wmi_bios as $wmi_call )
{
$serial = $wmi_call->SerialNumber;
$bios_version = $wmi_call->SMBIOSBIOSVersion;
}
i have above code to get the localhost information.and it works well. My question is, To get the remote machine info,where should i put user credentials(username,password of domain administrator)?
解決
You need to create an intermediary WbemScripting.SWbemLocator object, something like this:
$loc = new COM( "WbemScripting.SWbemLocator" );
$obj = $loc->ConnectServer( "hostname", "rootcimv2", "user", "password" );
他のヒント
ini_set('display_errors', 1);
error_reporting(~0);
$objLocator = new COM ("WbemScripting.SWbemLocator");
$objService = $objLocator->ConnectServer( "hostname", "rootcimv2", "user", "password" );
$objService->Security_->ImpersonationLevel = 3;
$values =$objService->execquery("SELECT * FROM Win32_OperatingSystem");
//$value = (array)$values;
$i = 0;
foreach ( $values as $wmi_call ) {
echo $caption = $wmi_call->CAPTION;
echo $csname = $wmi_call->CSNAME;
echo $CurrentTimeZone = $wmi_call->CurrentTimeZone;
echo "<br>";
echo $i;
$i++;
}
This might help when user want to access wmi from server. Cheers!!! Ajay Singh Rathore