如何解决当用户未使用远程桌面登录时,无法运行Powershell.exe并使用Invoke-WmiMethod执行ps1文件
我正在尝试执行远程计算机中的powershell脚本exec.ps1
。我正在使用java库中的winrm4j
代码使用下面的命令。
$execProc = Invoke-WmiMethod -path win32_process -name create -argumentlist 'powershell -file "C:\Users\Administrator\AppData\Local\Temp\powershell_script\exec.ps1"';Write-Output $execProc.ProcessId | Out-File 'C:\Users\pid.txt'
我的exec.ps1文件内容低于
cd 'C:\Users\Administrator\'
& C:\Users\Administrator\AppData\Local\Temp\powershell_script\command.ps1 2> C:\Users\Administrator\AppData\Local\Temp\powershell_script\error.txt 1> C:\Users\Administrator\AppData\Local\Temp\powershell_script\logs.txt
Write-Output $LASTEXITCODE | Out-File 'C:\Users\Administrator\AppData\Local\Temp\powershell_script\status.txt'
command.ps1的内容如下。
. 'C:\Users\Administrator\AppData\Local\Temp\powershell_script\addn.ps1'
Get-Date
并且addn.ps1的内容在下面
$EXECUTION_FOLDER='C:\Users\Administrator\AppData\Local\Temp\powershell_script\'
$SCRIPT_RESPONSE_FILE='C:\Users\Administrator\AppData\Local\Temp\powershell_script\rsp.txt'
只要用户使用远程桌面协议(RDP)登录,它就可以工作。但是,当用户从RDP中注销时,PowerShell进程将永远运行,没有任何结果。
我尝试使用Invoke-CimMethod,但结果相同。
任何线索为什么会这样?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。