Solved

HTA Application Name not showing up in Task Manager

Posted on 2011-03-25
3
1,389 Views
Last Modified: 2012-05-11
I have an HTA application that I have the HTA tag set with the Application name.  Refering to Microsofts page (http://technet.microsoft.com/en-us/library/ee692768.aspx) the Application name tag will be the name that is displayed in the Task Manager.  For some reason this is not displaying in any task manger I run on Windows XP SP 3 machines.  I need this to display as an application in task manager because I have code in the HTA which actives the window:
set wshell=createobject("wscript.shell")
wshell.appActivate("MyHTA")

Any ideas on why this dose not display?

<html>
<head>
<title>HTA App</title>

<HTA:APPLICATION
     APPLICATIONNAME="MyHTA"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

Open in new window

0
Comment
Question by:BKRsupport
3 Comments
 
LVL 14

Expert Comment

by:Dhiraj Mutha
ID: 35220045
Try this and let me know what happens
<html>
<head>
<title>HTA App</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Admin Login"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     
>

<body bgcolor=black>

Open in new window

0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 500 total points
ID: 35226752
If you are using:

wshell.appActivate("MyHTA")

... Then it won't work because the title of your application is here:

<title>HTA App</title>

... so the correct line would be something like:

wshell.appActivate document.Title

But I've found in my testing that for some reason I don't completely understand, the AppActivate method only seems to work once during a running HTA.

The code snippet below demonstrates one method I got to make the HTA come to the foreground over and over again,

Basically it generates a VBscript and, works out the PID of itself and passes it to the generated VBScript which does the AppActivate independently.

The timers just mean that every 5 seconds it calls the sub which makes the HTA come to the foreground.

Hope this Helps,
Daz.
<html>
<head>
<title>HTA App</title>

<HTA:APPLICATION
     APPLICATIONNAME="MyHTA"
     ID="oHTA"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>

<script Language = "VBScript">
    Dim idTimer


    Sub Window_Onload
        idTimer = window.setTimeout("BringToFront()", 5000)
    End Sub

    Sub BringToFront()
        window.ClearTimeout(idTimer)
        MeFocus()
        idTimer = window.setTimeout("BringToFront()", 5000)
        Set wshShell = Nothing
    End Sub

    Sub MeFocus()
        Dim fso, ts, wshShell, sTempScript, objWMIService, colProcesses, objProcess, iPid, sCmdLine
        Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
        Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name='mshta.exe'")
        iPid = 0
        For Each objProcess in colProcesses
            If InStr(1, objProcess.CommandLine, oHTA.CommandLine, 1) <> 0 Then iPid = objProcess.ProcessID
        Next
        If iPid = 0 Then
            MsgBox "Unable to work out the PID of this HTA!" : Exit Sub
        End If
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set wshShell = CreateObject("WScript.Shell")
        sTempScript = wshShell.ExpandEnvironmentStrings("%temp%\MeFocus.vbs")
        If Not fso.FileExists(sTempScript) Then
            Set ts = fso.OpenTextFile(sTempScript, 2, True)
            ts.WriteLine "Set wshShell = CreateObject(""WScript.Shell"")"
            ts.WriteLine "wshShell.AppActivate WScript.Arguments(0)"
            ts.Close
        End If
        wshShell.Run "WScript.exe """ & sTempScript & """ " & iPid, 0, True
    End Sub

</script>

</head>

<body>

<p> Test HTA </p>


</body>
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:BKRsupport
ID: 35231793
This is a bit more of a complicated solution but it works.  According to the Microsoft page the ApplicationName is what should be listed in the Task Manager Application list, not title.  However neither is listed in the task manager which is why your solution for finding the Process ID works and activating that will have to work.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
css, html 5 42
How would I do a website like this? 5 57
Html test in IIS 4 20
Mouse event to control image and transparency. 4 22
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question