From: Tom Lavedas on
On Jun 30, 11:11 am, "\\Rems" <akar...(a)gmail.com> wrote:
> On 26 jun, 04:27, "Todd Vargo" <tlva...(a)sbcglobal.netz> wrote:
>
>
>
> > >  Nice piece of work, Tom!
>
> > >  I don't really have a need for themessagebox, per se, but I will likely
> > > be borrowing your technique for some other projects. Having anHTA
> > > launched from a WSF really opens the door to being able to have pseudo
> > > multi-threadedHTA. The entire body of theHTAcan be neatly packaged
> > > inside of a <resource> in the WSF.
>
> > Yes, nice work Tom. The only thing that bothers me is when run using the
> > WSCRIPT.EXE host, after theHTAcloses and control returns to the script,
> > the window focus does not return to the running script. In otherwords, any
> > MsgBox thereafter will be opened as minimized. The only thing that seems to
> > display the MsgBox in the foreground following theHTAis if the
> > vbSystemModal flag is used.
>
> > --
> > Todd Vargo
>
> > (Post questions to group only. Remove "z" to email personal messages)- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > - Tekst uit oorspronkelijk bericht weergeven -
>
> There is a somewhat ugly workaround to get the focus back to
> wscript.exe  =>  .sendkeys "^"
>
> Awesome piece of work Tom!
>
> I noticed when I test the script that iexplore.exe processes where not
> quit after the script is ended.
> Therefore I added IE.quit to the script.
>
> I also perform a resize of the box twice - the first time there is
> just a minimal box centered on the screen.
> And after the color of the body has been set, the script resize the
> box to its final size.
> Additionally the intWindowStyle for CreateObject("WScript.Shell").RUN
> have I set to 2
>
> A sample is below (sorry for the other changes, these are personal),
>
> ' A simple example of HTABox --------------------------------
> {snip}

> ' ---------- code ends -------------
>
> \Rems

OK, I think the problem is that I didn't DIM IE in the subroutine, as
I should have. If that variable is made local it will release the
instance of IE upon exit of the function.

' A simple example of HTABox --------------------------------

'Dim IE
sWidth = 300
sHeight = 210

with HTABox(sHeight, sWidth)
.document.title = String(18, chr(160)) & "Credentials"
.msg.innerHTML = "UserID: &nbsp; &nbsp; <input type=text " _
& "size=20 id=UID><br>Password: <input "_
& "type=password id=PW size=22><p><input " _
& "type=submit value=Submit onclick=" _
& "'done.value=true'>"
.UID.value = createobject("wscript.network").username
.PW.focus
do until .done.value : wsh.sleep 50 : loop
sUID = .UID.value : sPW = .PW.value
.close
end with
CreateObject("WScript.Shell").SendKeys "^"

wsh.echo "UID:", sUID, "Password:", sPW

'--------- Main Ends ------------

' Author: Tom Lavedas, June 2010
Function HTABox(h, w)
Dim l, t, IE, sCmd
With createobject("internetexplorer.application")
l = .width
t = .height
.quit
End with

Dim IHTA
nRnd = hex(Timer*100)

sCmd = "mshta.exe ""javascript:{new " _
& "ActiveXObject(""InternetExplorer.Application"")" _
& ".PutProperty('" & nRnd & "',window);" _
& "window.resizeTo();window.moveTo(" & l/2 & "," & t/2 & ")}"""

with CreateObject("WScript.Shell")
.Run sCmd, 2, False
do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
end with ' WSHShell

For Each IE In CreateObject("Shell.Application").windows
If IsObject(IE.GetProperty(nRnd)) Then
set HTABox = IE.GetProperty(nRnd)
HTABox.document.title = "HTABox"
HTABox.document.write _
"<HTA:Application contextMenu=no border=thin " _
& "minimizebutton=no maximizebutton=no sysmenu=no />" _
& "<body scroll=no style=filter:progid:DXImageTrans" _
& "form.Microsoft.Gradient(GradientType=0,StartColor" _
& "Str='#86cceb',endColorStr='#5589ab');font:normal " _
& "10pt Arial' onbeforeunload='vbscript:if not done." _
& "value then window.event.cancelBubble=true:" _
& "window.event.returnValue=false:" _
& "done.value=true:end if'>" _
& "<input type=hidden id=done value=false>" _
& "<center><span id=msg>&nbsp;</span><center></body>"

l = (l - w) /2
t = (t - h) /2
HTABox.moveTo l,t
HTABox.resizeTo w,h
Exit Function
End If
Next

' I can't imagine how this line can be reached, but just in case
MsgBox "HTA window not found." : wsh.quit

End Function
' ---------- code ends -------------

