Jump to content

Recommended Posts

Posted

OK I am trying out some HTA scripting for a program I am writing. I need the ability to launch a program from a hidden control. Everything works, but the application closes immediately after opening it. However, if I put this action on a input button, it works fine.

Here is a working code example:

<script LANGUAGE="VBScript">Sub RunRestart
Set objShell = CreateObject("WScript.Shell")
objShell.Run "fscommand\restart.exe"
On Error Resume Next
Set objShell = Nothing
End Sub</SCRIPT>
<body>
<input id=runbutton style="width:153" class="button" type="button" value="Restart" name="restart_button" onClick="RunRestart">
</body>

Here is a non-working example

<script LANGUAGE="VBScript">Sub RunAdmin
Set objShell = CreateObject("WScript.Shell")
objShell.Run "fscommand\admin.exe"
On Error Resume Next
Set objShell = Nothing
End Sub</script>
<body><button id=runbutton style="width:0" class="button" type="hidden" value="Admin Prompt" accessKey="k" name="admin_button" onClick="RunAdmin"></body>

The main differences is that the working example uses an input object, while the other uses a button object. Setting the width to zero effectively hides the button. AccessKey allows me to use a keyboard shortcut to launch the program. If I change the onClick value in the "restart_button" object, the program launches properly.

What do you supposed is causing this behaviour?


Posted
Setting the width to zero effectively hides the button.

what about display:none or visibility:hidden rather than specifying a 0 width.

Posted

I'm thinking that this isn't working for me because I am testing it in VirtualBox. I will save this issue and check it when i recompile my source and test it on a live pc again.

Posted

I think there's a very basic reason for your problem, buttonObject.type can be set to either "submit", "button" or "reset" and you have it set to "hidden"!

'Test run, use Alt-k to run the script from the hta

<script language="vbscript">
Sub RunAdmin
CreateObject("WScript.Shell").Run "fscommand\admin.exe"
End Sub
</script>
<body>
<button id=runbutton style="width:0" class="button" type="button" value="Admin Prompt" accesskey="k" name="admin_button" onClick="RunAdmin">
</body>

Posted

I got this code from a webpage that I can't find right now. See my original command used the input object, but just this one used button. This is because I can assign a hotkey to button and not to input.

Posted

That shouldn't make any difference, you can use accesskey with input as well as button:

'Test run, use Alt-k to run the script from the hta

<script language="vbscript">
Sub RunAdmin
CreateObject("WScript.Shell").Run "fscommand\admin.exe"
End Sub
</script>
<body>
<input id=runbutton style="width:0" class="button" type="button" value="Admin Prompt" accesskey="k" name="admin_button" onClick="RunAdmin">
</body>

Posted

This worked using the Button Object.

<!--
Test Run Alt And K key
-->
<TITLE>Test Hta Access key</TITLE>
<script language="VBScript">
Sub RunAdmin
' CreateObject("Wscript.Shell").Run("fscommand\admin.exe"),1,true
alert "Test Alt And K"
End Sub</script>
<BODY>
<BUTTON
ID='RunButton'
Style='width:0;'
class='button'
value='Admin Promp'
accesskey='k'
onClick='RunAdmin'>
</BUTTON>
</BODY>

Posted

Yes I think I have the code down. It seems to work either with button or input objects. The symptom I am having now is that the program it launches does not stay open. I was testing in VirtualBox, and I think this is an issue. Nevertheless, this post has allowed me to clean up my code a bit at least.

Posted
The symptom I am having now is that the program it launches does not stay open.

If your object is being run like the example below

CreateObject("WScript.Shell").Run "fscommand\admin.exe"

Then change it to this to keep the program open

CreateObject("Wscript.Shell").Run("fscommand\admin.exe"),1,true

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...