本文整理汇总了PHP中COM::ConnectServer方法的典型用法代码示例。如果您正苦于以下问题:PHP COM::ConnectServer方法的具体用法?PHP COM::ConnectServer怎么用?PHP COM::ConnectServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COM
的用法示例。
在下文中一共展示了COM::ConnectServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
if (PSI_OS == 'WINNT') {
$_wmi = null;
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI');
} else {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
}
}
示例2: sysinfo
function sysinfo()
{
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
// initialize the wmi object
$objLocator = new COM("WbemScripting.SWbemLocator");
if ($strHostname == "") {
$this->wmi = $objLocator->ConnectServer();
} else {
$this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "{$strHostname}\$strUser", $strPassword);
}
}
示例3: __construct
/**
* Create a new wmi instance.
*
* @param string $host Host name or IP address to connect to
* @param string $username Local host user with rights to query WMI; normally a local admin
* @param string $password Password of local user account
* @return void New wmi object
*/
public function __construct($host = null, $username = null, $password = null)
{
$wmiLocator = new COM('WbemScripting.SWbemLocator');
try {
$this->connection = $wmiLocator->ConnectServer($host, 'root\\CIMV2', $username, $password);
$this->connection->Security_->impersonationLevel = 3;
} catch (Exception $e) {
// -2147352567 means that we're unable to connect to the local host with a username and password.
// Attempt connection again passing null values for username and password.
if ($e->getCode() == '-2147352567') {
$this->connection = $wmiLocator->ConnectServer($host, 'root\\CIMV2', null, null);
$this->connection->Security_->impersonationLevel = 3;
}
}
}
示例4: __construct
/**
* build the global Error object and create the WMI connection
*/
public function __construct()
{
parent::__construct();
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$this->_wmi = $objLocator->ConnectServer();
} else {
$this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
}
$this->_getCodeSet();
}
示例5: connect
/**
* Connects to a registry and returns a registry instance.
*
* @param string $host The host name or IP address of the computer whose registry to connect
* to. Defaults to the local computer.
* @param string $username The user name to use to access the registry.
* @param string $password The password to use to access the registry.
*
* @return Registry
*/
public static function connect($host = '.', $username = null, $password = null)
{
// create a WMI connection
$swbemLocator = new \COM('WbemScripting.SWbemLocator', null, CP_UTF8);
$swbemService = $swbemLocator->ConnectServer($host, 'root\\default', $username, $password);
$swbemService->Security_->ImpersonationLevel = 3;
// initialize registry provider
$handle = new RegistryHandle($swbemService->Get('StdRegProv'));
return new static($handle);
}
示例6: __construct
/**
* read the data into an internal array and also call the parent constructor
*
* @param String $enc target encoding
*/
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) {
case 'command':
if (PSI_OS == 'WINNT') {
try {
$objLocator = new COM('WbemScripting.SWbemLocator');
$wmi = $objLocator->ConnectServer('', 'root\\CIMv2');
$process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'ProcessId'));
foreach ($process_wmi as $process) {
$this->_filecontent[] = array(strtolower(trim($process['Caption'])), trim($process['ProcessId']));
}
} catch (Exception $e) {
}
} else {
if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) {
if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) {
$processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES);
} else {
$processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES);
}
if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX === true) {
foreach ($processes as $process) {
CommonFunctions::executeProgram("pgrep", "-n -x " . $process, $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_filecontent[] = array($process, $buffer);
}
}
} else {
foreach ($processes as $process) {
CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_filecontent[] = array($process, $buffer);
}
}
}
}
}
break;
case 'data':
CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
$processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($processes as $process) {
$ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
if (count($ps) == 2) {
$this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
}
}
break;
default:
$this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini");
break;
}
}
示例7: __construct
/**
* read the data into an internal array and also call the parent constructor
*
* @param String $enc encoding
*/
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
case 'command':
if (PSI_OS == 'WINNT') {
try {
$objLocator = new COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer();
$os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
foreach ($os_wmi as $os) {
$memtotal = $os->TotalVisibleMemorySize * 1024;
}
$process_wmi = $wmi->InstancesOf('Win32_Process');
foreach ($process_wmi as $process) {
if (strlen(trim($process->CommandLine)) > 0) {
$ps = trim($process->CommandLine);
} else {
$ps = trim($process->Caption);
}
if (trim($process->ProcessId) != 0) {
$memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
//ParentProcessId
//Unique identifier of the process that creates a process. Process identifier numbers are reused, so they
//only identify a process for the lifetime of that process. It is possible that the process identified by
//ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also
//possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can
//use the CreationDate property to determine whether the specified parent was created after the process
//represented by this Win32_Process instance was created.
//=> subtrees of processes may be missing (WHAT TODO?!?)
$this->_filecontent[] = trim($process->ProcessId) . " " . trim($process->ParentProcessId) . " " . $memusage . " " . $ps;
}
}
} catch (Exception $e) {
}
} else {
CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG);
}
break;
case 'data':
CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer);
break;
default:
$this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
break;
}
if (PSI_OS != 'WINNT') {
if (trim($buffer) != "") {
$this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
unset($this->_filecontent[0]);
} else {
$this->_filecontent = array();
}
}
}
示例8: __construct
/**
* build the global Error object and create the WMI connection
*/
public function __construct()
{
parent::__construct();
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$this->_wmi = $objLocator->ConnectServer();
} else {
$this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
}
$this->_getCodeSet();
}
示例9: __construct
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
$_wmi = null;
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor');
} else {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor', $strHostname . '\\' . $strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
}
}
示例10: __construct
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
$_wmi = null;
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$_wmi = $objLocator->ConnectServer('', 'root\\OpenHardwareMonitor');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
}
}
示例11: __construct
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
if (PSI_OS == 'WINNT') {
$_wmi = null;
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$_wmi = $objLocator->ConnectServer('', 'root\\WMI');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
}
}
示例12: __construct
/**
* read the data into an internal array and also call the parent constructor
*
* @param String $enc target encoding
*/
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (PSI_PLUGIN_PSSTATUS_ACCESS) {
case 'command':
if (PHP_OS == 'WINNT') {
$objLocator = new COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer();
$process_wmi = $wmi->InstancesOf('Win32_Process');
foreach ($process_wmi as $process) {
$this->_filecontent[] = array(trim($process->Caption), trim($process->ProcessId));
}
} else {
$processes = preg_split("/([\\s]+)?,([\\s]+)?/", PSI_PLUGIN_PSSTATUS_PROCESSES, -1, PREG_SPLIT_NO_EMPTY);
foreach ($processes as $process) {
CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
if (strlen(trim($buffer)) > 0) {
$this->_filecontent[] = array($process, trim($buffer));
}
}
}
break;
case 'data':
CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
$processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($processes as $process) {
$ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
if (count($ps) == 2) {
$this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
}
}
break;
default:
$this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in psstatus.config.php");
break;
}
}
示例13: readEventLogs
public function readEventLogs($host, $domain, $service)
{
// Get credentials.
$account = $this->options['account'];
$password = $this->options['password'];
$WbemLocator = new \COM("WbemScripting.SWbemLocator");
$WbemServices = $WbemLocator->ConnectServer($host, 'root\\cimv2', $account, $password);
$WbemServices->Security_->ImpersonationLevel = 3;
$events = $WbemServices->ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and type = 'Error' and TimeWritten > '2016'");
foreach ($events as $event) {
echo $event->category . '<br>';
echo $event->computerName . '<br>';
echo $event->eventCode . '<br>';
echo $event->message . '<br>';
echo $event->recordNumber . '<br>';
echo $event->sourceName . '<br>';
echo $event->timeWritten . '<br>';
echo $event->type . '<br>';
echo $event->user . '<br>';
echo '<hr>';
}
die;
/** Wscript.Echo "Category: " & objEvent.Category & VBNewLine _
& "Computer Name: " & objEvent.ComputerName & VBNewLine _
& "Event Code: " & objEvent.EventCode & VBNewLine _
& "Message: " & objEvent.Message & VBNewLine _
& "Record Number: " & objEvent.RecordNumber & VBNewLine _
& "Source Name: " & objEvent.SourceName & VBNewLine _
& "Time Written: " & objEvent.TimeWritten & VBNewLine _
& "Event Type: " & objEvent.Type & VBNewLine _
& "User: " & objEvent.User
Next
*
*/
die('ok');
}
示例14: sys_windows
function sys_windows()
{
if (PHP_VERSION >= 5) {
$objLocator = new COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer();
$prop = $wmi->get("Win32_PnPEntity");
} else {
return false;
}
//CPU
$cpuinfo = GetWMI($wmi, "Win32_Processor", array("Name", "L2CacheSize", "NumberOfCores"));
$res['cpu']['num'] = $cpuinfo[0]['NumberOfCores'];
if (null == $res['cpu']['num']) {
$res['cpu']['num'] = 1;
}
/*
for ($i=0;$i<$res['cpu']['num'];$i++)
{
$res['cpu']['model'] .= $cpuinfo[0]['Name']."<br />";
$res['cpu']['cache'] .= $cpuinfo[0]['L2CacheSize']."<br />";
}*/
$cpuinfo[0]['L2CacheSize'] = ' (' . $cpuinfo[0]['L2CacheSize'] . ')';
if ($res['cpu']['num'] == 1) {
$x1 = '';
} else {
$x1 = ' ×' . $res['cpu']['num'];
}
$res['cpu']['model'] = $cpuinfo[0]['Name'] . $cpuinfo[0]['L2CacheSize'] . $x1;
// SYSINFO
$sysinfo = GetWMI($wmi, "Win32_OperatingSystem", array('LastBootUpTime', 'TotalVisibleMemorySize', 'FreePhysicalMemory', 'Caption', 'CSDVersion', 'SerialNumber', 'InstallDate'));
$sysinfo[0]['Caption'] = iconv('GBK', 'UTF-8', $sysinfo[0]['Caption']);
$sysinfo[0]['CSDVersion'] = iconv('GBK', 'UTF-8', $sysinfo[0]['CSDVersion']);
$res['win_n'] = $sysinfo[0]['Caption'] . " " . $sysinfo[0]['CSDVersion'] . " 序列号:{$sysinfo[0]['SerialNumber']} 于" . date('Y年m月d日H:i:s', strtotime(substr($sysinfo[0]['InstallDate'], 0, 14))) . "安装";
//UPTIME
$res['uptime'] = $sysinfo[0]['LastBootUpTime'];
$sys_ticks = 3600 * 8 + time() - strtotime(substr($res['uptime'], 0, 14));
$min = $sys_ticks / 60;
$hours = $min / 60;
$days = floor($hours / 24);
$hours = floor($hours - $days * 24);
$min = floor($min - $days * 60 * 24 - $hours * 60);
if ($days !== 0) {
$res['uptime'] = $days . "天";
}
if ($hours !== 0) {
$res['uptime'] .= $hours . "小时";
}
$res['uptime'] .= $min . "分钟";
//MEMORY
$res['memTotal'] = round($sysinfo[0]['TotalVisibleMemorySize'] / 1024, 2);
$res['memFree'] = round($sysinfo[0]['FreePhysicalMemory'] / 1024, 2);
$res['memUsed'] = $res['memTotal'] - $res['memFree'];
//上面两行已经除以1024,这行不用再除了
$res['memPercent'] = round($res['memUsed'] / $res['memTotal'] * 100, 2);
$swapinfo = GetWMI($wmi, "Win32_PageFileUsage", array('AllocatedBaseSize', 'CurrentUsage'));
// LoadPercentage
$loadinfo = GetWMI($wmi, "Win32_Processor", array("LoadPercentage"));
$res['loadAvg'] = $loadinfo[0]['LoadPercentage'];
return $res;
}
示例15: AdapterAction
public function AdapterAction()
{
// Get credentials from config.
$config = $this->getServiceLocator()->get('Config')['cobalt'];
$account = $config['account'];
$password = $config['password'];
$host = $config['test_host'];
// hostname or IP address
$WbemLocator = new \COM("WbemScripting.SWbemLocator");
$WbemServices = $WbemLocator->ConnectServer($host, 'root\\cimv2', $account, $password);
$WbemServices->Security_->ImpersonationLevel = 3;
$adapter = $WbemServices->ExecQuery("Select * from Win32_NetworkAdapterConfiguration");
return array('adapter' => $adapter);
}