Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[HTA] How to hide the CMD prompt on HTA Script ?

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
0
0
TN
Hi !
I wonder if there are any tricks or tips can be done to hide the CMD prompt when I execute this HTA script?
Thank you !

Code:
<html>
<head><title>Traceroute</title>
<HTA:APPLICATION ID="oHTA";
  APPLICATIONNAME="Traceroute";
  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 traceroute
cmdarg="%comspec% /c tracert.exe " & T1.value
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>")
TraceOut.innerHTML= strOut
end sub
//-->
</script>
<p><b>Traceroute HTA by Paul R. Sadowski (11/2001)</b><hr noshode color="#000000"><br>
    <p>Hostname: <input type="text" size="40" name="T1">
    <input type="submit" name="B1" value="Submit"  onclick="traceroute"></p>
<div id=TraceOut></div>
<script language="JavaScript">
<!--
	if (window.resizeTo) self.resizeTo(600,400);
//-->
</script>
 
The only thing I can think of is that you create a litle batch file on the fly containing your reqyuired DOS command and redirected to a file

eg c:\test.bat
cmd /c tracert.exe localhost > c:\test.txt

Then call it with this

objShell.run "c:\test.bat" ,0,true

then read the output file c:\test.txt and display output in your HTA


In order to understand recursion, you must first understand recursion.
 
it won't "hide" the cmdbox but it will prevent 2 cmdbox from showing. The first box is opened by %comspec%. The second box is opened by the first to execute tracert.exe.

cmdarg="%comspec% /c tracert.exe " & T1.value


-Geates

"I do not offer answers, only considerations."
- Geates's Disclaimer

 
Thank you for your replies !
So The Problem is solved like this:

Code:
<html>
<head><title>Traceroute</title>
<HTA:APPLICATION ID="oHTA";
  APPLICATIONNAME="Traceroute";
  BORDER="thin";
  SCROLL="yes"
  SINGLEINSTANCE="yes"
  WINDOWSTATE="Maximize"
  icon="verifier.exe"
>
</head>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<script language="VBScript" type="text/vbscript">
Function CmdPrompt(sCmd)
  Dim strOut,alines, sCmdLine, stemp, ofs, oWS, nRes
  sCmdLine = """%comspec%"" /c " & sCmd & " 1>> "
  set ofs = CreateObject("Scripting.FileSystemObject")
  stemp = ofs.GetTempName
  set oWS = CreateObject("Wscript.Shell")
  stemp = oWS.Environment("PROCESS")("TEMP") & "\" & stemp
  nRes = oWS.Run(sCmdLine & Chr(34) & sTemp & Chr(34),0,True)
  if ofs.FileExists(sTemp) Then
    with ofs.OpenTextFile(stemp)
      if Not .AtEndofStream Then
        alines = aLines & .ReadAll
        alines = Replace(aLines,"‚","é")
        alines = Replace(alines,VbNewLine,"<br>")
        Message.style.visibility="visible"
        document.body.style.cursor = "default"
        TraceOut.InnerHTML = aLines
      End if
    End With
    ofs.DeleteFile stemp
    alines = Split(aLines, vbNewline)
   Else
    aLines = Array(nRes, "")
  End if
  ReDim Preserve alines(Ubound(alines) - 1)
  if Err.Number <> 0 Then _
    aLines = Array("Error Number:" & CStr(Err.Number),Err.Description)
    CmdPrompt = alines
    Message.style.visibility="visible"
    document.body.style.cursor = "default"
    TraceOut.InnerHTML = alines 
End Function

Sub Execution()
Message.InnerHTML = "<center><hr noshode color=""#000000""><b><font color='DarkOrange' size='5'>Détermination de l'itinéraire vers "&T1.Value&" </font><hr noshode color=""#000000"">"
document.body.style.cursor = "wait"
Call CmdPrompt("Tracert "&T1.Value&"")
End Sub
</script>
<body bgcolor="#12345678" text=white>
<center><font size=3 face="Century Gothic, Tahoma, Arial" color="White">
<p><b>Traceroute</b><hr noshode color="#000000"><br>
    <p>Nom de la Hôte ou bien son adresse IP: <input type="text" size="25" name="T1" Value="[URL unfurl="true"]www.tek-tips.com"></font></center>[/URL]
    <center><p><input type="submit" name="B1" value="Tracer la Hôte"  onclick="Execution()"></p></center>
    <span id ="Message"><hr noshode color="#000000"></span>
<font size=3 face="Century Gothic, Tahoma, Arial" color="White"><div id=TraceOut></div></font>
</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top