prevent user closing a HTA - vbscript

Using vbscript in a HTA
Aim: To prevent a user closing the HTA (except by my custom button or by using windows taskmanager)
As i understand from various webpages; You cannot prevent the HTA from closing when the close button is clicked in the HTA SYSMENU. Therefore my solution is to prevent the user from clicking close in the first place.
First up is to disable the system menu:
<HTA:APPLICATION SYSMENU="no" />
nb. I will replace the system menu with a custom one - any links to a good guide for this would be appreciated.
Next prevent keyboard shortcuts alt+f4, f5, or escape as follows:
Function Document_onKeyDown()
Dim alt
alt = window.event.altKey
Select Case window.event.keyCode
Case 27,116
window.event.keyCode = 0
window.event.cancelBubble = true
Document_onKeyDown = False
Case 115
If alt Then
window.event.keyCode = 0
window.event.cancelBubble = true
Document_onKeyDown = False
End If
Case Else
Document_onKeyDown = True
End Select
End Function
Finally I want to prevent the user using the windows taskbar context menu for my HTA app.
How can I prevent the user from seeing a context menu by right clicking my HTA?
nb. The HTA window cannot be full screen

Don't mess with a user's options to close your application. It's not up to you to decide how a user should work. Instead add a cleanup procedure where you do all the "on close" tasks and then call it on the beforeunload event:
<html>
<head>
<title>Sample</title>
<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="sample"
/>
<script language="VBScript">
Sub cleanup
'clean up stuff here
End Sub
</script>
</head>
<body onbeforeunload="cleanup">
...
</body>
</html>

With regards:
How can I prevent the user from seeing a context menu by right clicking my HTA?
<HTA:APPLICATION contextMenu="no">

<HTA:APPLICATION showintaskbar="no">

Related

How to control the size and position of the window used by navigator.bluetooth.requestDevice?

Ref this issue: How to make the Web Bluetooth Pair button work when run as chrome app
In my tests, the window which pops up when navigator.bluetooth.requestDevice is called is quite large, covers the html window from which it was invoked completely and the bottom of the window, containing the Pair and Cancel buttons are off the bottom of the screen and so not visible.
Is it possible to control and position of the requestDevice window?
<html>
<head>
<script type="text/javascript" src="bluetoothle.js"></script>
<script type="text/javascript" src="popup.js"></script>
</head>
<body>
<h1>Hello Bluetooth</h1>
<h2>Device Discovery</h2>
<button id="btn_discover">Discover Devices</button>
<div id="devices"></div>
</body>
</html>
navigator.bluetooth.requestDevice(options)
.then(device => {
console.log('> Name: ' + device.name);
console.log('> Id: ' + device.id);
console.log('> Connected: ' + device.gatt.connected);
bluetoothle.selected_device = device;
console.log(bluetoothle.selected_device);
})
.catch(error => {
console.log('ERROR: '+ error);
});
No, there is no way to control the size of the device chooser window that requestDevice() opens. It will use a fixed maximum size. (I don't have those dimensions on hand while writing here.) chrome.app.window can be opened maximized to work around this in the short term.
(Also, while there may be reasons to develop a chrome app or to retrofit web bluetooth into a previous one, if you haven't seen that Chrome Apps are being deprecated on Windows, macOS, Linux, you should read the announcement.)
It looks like https://bugs.chromium.org/p/chromium/issues/detail?id=751819 has been filed to investigate this issue.

Display loading gif before the page appears

First of all I'm a complete beginner when it comes to VBscripts.
I have only one asp file written in VB that starts a batch file.
The thing is that I want something that indicates that the page is loading like a gif. The batch takes almost 10 minutes to run and what I get is a blank page until it is finnished.
This is my entire code
<%# Language = VBScript %>
<HTML>
<script runat="server" language=VBScript>
' The batch file is running here
Dim myExecutor
Dim commandline
commandline = "cmd.exe /c C:\test.bat "
Set myExecutor = Server.CreateObject("WScript.Shell")
myExecutor.Run commandline,0,true
Set myExecutor = Nothing
Response.Write "The batch run is finnished <p> "
</script>
<body>
The batch is loading. <!--renders after batch is finnished :/ -->
</body>
</HTML>
I tried to run an onclick event <asp:Button Text="Click here" OnClick="run_batch" runat="server"/> but gives me a 500 page error when i use the sender As Object, e As EventArgs as parameters probably because I dont have the classes and only runns everything in one asp file.
Thanks.
The problem is that your code will execute as soon as the page loads. Define what you want to do as a Sub and call that in the onload event handler. The event will fire once everything on the page is loaded.
I tested the following in an hta and it works. Not sure how well it converts to asp.
<HTML>
<script language=VBScript>
sub DoStuff()
document.Write "<p>Doing stuff </p>"
CreateObject("WScript.Shell").Run "ping localhost",0,true
document.Write "<p>The batch run is finished <p> "
end sub
</script>
<body onload="DoStuff()">
</body>
</HTML>
Alternatively for a button approach just use
<button onclick="DoStuff()"> Do Stuff </button>

Prevent Exit On All Click Events With Google Swiffy

We have a 300x250 banner with 3 click events.
First click event will activate a lever.
Second click event is a CTA (i.e. exit event) that takes the user to a URL.
Third click event is the replay icon.
The issue is that every click will take the user to the URL (i.e. exit event).
How can I separate each click event? Is it done within Flash? Or after the Swiffy conversion (i.e. within the HTML/JS)?
Does this have anything to do with bubbling? Or is it that the exit event is somehow being tied to every click?
I thought about having the clicks timed but that screws up the whole experience.
I've tried stopPropigation but it prevents the add from working. Also, I don't want the first click to be stopped. It still needs to work accordingly.
HTML
<div id="bg-exit">
<div id="swiffycontainer" style="width: 300px; height: 250px">
<script type="text/javascript" src="test.js"></script>
</div>
JS
var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),
swiffyobject, { });
stage.start();
function bgExitHandler(e) {
Enabler.exit('Background Exit');
}
document.getElementById('bg-exit').addEventListener('click', bgExitHandler, false);

