Discussion:
HTA / VBScript window CMD output help required
(too old to reply)
firebladeboy
2008-03-17 12:28:02 UTC
Permalink
Hi,

While deploying machines via WinPE 2.0 I'm using imagex.exe cmd to deploy an
image to a pc & I need see imagex progress (so I can't just hide the CMD
window.)

Basically what I'm trying to do is create a nicer UI so I don't have to show
the cmd window itself.. just the output it's giving, so far I have a hta that
will display the output of the cmd window but it will only show this once the
cmd is finished. I think I somehow need to create a loop to view the
contents of the cmd output while it's still running and refresh the hta every
few seconds.. maybe I need to output a temp file and refresh the hta from
that while cmd is still running?

I'm aiming to use this to redirect the output of any cmd window and maybe
call it as a function whenever exe's are being run (file copy / directory
listing / defrag etc).
here is my code so far:

===================
CMDout.hta
===================

<html>
<head><title>CMDOut</title>
<HTA:APPLICATION ID="oHTA";
APPLICATIONNAME="CMDOut";
BORDER="thin";
BORDERSTYLE="normal";
SINGLEINSTANCE="no";
</head><body bgcolor="#E8E8E8" >
<font size=2 face="Century Gothic, Tahoma, Arial" color="black">
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub Window_Onload

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From
Win32_DesktopMonitor")
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
intLeft = (intHorizontal - 640) / 2
intTop = (intVertical - 480) / 2
window.resizeTo 640,480
window.moveTo intLeft, intTop


cmdarg="%comspec% /c ipconfig.exe "
set objExCmd = objShell.Exec(cmdarg)
strOut=objExCmd.StdOut.ReadAll
Set regEx = New RegExp
regEx.Pattern = "[\f\n\r\v]+"
regEx.Global = True
regEx.Multiline = True
strOut = regEx.Replace(strOut, "<br>")
CMDOut.innerHTML= strOut

end sub
//-->
</script>

<div id=CMDOut></div>


================

any assistance would be greatly appreciated!

Thanks
m***@newsgroup.nospam
2008-03-19 11:22:16 UTC
Permalink
Hi Firebladeboy,

I investigated a lot on this one year ago. I also opened a case with
Microsoft. IMAGEX has a /scroll option that should do what you need, the
problem is that this option doesn't work at all. Microsoft recognized that
this is a BUG in imagex and would be fixed in next release. Maybe you can
try the imagex version coming with Windows Server 2008 AIK (I've not tryed).

Basically the problem is due to the fact that any console application
buffers its output on a 4KB buffer. Every single character is written on the
console, but the write operations on any kind of pipe (redirection and
StdOut.Read included) are done whenever the buffer is full. Because the
output of imagex is very small, this happens only when the execution
completes and the buffer get flushed. If I could have the source code of
imagex, I could fix it in 30 seconds, simply adding a buffer flush command
after every output. Unfortunately imagex is not open source.
There's no way to solve this problem with imagex. Even if you redirect
output to a file, the file get written only upon program termination.
The only solution I found is write (from scratch) a program in C++ and using
the WIMGAPI to manage the WIM files. This works pretty good. If you want to
use an HTA, the only solution I know is SmartWIM (it's an ActiveX that does
the same job of imagex and more), but you should pay for it (I never tryed
it anyway).
--
Massimo
Post by firebladeboy
Hi,
While deploying machines via WinPE 2.0 I'm using imagex.exe cmd to deploy an
image to a pc & I need see imagex progress (so I can't just hide the CMD
window.)
Basically what I'm trying to do is create a nicer UI so I don't have to show
the cmd window itself.. just the output it's giving, so far I have a hta that
will display the output of the cmd window but it will only show this once the
cmd is finished. I think I somehow need to create a loop to view the
contents of the cmd output while it's still running and refresh the hta every
few seconds.. maybe I need to output a temp file and refresh the hta from
that while cmd is still running?
I'm aiming to use this to redirect the output of any cmd window and maybe
call it as a function whenever exe's are being run (file copy / directory
listing / defrag etc).
===================
CMDout.hta
===================
<html>
<head><title>CMDOut</title>
<HTA:APPLICATION ID="oHTA";
APPLICATIONNAME="CMDOut";
BORDER="thin";
BORDERSTYLE="normal";
SINGLEINSTANCE="no";
</head><body bgcolor="#E8E8E8" >
<font size=2 face="Century Gothic, Tahoma, Arial" color="black">
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub Window_Onload
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From
Win32_DesktopMonitor")
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
intLeft = (intHorizontal - 640) / 2
intTop = (intVertical - 480) / 2
window.resizeTo 640,480
window.moveTo intLeft, intTop
cmdarg="%comspec% /c ipconfig.exe "
set objExCmd = objShell.Exec(cmdarg)
strOut=objExCmd.StdOut.ReadAll
Set regEx = New RegExp
regEx.Pattern = "[\f\n\r\v]+"
regEx.Global = True
regEx.Multiline = True
strOut = regEx.Replace(strOut, "<br>")
CMDOut.innerHTML= strOut
end sub
//-->
</script>
<div id=CMDOut></div>
================
any assistance would be greatly appreciated!
Thanks
Loading...