A new HTA based message box

  • Follow


About ten days ago I adapted a Mayayana solution to create a
"chromeless" msgbox replacement.  The thread can be found here:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.

At the time I figured the only thing objectionable about the approach
was that it flashed a large HTA window before it could be adjusted to
the desired size.  I asked if anyone might have a solution.  Having
received no response, I kept thinking about that problem.  I was
pretty sure a fix could be coded into the JavaScript used to create
the HTA in the first place, but couldn't get it to work.  Today I had
a 'eureka' moment and after some fiddling got it worked out.

Hear is an example that presents a request for credentials and
provides a simple UID/Password dialog box as an example of its use
(watch for wordwrap) ...

' A simple example of HTABox
-----------' Main -------------
with HTABox("lightgrey", 150, 300, 400, 500)
  .document.title = "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

wsh.echo "UID:", sUID, "Password:", sPW
'--------- Main Ends ------------

' Author: Tom Lavedas, June 2010
Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA

  randomize : nRnd = Int(1000000 * rnd)
  sCmd = "mshta.exe ""javascript:" _
       & "{with (new ActiveXObject(""InternetExplorer.Application""))
{" _
       & "PutProperty('" & nRnd & "',window);" _
       & "with (GetProperty('" & nRnd & "')){" _
       & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
")}}}"""

  with CreateObject("WScript.Shell")
    .Run sCmd, 1, False
    do until .AppActivate("javascript:{with ") : 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='background-color:" _
             & sBgColor & ";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>"
      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 -------------

I chose to make the dialog box as simple as possible, purposely devoid
of 'bells and whistles'.  It merely returns a handle to the HTA window
that is created.  It does provided some fundamental features such as
the setting of  background color, height, width, left position and top
position.  The actual controls for the object are left to the user to
define through the 'msg' object that the routine creates.  A user's
intention to continue is signaled via the hidden 'done' control, by
setting its value to True.  However, a script is free to close the
window at any time by issuing a 'close' command.  The script example
provides some illustrative code and logic.

Enjoy.
_____________________
Tom Lavedas
0
Reply Tom 6/25/2010 4:01:32 PM

"Tom Lavedas" <tglbatch@verizon.net> wrote in message 
news:b9622e6d-0213-4d67-824c-e3d07fb17416@k39g2000yqb.googlegroups.com...
> About ten days ago I adapted a Mayayana solution to create a
> "chromeless" msgbox replacement.  The thread can be found here:
> http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
>
> At the time I figured the only thing objectionable about the approach
> was that it flashed a large HTA window before it could be adjusted to
> the desired size.  I asked if anyone might have a solution.  Having
> received no response, I kept thinking about that problem.  I was
> pretty sure a fix could be coded into the JavaScript used to create
> the HTA in the first place, but couldn't get it to work.  Today I had
> a 'eureka' moment and after some fiddling got it worked out.

  Nice piece of work, Tom!

  I don't really have a need for the message box, per se, but I will likely 
be borrowing your technique for some other projects. Having an HTA launched 
from a WSF really opens the door to being able to have pseudo multi-threaded 
HTA. The entire body of the HTA can be neatly packaged inside of a 
<resource> in the WSF. 


0
Reply James 6/25/2010 5:49:00 PM


  That works nicely for me. I tried to adjust it
to get a more msgbox-like border, but that
doesn't seem to work. borderstyle=static seems
to be the only thing that has any effect at all,
and that produces a somewhat odd border.



| About ten days ago I adapted a Mayayana solution to create a
| "chromeless" msgbox replacement.  The thread can be found here:
| 
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
|
| At the time I figured the only thing objectionable about the approach
| was that it flashed a large HTA window before it could be adjusted to
| the desired size.  I asked if anyone might have a solution.  Having
| received no response, I kept thinking about that problem.  I was
| pretty sure a fix could be coded into the JavaScript used to create
| the HTA in the first place, but couldn't get it to work.  Today I had
| a 'eureka' moment and after some fiddling got it worked out.
|
| Hear is an example that presents a request for credentials and
| provides a simple UID/Password dialog box as an example of its use
| (watch for wordwrap) ...
|
| ' A simple example of HTABox
| -----------' Main -------------
| with HTABox("lightgrey", 150, 300, 400, 500)
|  .document.title = "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
|
| wsh.echo "UID:", sUID, "Password:", sPW
| '--------- Main Ends ------------
|
| ' Author: Tom Lavedas, June 2010
| Function HTABox(sBgColor, h, w, l, t)
| Dim IE, HTA
|
|  randomize : nRnd = Int(1000000 * rnd)
|  sCmd = "mshta.exe ""javascript:" _
|       & "{with (new ActiveXObject(""InternetExplorer.Application""))
| {" _
|       & "PutProperty('" & nRnd & "',window);" _
|       & "with (GetProperty('" & nRnd & "')){" _
|       & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
| ")}}}"""
|
|  with CreateObject("WScript.Shell")
|    .Run sCmd, 1, False
|    do until .AppActivate("javascript:{with ") : 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='background-color:" _
|             & sBgColor & ";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>"
|      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 -------------
|
| I chose to make the dialog box as simple as possible, purposely devoid
| of 'bells and whistles'.  It merely returns a handle to the HTA window
| that is created.  It does provided some fundamental features such as
| the setting of  background color, height, width, left position and top
| position.  The actual controls for the object are left to the user to
| define through the 'msg' object that the routine creates.  A user's
| intention to continue is signaled via the hidden 'done' control, by
| setting its value to True.  However, a script is free to close the
| window at any time by issuing a 'close' command.  The script example
| provides some illustrative code and logic.
|
| Enjoy.
| _____________________
| Tom Lavedas 


0
Reply Mayayana 6/25/2010 10:26:54 PM

James Whitlow wrote:
> "Tom Lavedas" <tglbatch@verizon.net> wrote in message 
> news:b9622e6d-0213-4d67-824c-e3d07fb17416@k39g2000yqb.googlegroups.com...
>> About ten days ago I adapted a Mayayana solution to create a
>> "chromeless" msgbox replacement.  The thread can be found here:
>>
snip...
>>
>> At the time I figured the only thing objectionable about the approach
>> was that it flashed a large HTA window before it could be adjusted to
>> the desired size.  I asked if anyone might have a solution.  Having
>> received no response, I kept thinking about that problem.  I was
>> pretty sure a fix could be coded into the JavaScript used to create
>> the HTA in the first place, but couldn't get it to work.  Today I had
>> a 'eureka' moment and after some fiddling got it worked out.
>
>  Nice piece of work, Tom!
>
>  I don't really have a need for the message box, per se, but I will likely 
> be borrowing your technique for some other projects. Having an HTA 
> launched from a WSF really opens the door to being able to have pseudo 
> multi-threaded HTA. The entire body of the HTA can 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 the HTA closes 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 the HTA is if the 
vbSystemModal flag is used.

-- 
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages) 

0
Reply Todd 6/26/2010 2:27:10 AM

Thanks for a very interesting post/threads highlighting some
of the distinctions between HTAs and simple IE.

If I understand correctly, the philosophy of the HTA is,
"Gee, this IE was initiated by VBScript, therefore
perhaps its not unreasonable to give the script proper
access."  So why isn't the same philosophy followed
when VBScript initiates an IE?  (that question is
meant to be rhetorical except for Microsoft system
designers/architects).  There are, after all, now two
ways to gain this end - one by the means shown in the
post and the other by creating (or copying onto) a
..HTA, no?  And doesn't that effectively undo all the
security introduced by such distinction?

Csaba Gabor from Vienna


On Jun 25, 6:01 pm, Tom Lavedas <tglba...@verizon.net> wrote:
> About ten days ago I adapted a Mayayana solution to create a
> "chromeless" msgbox replacement.  The thread can be found here:http://groups.google.com/group/microsoft.public.scripting.vbscript/br....
>
> At the time I figured the only thing objectionable about the approach
> was that it flashed a large HTA window before it could be adjusted to
> the desired size.  I asked if anyone might have a solution.  Having
> received no response, I kept thinking about that problem.  I was
> pretty sure a fix could be coded into the JavaScript used to create
> the HTA in the first place, but couldn't get it to work.  Today I had
> a 'eureka' moment and after some fiddling got it worked out.
>
> Hear is an example that presents a request for credentials and
> provides a simple UID/Password dialog box as an example of its use
> (watch for wordwrap) ...
>
> ' A simple example of HTABox
> -----------' Main -------------
> with HTABox("lightgrey", 150, 300, 400, 500)
>   .document.title = "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
>
> wsh.echo "UID:", sUID, "Password:", sPW
> '--------- Main Ends ------------
>
> ' Author: Tom Lavedas, June 2010
> Function HTABox(sBgColor, h, w, l, t)
> Dim IE, HTA
>
>   randomize : nRnd = Int(1000000 * rnd)
>   sCmd = "mshta.exe ""javascript:" _
>        & "{with (new ActiveXObject(""InternetExplorer.Application""))
> {" _
>        & "PutProperty('" & nRnd & "',window);" _
>        & "with (GetProperty('" & nRnd & "')){" _
>        & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
> ")}}}"""
>
>   with CreateObject("WScript.Shell")
>     .Run sCmd, 1, False
>     do until .AppActivate("javascript:{with ") : 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='background-color:" _
>              & sBgColor & ";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>"
>       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 -------------
>
> I chose to make the dialog box as simple as possible, purposely devoid
> of 'bells and whistles'.  It merely returns a handle to the HTA window
> that is created.  It does provided some fundamental features such as
> the setting of  background color, height, width, left position and top
> position.  The actual controls for the object are left to the user to
> define through the 'msg' object that the routine creates.  A user's
> intention to continue is signaled via the hidden 'done' control, by
> setting its value to True.  However, a script is free to close the
> window at any time by issuing a 'close' command.  The script example
> provides some illustrative code and logic.
>
> Enjoy.
> _____________________
> Tom Lavedas
0
Reply Csaba 6/26/2010 10:42:36 AM

|
| If I understand correctly, the philosophy of the HTA is,
| "Gee, this IE was initiated by VBScript, therefore
| perhaps its not unreasonable to give the script proper
| access."  So why isn't the same philosophy followed
| when VBScript initiates an IE?  (that question is
| meant to be rhetorical except for Microsoft system
| designers/architects).  There are, after all, now two
| ways to gain this end - one by the means shown in the
| post and the other by creating (or copying onto) a
| .HTA, no?  And doesn't that effectively undo all the
| security introduced by such distinction?
|
   I'm wondering about that, too. HTAs were introduced
as a way to continue using IE/script utilities in the face
of increasing IE security. In Win98 I blocked HTAs, never
used IE online, and used .html files for scripted utilities.
HTAs seemed like an unnecessary security risk.

   But post-Win9x, an HTA is really the only way to do
much of anything in IE without being blocked by security
restrictions. I still wouldn't take IE online. I now think
of it as an HTA-based scripting GUI. But the methods
we're using to get file open dialogs and custom message
boxes really shouldn't be possible from the point of view
of Microsoft's IE security approach.

   I wouldn't be surprised if MS "fixes" that functionality,
the same way they've blocked the production of custom
message boxes, offscreen IE instances, etc. 


0
Reply Mayayana 6/26/2010 1:01:07 PM

Mayayana wrote:
> | | If I understand correctly, the philosophy of the HTA is, | "Gee,
> this IE was initiated by VBScript, therefore | perhaps its not
> unreasonable to give the script proper | access."  So why isn't the
> same philosophy followed | when VBScript initiates an IE?  (that
> question is | meant to be rhetorical except for Microsoft system |
> designers/architects).  There are, after all, now two | ways to gain
> this end - one by the means shown in the | post and the other by
> creating (or copying onto) a | .HTA, no?  And doesn't that
> effectively undo all the | security introduced by such distinction? |
>  I'm wondering about that, too. HTAs were introduced as a way to
> continue using IE/script utilities in the face of increasing IE
> security. In Win98 I blocked HTAs, never used IE online, and used
> .html files for scripted utilities. HTAs seemed like an unnecessary
> security risk.
> 
> But post-Win9x, an HTA is really the only way to do much of anything
> in IE without being blocked by security restrictions. I still
> wouldn't take IE online. I now think of it as an HTA-based scripting
> GUI. But the methods we're using to get file open dialogs and custom
> message boxes really shouldn't be possible from the point of view of
> Microsoft's IE security approach.
> 
> I wouldn't be surprised if MS "fixes" that functionality, the same
> way they've blocked the production of custom message boxes, offscreen
> IE instances, etc.

I used to get around a lot of those IE security restrictions by making
Zone 0 visible then unblocking everything, but I haven't figured out how
to do that in Windows 7, so I'm using HTA, instead. I've had to rewrite
a lot of homebuilt utilities, including my browser home page.
-- 
Crash

"Patriotism is the last refuge of a scoundrel."
~ Samuel Johnson ~
0
Reply Dave 6/26/2010 3:37:31 PM

| I used to get around a lot of those IE security restrictions by making
| Zone 0 visible then unblocking everything, but I haven't figured out how
| to do that in Windows 7, so I'm using HTA, instead. I've had to rewrite
| a lot of homebuilt utilities, including my browser home page.

  It keeps getting harder. IE security has become
a mess piled onto a mess piled onto a mess. I wrote
a script to demonstrate the *8* Registry values
currently involved with IE settings:

http://www.jsware.net/jsware/zips/ielocal.zip

Linked from this info. page:

http://www.jsware.net/jsware/iewacky.php5

  I don't think I've actually tried the script in Win7.
Like you, I only use HTAs now. I got tired of figuring
out all of those convoluted "secret" settings. IE is
really designed to be controlled by sys. admins in
corporations, used by employees on intranets. 


0
Reply Mayayana 6/26/2010 4:06:14 PM


"Csaba Gabor" <danswer@gmail.com> wrote in message 
news:766088c9-f311-459a-bfc9-23bd9ba74f80@t10g2000yqg.googlegroups.com...
> Thanks for a very interesting post/threads highlighting some
> of the distinctions between HTAs and simple IE.
>
> If I understand correctly,

you don't...

>    the philosophy of the HTA is,
> "Gee, this IE was initiated by VBScript, therefore
> perhaps its not unreasonable to give the script proper
> access."

As I understand it, the HTA was created as a way to develop applications 
having the same level of security restrictions as .exe's (i.e. none). There 
is no distinction about how the HTA (or HTML web page) is started and 
whether or not it is being manipulated by script not contained in the HTA 
itself.

>    So why isn't the same philosophy followed
> when VBScript initiates an IE?  (that question is
> meant to be rhetorical except for Microsoft system
> designers/architects).  There are, after all, now two
> ways to gain this end - one by the means shown in the
> post and the other by creating (or copying onto) a
> .HTA, no?  And doesn't that effectively undo all the
> security introduced by such distinction?

The idea is that an application you develop (or purchase) is generally more 
trustworthy than whatever web site your browser might take you to.

/Al

>
> Csaba Gabor from Vienna
>
>
> On Jun 25, 6:01 pm, Tom Lavedas <tglba...@verizon.net> wrote:
>> About ten days ago I adapted a Mayayana solution to create a
>> "chromeless" msgbox replacement.  The thread can be found 
>> here:http://groups.google.com/group/microsoft.public.scripting.vbscript/br....
>>
>> At the time I figured the only thing objectionable about the approach
>> was that it flashed a large HTA window before it could be adjusted to
>> the desired size.  I asked if anyone might have a solution.  Having
>> received no response, I kept thinking about that problem.  I was
>> pretty sure a fix could be coded into the JavaScript used to create
>> the HTA in the first place, but couldn't get it to work.  Today I had
>> a 'eureka' moment and after some fiddling got it worked out.
>>
>> Hear is an example that presents a request for credentials and
>> provides a simple UID/Password dialog box as an example of its use
>> (watch for wordwrap) ...
>>
>> ' A simple example of HTABox
>> -----------' Main -------------
>> with HTABox("lightgrey", 150, 300, 400, 500)
>>   .document.title = "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
>>
>> wsh.echo "UID:", sUID, "Password:", sPW
>> '--------- Main Ends ------------
>>
>> ' Author: Tom Lavedas, June 2010
>> Function HTABox(sBgColor, h, w, l, t)
>> Dim IE, HTA
>>
>>   randomize : nRnd = Int(1000000 * rnd)
>>   sCmd = "mshta.exe ""javascript:" _
>>        & "{with (new ActiveXObject(""InternetExplorer.Application""))
>> {" _
>>        & "PutProperty('" & nRnd & "',window);" _
>>        & "with (GetProperty('" & nRnd & "')){" _
>>        & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
>> ")}}}"""
>>
>>   with CreateObject("WScript.Shell")
>>     .Run sCmd, 1, False
>>     do until .AppActivate("javascript:{with ") : 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='background-color:" _
>>              & sBgColor & ";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>"
>>       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 -------------
>>
>> I chose to make the dialog box as simple as possible, purposely devoid
>> of 'bells and whistles'.  It merely returns a handle to the HTA window
>> that is created.  It does provided some fundamental features such as
>> the setting of  background color, height, width, left position and top
>> position.  The actual controls for the object are left to the user to
>> define through the 'msg' object that the routine creates.  A user's
>> intention to continue is signaled via the hidden 'done' control, by
>> setting its value to True.  However, a script is free to close the
>> window at any time by issuing a 'close' command.  The script example
>> provides some illustrative code and logic.
>>
>> Enjoy.
>> _____________________
>> Tom Lavedas 

0
Reply Al 6/26/2010 10:48:53 PM


"Tom Lavedas" <tglbatch@verizon.net> wrote in message 
news:b9622e6d-0213-4d67-824c-e3d07fb17416@k39g2000yqb.googlegroups.com...
> About ten days ago I adapted a Mayayana solution to create a
> "chromeless" msgbox replacement.  The thread can be found here:
> http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
>
> At the time I figured the only thing objectionable about the approach
> was that it flashed a large HTA window before it could be adjusted to
> the desired size.  I asked if anyone might have a solution.  Having
> received no response, I kept thinking about that problem.  I was
> pretty sure a fix could be coded into the JavaScript used to create
> the HTA in the first place, but couldn't get it to work.  Today I had
> a 'eureka' moment and after some fiddling got it worked out.
>
> Hear is an example that presents a request for credentials and
> provides a simple UID/Password dialog box as an example of its use
> (watch for wordwrap) ...
>
> ' A simple example of HTABox
> -----------' Main -------------
> with HTABox("lightgrey", 150, 300, 400, 500)
>  .document.title = "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
>
> wsh.echo "UID:", sUID, "Password:", sPW
> '--------- Main Ends ------------
>
> ' Author: Tom Lavedas, June 2010
> Function HTABox(sBgColor, h, w, l, t)
> Dim IE, HTA
>
>  randomize : nRnd = Int(1000000 * rnd)
>  sCmd = "mshta.exe ""javascript:" _
>       & "{with (new ActiveXObject(""InternetExplorer.Application""))
> {" _
>       & "PutProperty('" & nRnd & "',window);" _
>       & "with (GetProperty('" & nRnd & "')){" _
>       & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
> ")}}}"""
>
>  with CreateObject("WScript.Shell")
>    .Run sCmd, 1, False
>    do until .AppActivate("javascript:{with ") : 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='background-color:" _
>             & sBgColor & ";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>"
>      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 -------------
>
> I chose to make the dialog box as simple as possible, purposely devoid
> of 'bells and whistles'.  It merely returns a handle to the HTA window
> that is created.  It does provided some fundamental features such as
> the setting of  background color, height, width, left position and top
> position.  The actual controls for the object are left to the user to
> define through the 'msg' object that the routine creates.  A user's
> intention to continue is signaled via the hidden 'done' control, by
> setting its value to True.  However, a script is free to close the
> window at any time by issuing a 'close' command.  The script example
> provides some illustrative code and logic.
>
> Enjoy.
> _____________________
> Tom Lavedas

This is great stuff and I have been looking for something like this for 
quite some time. It is fairly easy to adapt the code for different 
applications even for someone like me who knows nothing at all about HTA and 
Java. However, I do have a problem with an application that requires a 
banner panel across the top of the screen. Just an informative message, no 
OK button. It runs in parallel with some independent process. To close the 
panel I replace this line

do until .done.value : wsh.sleep 50 : loop

with something like this:

do until oFSO.FileExists(sSemaphore) : loop

where the semaphore file is created by the parallel process. This works but 
here is a snag: The moment the program drops out of the Do loop, IE 
generates a dialog box asking if I really want to close the current window. 
How can I prevent this box from popping up? 

0
Reply Pegasus 6/29/2010 8:23:53 PM

On Jun 29, 4:23=A0pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Tom Lavedas" <tglba...@verizon.net> wrote in message
>
> news:b9622e6d-0213-4d67-824c-e3d07fb17416@k39g2000yqb.googlegroups.com...
>
>
>
> > About ten days ago I adapted a Mayayana solution to create a
> > "chromeless" msgbox replacement. =A0The thread can be found here:
> >http://groups.google.com/group/microsoft.public.scripting.vbscript/br...=
..
>
> > At the time I figured the only thing objectionable about the approach
> > was that it flashed a large HTA window before it could be adjusted to
> > the desired size. =A0I asked if anyone might have a solution. =A0Having
> > received no response, I kept thinking about that problem. =A0I was
> > pretty sure a fix could be coded into the JavaScript used to create
> > the HTA in the first place, but couldn't get it to work. =A0Today I had
> > a 'eureka' moment and after some fiddling got it worked out.
>
> > Hear is an example that presents a request for credentials and
> > provides a simple UID/Password dialog box as an example of its use
> > (watch for wordwrap) ...
>
> > ' A simple example of HTABox
> > -----------' Main -------------
> > with HTABox("lightgrey", 150, 300, 400, 500)
> > =A0.document.title =3D "Credentials"
> > =A0.msg.innerHTML =3D "UserID: &nbsp; &nbsp; <input type=3Dtext =A0size=
=3D20
> > id=3DUID>"_
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 & "<br>Password: <input type=3Dpassword=
 id=3DPW
> > size=3D22><p>" _
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 & "<input type=3Dsubmit value=3DSubmit
> > onclick=3D'done.value=3Dtrue'>"
> > =A0.UID.value =3D createobject("wscript.network").username
> > =A0.PW.focus
> > =A0do until .done.value : wsh.sleep 50 : loop
> > =A0sUID =3D .UID.value : sPW =3D .PW.value
> > =A0.close
> > end with
>
> > wsh.echo "UID:", sUID, "Password:", sPW
> > '--------- Main Ends ------------
>
> > ' Author: Tom Lavedas, June 2010
> > Function HTABox(sBgColor, h, w, l, t)
> > Dim IE, HTA
>
> > =A0randomize : nRnd =3D Int(1000000 * rnd)
> > =A0sCmd =3D "mshta.exe ""javascript:" _
> > =A0 =A0 =A0 & "{with (new ActiveXObject(""InternetExplorer.Application"=
"))
> > {" _
> > =A0 =A0 =A0 & "PutProperty('" & nRnd & "',window);" _
> > =A0 =A0 =A0 & "with (GetProperty('" & nRnd & "')){" _
> > =A0 =A0 =A0 & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
> > ")}}}"""
>
> > =A0with CreateObject("WScript.Shell")
> > =A0 =A0.Run sCmd, 1, False
> > =A0 =A0do until .AppActivate("javascript:{with ") : WSH.sleep 10 : loop
> > =A0end with ' WSHShell
>
> > =A0For Each IE In CreateObject("Shell.Application").windows
> > =A0 =A0If IsObject(IE.GetProperty(nRnd)) Then
> > =A0 =A0 =A0set HTABox =3D IE.GetProperty(nRnd)
> > =A0 =A0 =A0HTABox.document.title =3D "HTABox"
> > =A0 =A0 =A0HTABox.document.write _
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 "<HTA:Application contextMenu=3Dno border=
=3Dthin " _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "minimizebutton=3Dno maximizebutton=3Dno sysm=
enu=3Dno />" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "<body scroll=3Dno style=3D'background-color:=
" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & sBgColor & ";font:normal 10pt Arial' " _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "onbeforeunload=3D'vbscript:if not done.value=
 then " _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "window.event.cancelBubble=3Dtrue:" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "window.event.returnValue=3Dfalse:" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "done.value=3Dtrue:end if'>" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "<input type=3Dhidden id=3Ddone value=3Dfalse=
>" _
> > =A0 =A0 =A0 =A0 =A0 =A0 & "<center><span id=3Dmsg>&nbsp;</span><center>=
</body>"
> > =A0 =A0 =A0Exit Function
> > =A0 =A0End If
> > =A0Next
>
> > ' I can't imagine how this line can be reached, but just in case
> > =A0MsgBox "HTA window not found." : =A0wsh.quit
>
> > End Function
> > ' ---------- code ends -------------
>
> > I chose to make the dialog box as simple as possible, purposely devoid
> > of 'bells and whistles'. =A0It merely returns a handle to the HTA windo=
w
> > that is created. =A0It does provided some fundamental features such as
> > the setting of =A0background color, height, width, left position and to=
p
> > position. =A0The actual controls for the object are left to the user to
> > define through the 'msg' object that the routine creates. =A0A user's
> > intention to continue is signaled via the hidden 'done' control, by
> > setting its value to True. =A0However, a script is free to close the
> > window at any time by issuing a 'close' command. =A0The script example
> > provides some illustrative code and logic.
>
> > Enjoy.
> > _____________________
> > Tom Lavedas
>
> This is great stuff and I have been looking for something like this for
> quite some time. It is fairly easy to adapt the code for different
> applications even for someone like me who knows nothing at all about HTA =
and
> Java. However, I do have a problem with an application that requires a
> banner panel across the top of the screen. Just an informative message, n=
o
> OK button. It runs in parallel with some independent process. To close th=
e
> panel I replace this line
>
> do until .done.value : wsh.sleep 50 : loop
>
> with something like this:
>
> do until oFSO.FileExists(sSemaphore) : loop
>
> where the semaphore file is created by the parallel process. This works b=
ut
> here is a snag: The moment the program drops out of the Do loop, IE
> generates a dialog box asking if I really want to close the current windo=
w.
> How can I prevent this box from popping up?

Immediately before your script issues the Close, set the value of
'done' equal to True, as in ...

with HTABox (...)
  do until oFSO.FileExists(sSemaphore) : loop
  .done.value =3D true
  .close
end with

Obviously, I didn't test that ;-}
_____________________
Tom Lavedas
0
Reply Tom 6/29/2010 8:51:02 PM

>
> Immediately before your script issues the Close, set the value of
> 'done' equal to True, as in ...
>
> with HTABox (...)
>  do until oFSO.FileExists(sSemaphore) : loop
>  .done.value = true
>  .close
> end with
>
> Obviously, I didn't test that ;-}
> _____________________
> Tom Lavedas

I just tested it myself - works like a charm. Thanks for the quick response! 

0
Reply Pegasus 6/29/2010 9:30:53 PM

On Jun 29, 5:30=A0pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> > Immediately before your script issues the Close, set the value of
> > 'done' equal to True, as in ...
>
> > with HTABox (...)
> > =A0do until oFSO.FileExists(sSemaphore) : loop
> > =A0.done.value =3D true
> > =A0.close
> > end with
>
> > Obviously, I didn't test that ;-}
> > _____________________
> > Tom Lavedas
>
> I just tested it myself - works like a charm. Thanks for the quick respon=
se!

Glad I could help.

BTW, I tweaked the code a bit (I figured out that the JavaScript part
could be simplified):

with HTABox("lightgrey", 150, 300, 400, 500)
  .document.title =3D "Credentials"
  .msg.innerHTML =3D "UserID: &nbsp; &nbsp; <input type=3Dtext  size=3D20
id=3DUID>"_
                 & "<br>Password: <input type=3Dpassword id=3DPW
size=3D22><p>" _
                 & "<input type=3Dsubmit value=3DSubmit
onclick=3D'done.value=3Dtrue'>"
  .UID.value =3D createobject("wscript.network").username
  .PW.focus
  do until .done.value : wsh.sleep 50 : loop
  sUID =3D .UID.value : sPW =3D .PW.value
  .done.value =3D true ' Only needed if box to be closed before return
  .close
end with

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

Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA

  randomize : nRnd =3D Int(1000000 * rnd)
  sCmd =3D "mshta.exe ""javascript:{new " _
       & "ActiveXObject(""InternetExplorer.Application"")" _
       & ".PutProperty('" & nRnd & "',window);" _
       & "window.resizeTo(" & w & "," & h & ");" _
       & "window.moveTo(" & l & "," & t & ")}"""

  with CreateObject("WScript.Shell")
    .Run sCmd, 1, 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 =3D IE.GetProperty(nRnd)
      HTABox.document.title =3D "HTABox"
      HTABox.document.write _
               "<HTA:Application contextMenu=3Dno border=3Dthin " _
             & "minimizebutton=3Dno maximizebutton=3Dno sysmenu=3Dno />" _
             & "<body scroll=3Dno style=3D'background-color:" _
             & sBgColor & ";font:normal 10pt Arial;" _
             & "border-Style:outset;border-Width:3px'" _
             & "onbeforeunload=3D'vbscript:if not done.value then " _
             & "window.event.cancelBubble=3Dtrue:" _
             & "window.event.returnValue=3Dfalse:" _
             & "done.value=3Dtrue:end if'>" _
             & "<input type=3Dhidden id=3Ddone value=3Dfalse>" _
             & "<center><span id=3Dmsg>&nbsp;</span><center></body>"
      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
__________________
Tom Lavedas
0
Reply Tom 6/30/2010 2:34:41 AM

On Jun 25, 10:27=A0pm, "Todd Vargo" <tlva...@sbcglobal.netz> wrote:
> James Whitlow wrote:
> > "Tom Lavedas" <tglba...@verizon.net> wrote in message
> >news:b9622e6d-0213-4d67-824c-e3d07fb17416@k39g2000yqb.googlegroups.com..=
..
> >> About ten days ago I adapted a Mayayana solution to create a
> >> "chromeless" msgbox replacement. =A0The thread can be found here:
>
> snip...
>
> >> At the time I figured the only thing objectionable about the approach
> >> was that it flashed a large HTA window before it could be adjusted to
> >> the desired size. =A0I asked if anyone might have a solution. =A0Havin=
g
> >> received no response, I kept thinking about that problem. =A0I was
> >> pretty sure a fix could be coded into the JavaScript used to create
> >> the HTA in the first place, but couldn't get it to work. =A0Today I ha=
d
> >> a 'eureka' moment and after some fiddling got it worked out.
>
> > =A0Nice piece of work, Tom!
>
> > =A0I don't really have a need for the message box, per se, but I will l=
ikely
> > be borrowing your technique for some other projects. Having an HTA
> > launched from a WSF really opens the door to being able to have pseudo
> > multi-threaded HTA. The entire body of the HTA can 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 the HTA closes and control returns to the script,
> the window focus does not return to the running script. In otherwords, an=
y
> MsgBox thereafter will be opened as minimized. The only thing that seems =
to
> display the MsgBox in the foreground following the HTA is if the
> vbSystemModal flag is used.
>
> --
> Todd Vargo
>
> (Post questions to group only. Remove "z" to email personal messages)

You could just reuse the same HTABox to display your results,
something like this ...

with HTABox("lightgrey", 150, 300, 400, 500)
  .document.title =3D "Credentials"
  .msg.innerHTML =3D "UserID: &nbsp; &nbsp; " _
 & "<input type=3Dtext size=3D20 id=3DUID>"_
 & "<br>Password: <input type=3Dpassword id=3DPW size=3D22><p>" _
 & "<input type=3Dsubmit value=3DSubmit onclick=3D'done.value=3Dtrue'>"
  .UID.value =3D createobject("wscript.network").username
  .PW.focus
  do until .done.value : wsh.sleep 50 : loop
  sUID =3D .UID.value : sPW =3D .PW.value

' Show the results by reusing the HTABox
' Optionally change box style parameters
  .resizeto 250, 125 : .moveto 500, 400
  .document.body.style.borderwidth =3D "1px"
  .document.title =3D "Results"
  .msg.innerHTML =3D "UID: " & sUID & " Password: " & sPW & "<p>" _
 & "<input type=3Dsubmit id=3Dok value=3DOK onclick=3D'done.value=3Dtrue'>"
  .done.value =3D false ' reset exit control to wait
  timeout =3D 3000 ' set an automatic close timeout
  .OK.focus
  do until .done.value or n > TimeOut: wsh.sleep 50 : n=3Dn+50 : loop
  .done.value =3D true ' suppress IE close message
  .close
end with
_____________________
Tom Lavedas
0
Reply Tom 6/30/2010 12:32:06 PM

On 26 jun, 04:27, "Todd Vargo" <tlva...@sbcglobal.netz> wrote:

> > =A0Nice piece of work, Tom!
>
> > =A0I don't really have a need for themessagebox, per se, but I will lik=
ely
> > 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, an=
y
> 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)- Te=
kst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


There is a somewhat ugly workaround to get the focus back to
wscript.exe  =3D>  .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 --------------------------------

Dim IE
sWidth =3D 300
sHeight =3D 210

with HTABox(sHeight, sWidth)
  .document.title =3D String(18, chr(160)) & "Credentials"
  .msg.innerHTML =3D "UserID: &nbsp; &nbsp; <input type=3Dtext " _
                 & "size=3D20 id=3DUID><br>Password: <input "_
                 & "type=3Dpassword id=3DPW size=3D22><p><input " _
                 & "type=3Dsubmit value=3DSubmit onclick=3D" _
                 & "'done.value=3Dtrue'>"
  .UID.value =3D createobject("wscript.network").username
  .PW.focus
  do until .done.value : wsh.sleep 50 : loop
  sUID =3D .UID.value : sPW =3D .PW.value
  .close
end with
IE.quit : CreateObject("WScript.Shell").SendKeys "^"


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

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


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

  Dim IHTA
  nRnd =3D hex(Timer*100)

  sCmd =3D "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 =3D IE.GetProperty(nRnd)
      HTABox.document.title =3D "HTABox"
      HTABox.document.write _
               "<HTA:Application contextMenu=3Dno border=3Dthin " _
             & "minimizebutton=3Dno maximizebutton=3Dno sysmenu=3Dno />" _
             & "<body scroll=3Dno style=3Dfilter:progid:DXImageTrans" _
             & "form.Microsoft.Gradient(GradientType=3D0,StartColor" _
             & "Str=3D'#86cceb',endColorStr=3D'#5589ab');font:normal " _
             & "10pt Arial' onbeforeunload=3D'vbscript:if not done." _
             & "value then window.event.cancelBubble=3Dtrue:" _
             & "window.event.returnValue=3Dfalse:" _
             & "done.value=3Dtrue:end if'>" _
             & "<input type=3Dhidden id=3Ddone value=3Dfalse>" _
             & "<center><span id=3Dmsg>&nbsp;</span><center></body>"

      l =3D (l - w) /2
      t =3D (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 -------------

\Rems
0
Reply Rems 6/30/2010 3:11:59 PM

On Jun 30, 11:11=A0am, "\\Rems" <akar...@gmail.com> wrote:
> On 26 jun, 04:27, "Todd Vargo" <tlva...@sbcglobal.netz> wrote:
>
>
>
> > > =A0Nice piece of work, Tom!
>
> > > =A0I don't really have a need for themessagebox, per se, but I will l=
ikely
> > > be borrowing your technique for some other projects. Having anHTA
> > > launched from a WSF really opens the door to being able to have pseud=
o
> > > 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 th=
e
> > 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 seem=
s 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 =A0=3D> =A0.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 =3D 300
sHeight =3D 210

with HTABox(sHeight, sWidth)
  .document.title =3D String(18, chr(160)) & "Credentials"
  .msg.innerHTML =3D "UserID: &nbsp; &nbsp; <input type=3Dtext " _
                 & "size=3D20 id=3DUID><br>Password: <input "_
                 & "type=3Dpassword id=3DPW size=3D22><p><input " _
                 & "type=3Dsubmit value=3DSubmit onclick=3D" _
                 & "'done.value=3Dtrue'>"
  .UID.value =3D createobject("wscript.network").username
  .PW.focus
  do until .done.value : wsh.sleep 50 : loop
  sUID =3D .UID.value : sPW =3D .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 =3D .width
     t =3D .height
     .quit
   End with

  Dim IHTA
  nRnd =3D hex(Timer*100)

  sCmd =3D "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 =3D IE.GetProperty(nRnd)
      HTABox.document.title =3D "HTABox"
      HTABox.document.write _
               "<HTA:Application contextMenu=3Dno border=3Dthin " _
             & "minimizebutton=3Dno maximizebutton=3Dno sysmenu=3Dno />" _
             & "<body scroll=3Dno style=3Dfilter:progid:DXImageTrans" _
             & "form.Microsoft.Gradient(GradientType=3D0,StartColor" _
             & "Str=3D'#86cceb',endColorStr=3D'#5589ab');font:normal " _
             & "10pt Arial' onbeforeunload=3D'vbscript:if not done." _
             & "value then window.event.cancelBubble=3Dtrue:" _
             & "window.event.returnValue=3Dfalse:" _
             & "done.value=3Dtrue:end if'>" _
             & "<input type=3Dhidden id=3Ddone value=3Dfalse>" _
             & "<center><span id=3Dmsg>&nbsp;</span><center></body>"

      l =3D (l - w) /2
      t =3D (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
0
Reply Tom 6/30/2010 3:39:02 PM

On 30 jun, 17:39, Tom Lavedas <tglba...@verizon.net> wrote:
> On Jun 30, 11:11=A0am, "\\Rems" <akar...@gmail.com> wrote:
>
>
>
>
>
> > On 26 jun, 04:27, "Todd Vargo" <tlva...@sbcglobal.netz> wrote:
>
> > > > =A0Nice piece of work, Tom!
>
> > > > =A0I 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 pse=
udo
> > > > 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 scrip=
t,
> > > the window focus does not return to the running script. In otherwords=
, any
> > > MsgBox thereafter will be opened as minimized. The only thing that se=
ems 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 =A0=3D> =A0.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. =A0If 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 =3D 300
> sHeight =3D 210
>
> with HTABox(sHeight, sWidth)
> =A0 .document.title =3D String(18, chr(160)) & "Credentials"
> =A0 .msg.innerHTML =3D "UserID: &nbsp; &nbsp; <input type=3Dtext " _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0& "size=3D20 id=3DUID><br>Password: <i=
nput "_
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0& "type=3Dpassword id=3DPW size=3D22><=
p><input " _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0& "type=3Dsubmit value=3DSubmit onclic=
k=3D" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0& "'done.value=3Dtrue'>"
> =A0 .UID.value =3D createobject("wscript.network").username
> =A0 .PW.focus
> =A0 do until .done.value : wsh.sleep 50 : loop
> =A0 sUID =3D .UID.value : sPW =3D .PW.value
> =A0 .close
> end with
> CreateObject("WScript.Shell").SendKeys "^"
>
> wsh.echo "UID:", sUID, "Password:", sPW
>
> '--------- Main Ends ------------
>
> ' Author: Tom Lavedas, June 2010
> Function HTABox(h, w)
> =A0 =A0Dim l, t, IE, sCmd
> =A0 =A0With createobject("internetexplorer.application")
> =A0 =A0 =A0l =3D .width
> =A0 =A0 =A0t =3D .height
> =A0 =A0 =A0.quit
> =A0 =A0End with
>
> =A0 Dim IHTA
> =A0 nRnd =3D hex(Timer*100)
>
> =A0 sCmd =3D "mshta.exe ""javascript:{new" _
> =A0 =A0 =A0 =A0& "ActiveXObject(""InternetExplorer.Application"")" _
> =A0 =A0 =A0 =A0& ".PutProperty('" & nRnd & "',window);" _
> =A0 =A0 =A0 =A0& "window.resizeTo();window.moveTo(" & l/2 & "," & t/2 & "=
)}"""
>
> =A0 with CreateObject("WScript.Shell")
> =A0 =A0 .Run sCmd, 2, False
> =A0 =A0 =A0do until .AppActivate("javascript:{new") : WSH.sleep 10 : loop
> =A0 end with ' WSHShell
>
> =A0 For Each IE In CreateObject("Shell.Application").windows
> =A0 =A0 If IsObject(IE.GetProperty(nRnd)) Then
> =A0 =A0 =A0 set HTABox =3D IE.GetProperty(nRnd)
> =A0 =A0 =A0 HTABox.document.title =3D "HTABox"
> =A0 =A0 =A0 HTABox.document.write _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"<HTA:Application contextMenu=3Dno border=
=3Dthin " _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "minimizebutton=3Dno maximizebutton=3Dno sys=
menu=3Dno />" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "<body scroll=3Dno style=3Dfilter:progid:DXI=
mageTrans" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "form.Microsoft.Gradient(GradientType=3D0,St=
artColor" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "Str=3D'#86cceb',endColorStr=3D'#5589ab');fo=
nt:normal " _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "10pt Arial' onbeforeunload=3D'vbscript:if n=
ot done." _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "value then window.event.cancelBubble=3Dtrue=
:" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "window.event.returnValue=3Dfalse:" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "done.value=3Dtrue:end if'>" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "<input type=3Dhidden id=3Ddone value=3Dfals=
e>" _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0& "<center><span id=3Dmsg>&nbsp;</span><center=
></body>"
>
> =A0 =A0 =A0 l =3D (l - w) /2
> =A0 =A0 =A0 t =3D (t - h) /2
> =A0 =A0 =A0 HTABox.moveTo l,t
> =A0 =A0 =A0 HTABox.resizeTo w,h
> =A0 =A0 =A0 Exit Function
> =A0 =A0 End If
> =A0 Next
>
> ' I can't imagine how this line can be reached, but just in case
> =A0 MsgBox "HTAwindow not found." : =A0wsh.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. =A0It'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
0
Reply Rems 7/1/2010 8:34:02 AM

16 Replies
787 Views

(page loaded in 0.312 seconds)


Reply: