我想以普通用户身份在Windows 7上运行PowerShell脚本.每当我尝试时,我都会收到以下错误:
File C:\Users\danv\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because the
execution of scripts is disabled on this system. Please see "get-help about_signing" for
more details.
At line:1 char:2
+ . <<<< 'C:\Users\danv\Documents\WindowsPowerShell\profile.ps1'
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Run Code Online (Sandbox Code Playgroud)
尝试解决via Set-ExecutionPolicy Unrestricted失败:
PS C:\Users\danv> Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy : Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell'
is denied.
At line:1 char:20
+ Set-ExecutionPolicy <<<< Unrestricted
+ CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
Run Code Online (Sandbox Code Playgroud)
我可以Set-ExecutionPolicy …
在网络打印机上打印PDF文档,同时传递颜色,方向,双面等内容的打印参数.
我登录了其中一台打印机(192.168.0.10 - 理光MP C5503 [如果你真的必须知道])并添加了FTP访问权限
在Windows工作中使用命令提示符打印文档!
> ftp 192.168.0.10
> User (192.168.0.10:(none)): username
> Password: password
> put path\to\file.pdf filetype=PDF
> bye
Run Code Online (Sandbox Code Playgroud)
尝试1使用PHP的exec()函数
我已经尝试了很多方法使exec工作,但无济于事.我无法使用PHP的exec函数运行多行命令(理想情况下,运行以下命令).在exec()中运行以下命令时,我无法连接到FTP,因为必须在上一行运行后执行每一行.我在网上找不到任何内容(多次谷歌搜索没有结果[除了如何从cmd回显多个输出行 - 不是如何连续插入多个cmd行])
> ftp 192.168.0.10
> User (192.168.0.10:(none)): username
> Password: password
> put path\to\test.pdf filetype=PDF
> bye
Run Code Online (Sandbox Code Playgroud)
尝试2使用PHP的exec()函数 …
我正在尝试运行一个运行PowerShell脚本的简单PHP,如果我使用此代码,我会在命令窗口中获得结果,但我在浏览器中得到一个空数组:
<?php
exec("powershell C:\\Inetpub\\wwwroot\\my_shell.ps1 < NUL", $output);
echo "<pre>";
print_r($output);
echo "</pre>";
?>
Run Code Online (Sandbox Code Playgroud)
我相信NUL将丢弃输出,但是它在浏览器中发现了它[这个Fourm] [1]
如果我使用这个代码,没有NUL,我会在命令窗口中得到结果,但如果我在浏览器中运行脚本将继续加载,它永远不会给我任何结果:
exec("powershell C:\\Inetpub\\wwwroot\\emsrDev\\manual_shell.ps1", $output);
Run Code Online (Sandbox Code Playgroud)
如果我这样做,结果相同:
$output = shell_exec("powershell C:\\Inetpub\\wwwroot\\emsrDev\\manual_shell.ps1");
Run Code Online (Sandbox Code Playgroud)
如果我独立运行powershell脚本运行正常:
$cmd = "cmd.exe";
&$cmd "/C echo update tasks set last='manual' where id='8'; | sqlplus vvv/www@xxx";
Run Code Online (Sandbox Code Playgroud)
所以我需要在浏览器中执行此操作并获取输出.