本文介绍了HTA写入< span>从文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文本文件中的数据写入HTA中的.

我正在HTA内运行Powershell脚本,使用VBscript作为输入按钮

Get-TSSession -computername ismeta | where { $_.username -eq 'amis5235'} | format-table windowstationname,username,state,sessionid | out-file C:\windows\temp\PSTerminalServices.txt

我将为大约60台服务器的每个循环使用一个

然后我希望将输出写入HTA中,就像在VB中使用流媒体或在VBscript中堆积字符串一样,

strHTML = strHTML & "Running Process = " & objProcess.Name & " PID = " & objProcess.ProcessID & " Description = " & objProcess.Description & "<br>"

但是似乎应该有一种更简单的方法来实现此目的.

解决方案

我认为这种最小的HTA可以解决您的问题.它运行命令行并读取输出流,每1/10秒一行一行,然后将结果推送到文本区域.您可能想要更改Powershell脚本,以将过程详细信息返回到STDOUT,但是它可能会起作用.

<script language="Javascript">
var E, LineWriteTimerID
function execWithStatus(cmdLine){//Can't run minimized with Exec. Can't capture StdOut/StdErr with Run. 
    E = new ActiveXObject("WScript.Shell").Exec(cmdLine);
    LineWriteTimerID = window.setInterval("writeOutLine()",100);//pause for 100ms
    E.StdIn.Close();//must close input to complete a ps command    
}
function writeOutLine(){
    if(E.StdOut.AtEndOfStream) window.clearTimeout(LineWriteTimerID);
    if(!E.StdErr.AtEndOfStream) txtResults.value += "ERROR: " + E.StdErr.ReadAll() + "\n";
    if(!E.StdOut.AtEndOfStream) txtResults.value += E.StdOut.ReadLine() + "\n";
}
</script>
<textarea id=txtCmd style="width:90%" rows=1>
powershell.exe -noninteractive -command ls c:\windows\system32\drivers\etc\</textarea> 
<button onclick="execWithStatus(txtCmd.value)">Run</button>
<br><textarea id=txtResults style="width:100%" rows=20></textarea> 

将此代码另存为.HTA文件,将txtCmd textarea的内容更改为您的命令行,然后尝试一下.祝你好运!

I am trying to write data from a text file to a in an HTA.

I'm running a powershell script inside of the HTA, using VBscript for the input buttons

Get-TSSession -computername ismeta | where { $_.username -eq 'amis5235'} | format-table windowstationname,username,state,sessionid | out-file C:\windows\temp\PSTerminalServices.txt

I'm going to be using a for each loop for about 60 servers

Then I was hoping to write the output to a within the HTA, kind of like a streamer in VB or stacking a string the VBscript, something like:

strHTML = strHTML & "Running Process = " & objProcess.Name & " PID = " & objProcess.ProcessID & " Description = " & objProcess.Description & "<br>"

but it seems there should be a simpler way to do this.

解决方案

I think this minimal HTA will solve your problem. It runs a command line and reads the output stream, one line every 1/10 second, then pushes the results into a textarea. You may want to alter your Powershell script to return the process details to STDOUT, but it will probably work.

<script language="Javascript">
var E, LineWriteTimerID
function execWithStatus(cmdLine){//Can't run minimized with Exec. Can't capture StdOut/StdErr with Run. 
    E = new ActiveXObject("WScript.Shell").Exec(cmdLine);
    LineWriteTimerID = window.setInterval("writeOutLine()",100);//pause for 100ms
    E.StdIn.Close();//must close input to complete a ps command    
}
function writeOutLine(){
    if(E.StdOut.AtEndOfStream) window.clearTimeout(LineWriteTimerID);
    if(!E.StdErr.AtEndOfStream) txtResults.value += "ERROR: " + E.StdErr.ReadAll() + "\n";
    if(!E.StdOut.AtEndOfStream) txtResults.value += E.StdOut.ReadLine() + "\n";
}
</script>
<textarea id=txtCmd style="width:90%" rows=1>
powershell.exe -noninteractive -command ls c:\windows\system32\drivers\etc\</textarea> 
<button onclick="execWithStatus(txtCmd.value)">Run</button>
<br><textarea id=txtResults style="width:100%" rows=20></textarea> 

Save this code as an .HTA file, change the contents of the txtCmd textarea to be your command line, and give it a try. Good Luck!

这篇关于HTA写入&lt; span&gt;从文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:31