2

$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;
}

我有上面的代码来获取本地主机信息。它运行良好。我的问题是,要获取远程机器信息,我应该将用户凭据(用户名、域管理员的密码)放在哪里?

4

2 回答 2

1

您需要创建一个中间WbemScripting.SWbemLocator对象,如下所示:

$loc = new COM( "WbemScripting.SWbemLocator" );
$obj = $loc->ConnectServer( "hostname", "rootcimv2", "user", "password" );
于 2013-05-22T10:12:54.037 回答
0

ini_set('display_errors', 1);

错误报告(~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++;

}

当用户想要从服务器访问 wmi 时,这可能会有所帮助。干杯!!!阿杰·辛格·拉索尔

于 2014-01-30T11:43:45.157 回答