Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (128 sloc) 4.42 KB
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTATest"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
const cSharpCodeFileName = ".\powershell.cs"
const commandsOutputFile = ".\powershell.txt"
const cSharpExeFileName = ".\ps.exe"
Public globalShellObj
Public globalExecObj
Function writeToFile(outFile, contents)
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write contents
objFile.Close
end function
Function compileCSharpCodeFromFile(filename, outFile)
Set compileShell = CreateObject("WScript.Shell")
exitCode = compileShell.run("c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /r:c:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll /unsafe /platform:anycpu /out:" & outFile & " " & filename, visible = false, wait = true)
end function
Function writeOutput(text)
Set div = document.getElementById("output")
div.innerText = div.innerText & text
document.getElementById("right").scrollTop = document.getElementById("right").scrollHeight
end function
sub init
writeToFile cSharpCodeFileName, document.getElementById("cscode").innerText
compileCSharpCodeFromFile cSharpCodeFileName, cSharpExeFileName
end sub
sub checkOutput
std = globalExecObj.stdout.readall()
errr = globalExecObj.StdErr.readall
if InStr(std, "startasdfasdfasdf") then
std = Mid(std ,instr(std, "startasdfasdfasdf")+ len("startasdfasdfasdf"), instr(std, "The uninstall has completed.")- instr(std, "startasdfasdfasdf") -len("startasdfasdfasdf"))
end if
writeOutput vbCrLf & std
writeOutput errr
end Sub
Sub HandleInput
writeToFile commandsOutputFile, BasicTextBox.value
Set globalShellObj = CreateObject("WScript.Shell")
Set globalExecObj = globalShellObj.exec("C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=True /u .\ps.exe")
writeOutput vbCrLf & "> " & BasicTextBox.value
BasicTextbox.value = ""
checkOutput
End Sub
sub runInteractive
writeToFile commandsOutputFile, BasicTextBox.value
Set temp1 = CreateObject("WScript.Shell")
temp2 = temp1.run("C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=True /u .\ps.exe", 1, 0)
end sub
</SCRIPT>
<body>
<div id="left" style="float:left;height=100%;">
<div>
<textarea rows="4" cols="50" id="prompt" type="text" name="BasicTextbox" size="30"></textarea>
</div>
<div>
<input id=runbutton type="button" value="Run and grab stdin/out (non-interactive blocking)" name="run_button" onClick="HandleInput">
<br>
<input id=runbutton type="button" value="Run without grabbing stdin/out (interactive non-blocking)" name="run_button" onClick="runInteractive">
</div>
</div>
<p id="cscode" style="display:none">using System;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.Management.Automation.Runspaces;
public class Program
{
public static void Main()
{
}
}
[System.ComponentModel.RunInstaller(true)]
public class Sample : System.Configuration.Install.Installer
{
public override void Uninstall(System.Collections.IDictionary savedState)
{
Mycode.Exec();
}
}
public class Mycode
{
public static void Exec()
{
string command = System.IO.File.ReadAllText(@".\powershell.txt");
RunspaceConfiguration rspacecfg = RunspaceConfiguration.Create();
Runspace rspace = RunspaceFactory.CreateRunspace(rspacecfg);
rspace.Open();
Pipeline pipeline = rspace.CreatePipeline();
pipeline.Commands.AddScript(command);
pipeline.InvokeAsync();
while(pipeline.PipelineStateInfo.State == PipelineState.Running || pipeline.PipelineStateInfo.State == PipelineState.Stopping) {
System.Threading.Thread.Sleep(50);
}
Console.WriteLine("startasdfasdfasdf");
foreach (object item in pipeline.Output.ReadToEnd())
{
if(item != null) {
Console.WriteLine(item.ToString());
}
}
foreach (object item in pipeline.Error.ReadToEnd())
{
if(item != null) {
Console.WriteLine(item.ToString());
}
}
}
}
</p>
<div id="right" style="background-color:black;font-family:monospace;color:white;height:100%;max-height:100%;overflow:scroll;">
<p id="output">get ready...</p>
</div>
<script>
document.getElementById("prompt").focus()
</script>
<SCRIPT LANGUAGE="VBScript">
init
</SCRIPT>
</body>
</html>