在HTA中获取PowerShell脚本的输出 [英] Get Output of a PowerShell Script in a HTA
本文介绍了在HTA中获取PowerShell脚本的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从HTML应用程序[HTA]调用Powershell脚本:
I am trying to call a powershell script from HTML Application [HTA] as :
Set WshShell = CreateObject("WScript.Shell")
Set retVal = WshShell.Exec("powershell.exe C:\PS_Scripts\test.ps1")
test.ps1的进程计数刚刚返回
Where the test.ps1 just has the process count returning
return (Get-Process).Count
我想获取此powershell脚本的输出,然后将其存储在本地变量中或显示在HTA上.怎么办呢?
I want to get the output of this powershell script and then store it in a local variable or display on HTA. How can this be done ?
我尝试使用:
retVal.StdIn.Close()
result = retVal.StdOut.ReadAll()
alert(result)
但是打印结果值为空.
请帮助我如何实现这一目标.
Please help me how to achieve this.
推荐答案
这对我有用:
test.ps1:
(Get-Process).Count | Out-File c:\temp\output.txt -Encoding ascii
test.hta:
<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
</head>
<script language="VBScript">
Sub TestSub
Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File test.ps1", 0, true)
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("c:\temp\output.txt", 1)
text = file.ReadAll
alert(text)
file.Close
End Sub
</script>
<body>
<input type="button" value="Run Script" name="run_button" onClick="TestSub"><p>
</body>
这篇关于在HTA中获取PowerShell脚本的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文