VBScript works as .VBA not as .HTA

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
creetar
Posts: 5
Last visit: Tue Aug 11, 2009 11:36 pm

VBScript works as .VBA not as .HTA

Post by creetar »

Hi,

I want to read a Registry Key.

First I add this into my registry

Code: Select all

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumps]
"DumpCount"=dword:00000100
This saved as .VBS works just fine, popup with 256

Code: Select all

Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Popup WSHShell.regread("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpsDumpCount")
But this, saved as .HTA which is basically the same, says root invalid

Code: Select all

<script language="VBScript">
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Popup WSHShell.regread("HKLMSOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpsDumpCount")
</script>
The HTA fails on Vista 64-bit, but works on Vista 32-bit.

What is the problem?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript works as .VBA not as .HTA

Post by jvierra »

Change to:

Code: Select all

<script language="VBScript">
Sub window_onload  
     Dim WSHShell  
    Set WSHShell = CreateObject("WScript.Shell")  
     WSHShell.Popup WSHShell.regread("HKLMSOFTWAREMicrosoftWindowsWindows ErrorReportingLocalDumpsDumpCount")
End Sub
</script>

The window executes this before it is ready unless you tell it to execute in teh "window_onload" procedure which occurs after teh windows has been built and displayed.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript works as .VBA not as .HTA

Post by jvierra »

If you don't put the code in the onload procedure it will only work intermittently. Look at teh DHTML and IE/HTA Windows specs. It is very clear that any code short of simple assignment must be plaxced inside of a procedure or an event. If this is not done then the code will fail occasionally. Search MS KB and you willfind numerous examples.

Of course you may have made a typo when translating th first time. I find with IE7 and later on XP that code not in a procedure will normally execute correctly nearly all of the time. On Windows 2003 and on Vista or on a very busy XP system it will fail.


Do yourself a favor by placing code in procedure.

Here is an laternate method that globalizes the object allowing it to be initialized only once.

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>My HTML Application</title>
<script language="vbscript">
Dim wshShell, regval
Sub window_onload()    
    Set WSHShell = CreateObject("WScript.Shell")        
    regval= WSHShell.regread("HKLMSOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpsDumpCount")        
    test.innerHTML = regval 
End Sub
    
</script>
</head>
    <body>
        <div id="test"></div>
        <input type="button" value="GetReg" onclick="MsgBox regval,,'DumpCount'" />
    </body>
</html>

You cannot drag and drop from messagebox or popup so I don't know how you expect to accomplish that. You can assign value to display control and copy and paste from there.

jvierra2009-05-11 13:14:20
User avatar
creetar
Posts: 5
Last visit: Tue Aug 11, 2009 11:36 pm

VBScript works as .VBA not as .HTA

Post by creetar »

I use IE6 at home and IE8 on the machine where it's not working.So I assume there is no workaround with .HTA and the best methodis using a .VBS and create a HTML-file with it for the report?Like VBS => get key, create HTML file with key displayed, open file
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript works as .VBA not as .HTA

Post by jvierra »

So I assume there is no workaround with .HTA and the best methodis using a .VBS and create a HTML-file with it for the report?


Why can't you use the onload event. That will work in all versions of IE and MSHTA.

I don't think you are understanding why you need to use the window_onload event.

Why can't you cut and paste from a CMD prompt?
Why not output to a file?

Put the output in a DIV, SPAN or TABLE and it can be cut and pasted easily.

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript works as .VBA not as .HTA

Post by jvierra »

Each "onload" method is called in turn. The window_onload is called first then body then each object in body and so on.

You problem is that you are trying to call a popup messagebox. This will stop all processing as soon as it is called. It effectively aborts processing by diverting teh flow of events.

You should run everything in the body onload or run everything in window_onload but use no popups. In Window_onload assign output to a div like in my example.

If you are trying to scatter gather info then you can assign it to controls on body as you get info in onload of windows and/or body.

YOu should not have trouble with CSDVersion but cannot run that code outside of an event or it will not behave correctly.

User avatar
creetar
Posts: 5
Last visit: Tue Aug 11, 2009 11:36 pm

VBScript works as .VBA not as .HTA

Post by creetar »

Hey,I'm now in my office and I try exactly the code you provided and it's not working, same message appears "invalid root".So the onload wasn't the problem, its a security issue probably.Sad that there is no way to produce a layout with vbscriptThanks for your help though :)
User avatar
creetar
Posts: 5
Last visit: Tue Aug 11, 2009 11:36 pm

VBScript works as .VBA not as .HTA

Post by creetar »

i think it was because the HTA has lower rights then the VBS.I use now a VBS to create a HTA in the Temp-Folder, that works.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

VBScript works as .VBA not as .HTA

Post by rasimmer »

If someone would like to share some code, a HTA has the ability to do anything a VBS can do plus provide a HTML front-end.
User avatar
creetar
Posts: 5
Last visit: Tue Aug 11, 2009 11:36 pm

VBScript works as .VBA not as .HTA

Post by creetar »

<HTML><HEAD><HTA:APPLICATION ID='App Name' SingleInstance='Yes' MaximizeButton='No' ScrollFlat ='Yes' Caption='Yes' WindowState='Normal' ApplicationName='App Name' Icon='%Windir%explorer.exe'><TITLE>QA FileVerification</TITLE><STYLE Type='text/css'> table { border-top: solid 1px black; border-left: solid 1px black; border-bottom: 2px solid black; border-right: 2px solid black; } table, div { width: auto; } body { Text-Align:Center; Vertical-Align:Top; Color:#000020; BackGround-Color:Transparent; Filter:progid:DXImageTransform.Microsoft.Gradient (StartColorStr='#fdf7f1',endColorStr='#a6a29e'); } div, td, th, body { font-size: 8pt; font-family: Arial;} td, th { text-align: left; border: 1px solid black; padding-right: 1px; padding-left: 1px; background-color: white;} .g { background-color: black; color: white; border: 1px solid black; } .h { background-color: #dddddd; } .d { background-color: #efefef; }</STYLE><SCRIPT Language='VBScript'> vb stuff, to access an html element just write like report_div.innerHTML = "meow"</SCRIPT></HEAD><BODY Scroll='yes' onLoad="Main()"><b><u>AppName</u></b><br><hr color="black" size="1" noshade><p><div id='report_div' name='report_div'></div></p><hr color="black" size="1" noshade></BODY></HTML>
This topic is 14 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked