Get Output of a PowerShell Script in a HTA

前端 未结 3 1504
无人及你
无人及你 2020-12-10 07:25

I am trying to call a powershell script from HTML Application [HTA] as :

Set WshShell = CreateObject(\"WScript.Shell\")

Set retVal = WshShell.Exec(\"powersh         


        
3条回答
  •  情深已故
    2020-12-10 07:44

    You can use the Exec method of WScript.Shell to avoid intermediate files. Unfortunately it opens a new window when it runs, but the code is much cleaner and gives you access to the StdOut and StdErr streams. Paste this into an .HTA file (with header and body if desired) to test:

    
     
    
    

    Part of your problem may have been that Exec isn't blocking waiting for StdOut to start filling up. Adding the timer corrected that issue for me.

提交回复
热议问题