How Can I Create an HTA that Doesn’t Have a Close Button in the Title Bar?


Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I create an HTA that doesn’t have a Close button in the title bar?

-- AK

SpacerHey, Scripting Guy! AnswerScript Center

Hey, AK. You know, you’ve presented us with a great moral and ethical quandary. After all, suppose we answer this question: suddenly the world might be inundated with HTAs that couldn’t be closed. We have this vision of unclosable, unstoppable HTAs sweeping unchecked throughout the land, gobbling up any and all system resource in their paths. And we, the Scripting Guys, would be responsible for that. We just don’t think we could live with such a thing on our consciences.


But, then again, what difference will it make to have one more thing on our consciences? With that in mind, here’s an HTA that can’t be closed; the only way to get rid of it is to terminate the Mshta.exe process (or have the Army Air Corps try to shoot it down off the top of the Empire State Building):

<html>
<head>
<title>Test</title>
</head>

<HTA:APPLICATION
SysMenu="no"
>

<body>
<p>This HTA has no Close button.</p>
</body>
</html>


And when you run the thing, you should see something that looks like this:

HTA


So how did we get rid of the Close button (not to mention the Minimize and Maximize buttons) yet still keep the window title bar? That’s easy: all we did was set the value of the SysMenu property to no:

<HTA:APPLICATION
SysMenu="no"
>

That’s it: setting the value of SysMenu to no (which must be done inside the HTA:APPLICATION tag) will get rid of the Close button, the Minimize and Maximize buttons, and the system menu. You can still move the window around (just click on the title bar and drag), but there’s no way to close the window.


And, yes, our consciences are bothering us a little. (Although that’s probably because we drank the last of the coffee but were too lazy to make a new pot.) Here’s a revised HTA that doesn’t have a Close button in the title bar; however, it does have a button in the body of the HTA labeled Exit. Click that button, and a subroutine named ExitProgram will close the HTA window for you:

<html>
<head>
<title>Test</title>
</head>

<HTA:APPLICATION
SysMenu="no"
>

<SCRIPT LANGUAGE="VBScript">
Sub ExitProgram
window.close()
End Sub
</SCRIPT>

<body>
<input id=runbutton type="button" value="Exit" onClick="ExitProgram">
</body>
</html>


In this case, we end up with an HTA that looks like this:

HTA


All things considered, it’s probably best to have some way to gracefully dismiss the HTA. But that’s up to you. And your conscience.







Note. If you’ve read through this entire column and are still thinking, “HT-whats?” then you might want to check out the information in the HTA Developers Center, or - even better - view the Scripting Week 3 webcast on creating HTAs.

Comments (3)

  1. Anonymous Coward says:

    Absolute rubbish that it can't be closed.

    Press Alt+F4.

    Behold, window closes.

    (Sorry to exhume this post, but bald-faced lies like this get my goat. It's like you're saying the sky is green)

  2. tornaritech says:

    Sure it can be closed! You need an exit button and the ExitProgram sub. You can see it if you know the basic in Vbscripts! The only thing I would like to ask is how to disable the close button but leave the minimize and maximize. The SysMenu="no" option
    removes them all!

  3. mike says:

    can you stop this with ctrl alt delete?

Skip to main content