I have a HTA file containing javascript executed on load to pull the users network logon:
var WinNetwork = new ActiveXObject("WScript.Network");
return WinNetwork.UserName;
When I first open the HTA file, I receive a runtime error:
"The automation server can't create object"
on the first line of code above. I dismiss the error and close the HTA window.
If I then re-launch the HTA file within a few seconds of closing, it works without error and I get the UserName value. If I leave it for a few minutes and launch it again, the error returns. I have been able to repeat these outcomes every time I have tried.
Does anyone know why this doesn't work the first time? And how I might resolve it? Thanks
Edit: Thank you for your answers so far, but this is a HTA and is not run in IE, security settings are not relevant.
from https://en.wikipedia.org/wiki/HTML_Application: An HTML Application (HTA) is a Microsoft Windows program whose source code consists of HTML, Dynamic HTML, and one or more scripting languages supported by Internet Explorer, such as VBScript or JScript. The HTML is used to generate the user interface, and the scripting language is used for the program logic. An HTA executes without the constraints of the internet browser security model; in fact, it executes as a "fully trusted" application.