Solved

HTA Application Name not showing up in Task Manager

Posted on 2011-03-25
3
1,436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

690 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