[英]Change Default Printer paper size with PHP powershell script
I am trying to change Default printer paper size from PHP我正在尝试从 PHP 更改默认打印机纸张大小
Index.php索引.php
<?php
$printer = Shell_Exec ('powershell.exe -executionpolicy bypass -NoProfile -Command "(Get-WmiObject win32_printer | Where-Object Default -eq $True).Name"');
$printer = substr($printer, 0, -1);
$printer = '"' . $printer . '"';
$cmd = ('powershell.exe -executionpolicy bypass -NoProfile -Command ../A5.ps1 ' .$printer);
echo shell_exec($cmd);
?>
A5.ps1 A5.ps1
$printer=$args[0]
Set-PrintConfiguration -PrinterName $printer -PaperSize A5
Error错误
Set-PrintConfiguration : The specified printer was not found. At C:\Users\t4taa\Desktop\phpdesktop\A5.ps1:2 char:1 + Set-PrintConfiguration -PrinterName $printer -PaperSize A5 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration) [Set-PrintCo nfiguration], CimException + FullyQualifiedErrorId : HRESULT 0x80070709,Set-PrintConfiguration
When I run script file from PowerShell works fine but from PHP it's refuse to take printer name or miss double quotes, how to resolve this problem.当我从 PowerShell 运行脚本文件时工作正常,但从 PHP 运行它拒绝使用打印机名称或错过双引号,如何解决此问题。
Why not change the A5.ps1
into为什么不把A5.ps1
改成
$printer = (Get-WmiObject win32_Printer | Where-Object { $_.Default -eq $true }).Name
Set-PrintConfiguration -PrinterName $printer -PaperSize A5
to have powershell figure out the default printer name AND set the papersize.让 powershell 找出默认打印机名称并设置纸张大小。
That way you can do in the index.php
:这样你就可以在index.php
中做:
<?php
$cmd = ('powershell.exe -ExecutionPolicy Bypass -NoProfile -File ../A5.ps1');
echo shell_exec($cmd);
?>
Use -File
instead of -Command
使用-File
而不是-Command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.