将蝙蝠文件执行到远程客户端



我正在尝试打开一个 HTML 文件到客户端"ClientA",该文件通过执行下面的 powershell 命令远程复制到文件夹"C:\1.html"

$Username = 'username'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList                 
$Username,$pass

Invoke-Command -ComputerName ClientA -ScriptBlock { Invoke-Expression - 
Command:"cmd.exe /c 'C:1.bat'" } -credential $Cred

"1.bat"批次具有波纹管线

START iexplore -k "C:1.html"

我在执行时没有收到错误...但是文件没有向远程客户端打开! 有什么想法吗?

谢谢!

脚本是正确的,内部没有错误,但可能它没有做你认为它做的事情。

调用远程管理会话时,Powershell 正在使用自己的会话在远程计算机上工作,该会话没有桌面交互,因此您不会从最终用户可能保持登录状态的会话在主 shell 中启动 Internet Explorer。

要仔细检查您的代码是否正常工作,您可以在 1 中使用以下内容.bat

START iexplore -k "C:1.html"
echo %PATH% >> c:patlog.txt
echo "DONE" >> c:1_log.txt

您将看到来自路径和控制台上最终"完成"的回声,以确认蝙蝠已执行。

无论如何,Internet Explorer 无论如何都不会显示在任何已记录的用户会话中,因为在此页面上也进行了讨论:

https://serverfault.com/questions/690852/use-powershell-to-start-a-gui-program-on-a-remote-machine

最新更新