ask:
Hello, script expert! How to create an HTA without a "Close" button in the title bar?
--AK
answer:
Hello, AK. You know, your problem has put us in a moral and ethical dilemma. After all, if we give the answer to this question: the world may suddenly be overwhelmed by a large number of HTAs that cannot be turned off. A picture will appear before our eyes: the HTA, which cannot be turned off and cannot be stopped, sweeping across the entire land frantically and swallowing all the system resources along the way. And we script experts will be responsible for this. We just feel that we cannot bear such a guilt in our conscience.
But what is the difference between adding one more guilt to our conscience? After clarifying this, we give the following HTA that cannot be closed; the only way to turn it off is to terminate the Mshta.exe process (or have the Army Air Force shoot it down from the top of the Empire State Building):
<html>
<head>
<title>Test</title>
</head>
<HTA:APPLICATION
SysMenu="no"
>
<body>
<p>ThisHTAhasnoClosebutton.</p>
</body>
</html>
When you run it, the results you see should be similar to the following image:
So how do we remove the Close button (not to mention the Maximize and Minimize buttons) and still retain the window title bar? It's very simple: just set the SysMenu property value to no:
<HTA:APPLICATION
SysMenu="no"
>
That's it: Setting the value of SysMenu to no (this must be done inside the HTA:APPLICATION tag) will remove the Close button, the Maximize and Minimize buttons, and the system menu. You can still move the window around (click the title bar and drag it), but there is no way to close the window.
Yes, our conscience is a little uneasy at this moment. (Although this is likely because we finished our last cup of coffee but were too lazy to re-making a pot.) Below is a revised HTA with no "Close" button in the title bar; however, there is a button marked Exit in its body. Click this button and a subroutine named ExitProgram will close the HTA window:
<html>
<head>
<title>Test</title>
</head>
<HTA:APPLICATION
SysMenu="no"
>
<SCRIPTLANGUAGE="VBScript">
SubExitProgram
window.close()
EndSub
</SCRIPT>