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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA talking to HTA 1

Status
Not open for further replies.

Skie

Programmer
Jun 21, 2004
475
US
I have two HTAs and I want them to be able to talk to each other. If they were IE, this would be pretty simple. Grab the object and then call scripts, populate fields, etc. from there. What I don't know is the code to get an HTA object.
 
An HTA is just an IE object.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Code:
Set oApp = CreateObject("Shell.Application")
For Each oWin In oApp.Windows
 If InStr(oWin.Name, "Internet") Then
  Set oElements = oWin.Document.GetElementsByTagName("title")
  For Each oElement In oElements
   WScript.Echo oElement.innerHTML & " - " & oWin.Name
  Next
  Set oElements = Nothing
 End If
Next
This returns "VBScript - HTA talking to HTA - Microsoft Internet Explorer" as the only application. If I remove the Instr line I get the same response. This makes sense because HTAs don't show as applications.
 
If I run through the processes using a WMI.ExecQuery I can find mshta.exe, but I don't know how to manipulate the window from there...
 
>This returns "VBScript - HTA talking to HTA - Microsoft Internet Explorer" as the only application. If I remove the Instr line I get the same response.
You don't find error except very particular case?!

This is what you can get the idea of handling talking.
[tt]
Set oApp = CreateObject("Shell.Application")
For Each oWin In oApp.Windows
If InStr(oWin.Name, "Internet") Then
[blue]if strcomp(typename(oWin.document),"htmldocument",1)=0 then[/blue]
Set oElements = oWin.Document.GetElementsByTagName("title")
For Each oElement In oElements
WScript.Echo oElement.innerHTML & " - " & oWin.Name
Next
Set oElements = Nothing
[blue]end if[/blue]
End If
Next
[/tt]
 
Using the code tsuji posted, I get the exact same response, "VBScript - HTA talking to HTA - Microsoft Internet Explorer", of this open IE window. I have two HTA windows open, but they're not listed as a window from Shell.Application.

Code:
Set oApp = CreateObject("Shell.Application")
For Each oWin In oApp.Windows
  WScript.Echo oWin.Name
Next
Even if I simplify the code, it only returns the open IE window.
 
>Using the code tsuji posted, I get the exact same response, "VBScript - HTA talking to HTA - Microsoft Internet Explorer", of this open IE window.
What do you mean? I tell you your script is incorrect, period.
 
I realize the code I posted could result in an error if say an explorer window was open. However, I'm not receiving an error and I'm not trapping any errors. My point was that the HTA window isn't handled the same as an IE window. As far as I can tell, and this is where I need help, I can't grab an HTA object and send it commands.

As far as I can tell, the only way I could get two HTAs to talk to each other would be to create a common object. HTA A passes a message to the common object. HTA B is set to check that object every tenth of a second. If there's a message there, HTA B executes something based on the message. Then HTA B removes the message and/or passes a message back saying, "I'm done." HTA A code proceeds.

If there's a way to get them talking directly, I'd prefer to be able do that instead.
 
You could create some sort of out-of-process server to do it, but there is no reason why it couldn't raise events back to your HTA.

It might be even easier to create an in-process server that implements one of the many types of IPC Windows supports. Maybe a separate client and server control or class or a combined transceiver control or class.

One of the few standard IPC mechanisms with an existing COM wrapper that I know of in Windows is MSMQ. Of course not all machines have it installed, since it is an optional Windows component. It is quite powerful though, and probably does a lot more than you need even on machines running in Workgroup mode. Aside from XP Home it is supported on NT 4.0 and every OS beginning with Win2K. Microsoft even decided to imclude it in limited form in most Vista Home Editions.
 
I should add that MSMQ private machine queues can be used between machines even within a Workgroup LAN as well as within one machine. Of course the options range more widely on an AD network.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top