我试图从HTML应用程序[HTA]调用powershell脚本:
Set WshShell = CreateObject("WScript.Shell")
Set retVal = WshShell.Exec("powershell.exe C:\PS_Scripts\test.ps1")
Run Code Online (Sandbox Code Playgroud)
test.ps1只返回进程计数
return (Get-Process).Count
Run Code Online (Sandbox Code Playgroud)
我想获取此powershell脚本的输出,然后将其存储在本地变量中或显示在HTA上.如何才能做到这一点 ?
我试过用:
retVal.StdIn.Close()
result = retVal.StdOut.ReadAll()
alert(result)
Run Code Online (Sandbox Code Playgroud)
但打印结果值为null.
请帮我解决这个问题.
这对我有用:
测试.ps1:
(Get-Process).Count | Out-File c:\temp\output.txt -Encoding ascii
Run Code Online (Sandbox Code Playgroud)
测试.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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5498 次 |
| 最近记录: |