VB6 usercontrol Raise Event, how to catch the event in VBSCRIPT?

I am trying to catch an event in the VBSCRIPT of an html page but I can't make it work. I must have missed a step.
This is the code of my usercontrol (VB6):
Public Event sendText(ByVal Text As String)
Private Sub Command1_Click()
RaiseEvent sendText(Text1.Text)
End Sub
And this is the code of my web page (HTML):
<form>
<OBJECT name="ActiveX" id="ActiveX" classid="clsid:..."></OBJECT>
<script language="VBScript">
Sub ActiveX_sendText(Text)
Msgbox("aaa" & Text)
End Sub
</script>
</form>
The Event is raised in the user control when clicking the Command1 button, but I never get into the VBSCRIPT function.
I am using IE8/IE8 Standard.
Any clue?
It was a problem in the configuration of security rules in Internet Explorer. After enabling unsigned ActiveX, the issue was solved.

Correct usage of VBScript's MsgBox

I require to display some text in the browser with some words in between as links. On click of the links I want to display a pop up dialog with just some text and an OK button.
I want the title of the Pop up dialog to be changeable via code and also the icon to be the information icon. I use a JavaScript alert box which always has a heading of pop up as "Message from web page".
I think it can done using VBScript. What is the correct usage of VBScript? PFB the sample using JavaScript, I need this to be tweaked, so that VBScript is used and MsgBox is used.
<html>
<head>
<script type="text/javascript">
fucntion(test){
alert(test)
}
</script>
</head>
<body>
This is my link which
you can click on for definition.
</body>
</html>
This works fine. 64 is for the information icon and OK button. But I not able to get rid of "vbscript:" which is present at the start of the title. I am not sure why it is like that.
<html>
<head>
<script type="text/vbscript">
Function myPopUp(test)
MsgBox test, 64, "My Custom Title"
End Function
</script>
</head>
<body>
This is my <a href="#" language="vbscript" onclick="myPopUp('How are you do
today')">link</a> which
you can click on for definition.
</body>
</html>

Resources