Learn about Windows PowerShell
Hey, Scripting Guy! How can I create an HTA that doesn’t have a Close button in the title bar?-- AK
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):
<p>This HTA has no Close button.</p>
And when you run the thing, you should see something that looks like this:
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:
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:
<input id=runbutton type="button" value="Exit" onClick="ExitProgram">
In this case, we end up with an HTA that looks like this:
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.
Absolute rubbish that it can't be closed.
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)
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!