If that doesn't work for some reason (it worked on my XPSP3 equipped
system), you can add an IE.QUIT right after the GetProperty line to
release IE. It's not needed after that point.
_____________________
Tom Lavedas
From: Rems on
On 30 jun, 17:39, Tom Lavedas <tglba...(a)verizon.net> wrote:
> On Jun 30, 11:11 am, "\\Rems" <akar...(a)gmail.com> wrote:
>
>
>
>
>
> > On 26 jun, 04:27, "Todd Vargo" <tlva...(a)sbcglobal.netz> wrote:
>
> > > >  Nice piece of work, Tom!
>
> > > >  I don't really have a need for themessagebox, per se, but I will likely
> > > > be borrowing your technique for some other projects. Having anHTA
> > > > launched from a WSF really opens the door to being able to have pseudo
> > > > multi-threadedHTA. The entire body of theHTAcan be neatly packaged
> > > > inside of a <resource> in the WSF.
>
> > > Yes, nice work Tom. The only thing that bothers me is when run using the
> > > WSCRIPT.EXE host, after theHTAcloses and control returns to the script,
> > > the window focus does not return to the running script. In otherwords, any
> > > MsgBox thereafter will be opened as minimized. The only thing that seems to
> > > display the MsgBox in the foreground following theHTAis if the
> > > vbSystemModal flag is used.
>
> > > --
> > > Todd Vargo
>
> > > (Post questions to group only. Remove "z" to email personal messages)- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -
>
> > There is a somewhat ugly workaround to get the focus back to
> > wscript.exe  =>  .sendkeys "^"
>
> > Awesome piece of work Tom!
>
> > I noticed when I test the script that iexplore.exe processes where not
> > quit after the script is ended.
> > Therefore I added IE.quit to the script.
>
> > I also perform a resize of theboxtwice - the first time there is
> > just a minimalboxcentered on the screen.
> > And after the color of the body has been set, the script resize the
> >boxto its final size.
> > Additionally the intWindowStyle for CreateObject("WScript.Shell").RUN
> > have I set to 2
>
> > A sample is below (sorry for the other changes, these are personal),
>
> > ' A simple example of HTABox --------------------------------
> > {snip}
> > ' ---------- code ends -------------
>
> > \Rems
>
> OK, I think the problem is that I didn't DIM IE in the subroutine, as
> I should have.  If that variable is made local it will release the
> instance of IE upon exit of the function.
>
> ' A simple example of HTABox --------------------------------
>
> 'Dim IE
> sWidth = 300
> sHeight = 210
>
> with HTABox(sHeight, sWidth)
>   .document.title = String(18, chr(160)) & "Credentials"
>   .msg.innerHTML = "UserID: &nbsp; &nbsp; <input type=text " _
>                  & "size=20 id=UID><br>Password: <input "_
>                  & "type=password id=PW size=22><p><input " _
>                  & "type=submit value=Submit onclick=" _
>                  & "'done.value=true'>"
>   .UID.value = createobject("wscript.network").username
>   .PW.focus
>   do until .done.value : wsh.sleep 50 : loop
>   sUID = .UID.value : sPW = .PW.value
>   .close
> end with
> CreateObject("WScript.Shell").SendKeys "^"
>
> wsh.echo "UID:", sUID, "Password:", sPW
>
> '--------- Main Ends ------------
>
> ' Author: Tom Lavedas, June 2010
> Function HTABox(h, w)
>    Dim l, t, IE, sCmd
>    With createobject("internetexplorer.application")
>      l = .width
>      t = .height
>      .quit
>    End with
>
>   Dim IHTA
>   nRnd = hex(Timer*100)
>
>   sCmd = "mshta.exe ""javascript:{new" _
>        & "ActiveXObject(""InternetExplorer.Application"")" _
>        & ".PutProperty('" & nRnd & "',window);" _
>        & "window.resizeTo();window.moveTo(" & l/2 & "," & t/2 & ")}"""
>
>   with CreateObject("WScript.Shell")
>     .Run sCmd, 2, False
>      do until .AppActivate("javascript:{new") : WSH.sleep 10 : loop
>   end with ' WSHShell
>
>   For Each IE In CreateObject("Shell.Application").windows
>     If IsObject(IE.GetProperty(nRnd)) Then
>       set HTABox = IE.GetProperty(nRnd)
>       HTABox.document.title = "HTABox"
>       HTABox.document.write _
>                "<HTA:Application contextMenu=no border=thin " _
>              & "minimizebutton=no maximizebutton=no sysmenu=no />" _
>              & "<body scroll=no style=filter:progid:DXImageTrans" _
>              & "form.Microsoft.Gradient(GradientType=0,StartColor" _
>              & "Str='#86cceb',endColorStr='#5589ab');font:normal " _
>              & "10pt Arial' onbeforeunload='vbscript:if not done." _
>              & "value then window.event.cancelBubble=true:" _
>              & "window.event.returnValue=false:" _
>              & "done.value=true:end if'>" _
>              & "<input type=hidden id=done value=false>" _
>              & "<center><span id=msg>&nbsp;</span><center></body>"
>
>       l = (l - w) /2
>       t = (t - h) /2
>       HTABox.moveTo l,t
>       HTABox.resizeTo w,h
>       Exit Function
>     End If
>   Next
>
> ' I can't imagine how this line can be reached, but just in case
>   MsgBox "HTAwindow not found." :  wsh.quit
>
> End Function
> ' ---------- code ends -------------
>
> If that doesn't work for some reason (it worked on my XPSP3 equipped
> system), you can add an IE.QUIT right after the GetProperty line to
> release IE.  It's not needed after that point.
> _____________________
> Tom Lavedas- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


Thanks Tom.
Actually you did DIM'd IE in the subroutine but iexpore.exe didn't
close on my computer (I use WinXPSP3 IE8).
I added IE.QUIT right after the GetProperty line now, that works very
well for me.

thanks,
\Rems