Tripredacus Posted April 28, 2009 Share Posted April 28, 2009 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 = NothingEnd 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 = NothingEnd 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? Link to comment Share on other sites More sharing options...
iamtheky Posted April 28, 2009 Share Posted April 28, 2009 Setting the width to zero effectively hides the button. what about display:none or visibility:hidden rather than specifying a 0 width. Link to comment Share on other sites More sharing options...
Tripredacus Posted April 29, 2009 Author Share Posted April 29, 2009 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. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 29, 2009 Share Posted April 29, 2009 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> Link to comment Share on other sites More sharing options...
Tripredacus Posted April 29, 2009 Author Share Posted April 29, 2009 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. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 29, 2009 Share Posted April 29, 2009 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> Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 30, 2009 Share Posted April 30, 2009 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> Link to comment Share on other sites More sharing options...
Tripredacus Posted May 1, 2009 Author Share Posted May 1, 2009 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. Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 1, 2009 Share Posted May 1, 2009 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 belowCreateObject("WScript.Shell").Run "fscommand\admin.exe"Then change it to this to keep the program openCreateObject("Wscript.Shell").Run("fscommand\admin.exe"),1,true Link to comment Share on other sites More sharing options...
Tripredacus Posted May 19, 2009 Author Share Posted May 19, 2009 Update: the problem I had with launching the program was with the program itself, not the HTA. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now