不同,我有以下的代码来实现:Exec在PowerShell会返回直接运行PowerShell的
$ServiceName = $_GET['Service'];
exec("echo . | powershell.exe -c get-service ".$ServiceName,$OutputArray);
echo "<pre>";
print_r($OutputArray);
echo "</pre>";
我$ServiceName
通过GET分配,但对于这个例子。
$_GET['Service'] = "WinRM"; // Service Name is assigned to WinRM For *Windows Remote Management*
现在。当我运行该脚本,我得到以下几点:
Array
(
[0] => Get-Service : Cannot find any service with service name 'WinRM'.
[1] => At line:1 char:12
[2] => + get-service <<<< WinRM
[3] => + CategoryInfo : ObjectNotFound: (WinRM:String) [Get-Service], Se
[4] => rviceCommandException
[5] => + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
[6] => Commands.GetServiceCommand
[7] =>
)
现在,当我打开PowerShell中并运行以下命令:
get-service WinRM
我得到与返回以下输出:
PS C:\Users\Administrator> get-service WinRM
Status Name DisplayName
------ ---- -----------
Running WinRM Windows Remote Management (WS-Manag...
这发生在其他一些服务名称上,例如:
$Array = array(
"DNSServer" => "DNS",
"DHCP Client" => "DHCP",
"Web Server" => "IISADMIN",
"Windows Remote Management" => "WinRM"
);
这在失败中DNS, IISADMIN, WinRM
这个例子......但同样,从PS我得到与返回:
PS C:\Users\Administrator> get-service DNS,IISADMIN,WinRM
Status Name DisplayName
------ ---- -----------
Running DNS DNS Server
Running IISADMIN IIS Admin Service
Running WinRM Windows Remote Management (WS-Manag...
我的总的问题是如何提高从PowerShell中的报告,以PHP和得到准确两端的结果?
这取决于服务名称取决于某些时间。例如: -
$ServiceName = "DHCP";
这就是为什么在错误调试不包含此名称。我得到与返回:
Array
(
[0] =>
[1] => Status Name DisplayName
[2] => ------ ---- -----------
[3] => Running DHCP DHCP Client
[4] =>
[5] =>
)
这正是我所期待的。
对不起,我会在一分钟内检查一下,看看它是否有效 – 2013-05-01 15:46:41
运行第一个块后,它返回空白,第二个也是如此。如果我运行'win32_service'库在PHP中,我得到错误5这是一个权限问题,我不必解决 – 2013-05-01 22:23:10
对不起,不知道为什么这不适合你。这两种方法都能在我的win7机器上正常工作。 – Gordon 2013-05-02 09:06:36