...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.



Custom HTAs and Command Line Arguments

Wednesday, February 06, 2013 in Technical Articles (Views: 4576)
For those who had/are having an issue with this, here's a quick and easy way to add command line support for your hta file. This is one way to keep away from using multiple HTAs based on where you are in a Task Sequence.

A few things of note:
- The Window_onLoad Sub is built into mshta. If this is present, the code is run.
- Below, I am using HTA.Commandline. The "HTA" comes from the ID field in the body of the HTA doc. i.e. this: HTA:Application ID = "HTA"
- The command line is looking for YOURARG, which is capitalized to remove case sensitivity. If it finds this, the checkbox is enabled. Otherwise, the checkbox is disabled. For some reason, this works backwards of normal VB, which is .Enabled = "True", rather than .Disabled = "False", achieving the same result.
- Note the parsing of the command line needed the split. So the argument to "mshta.exe myhta.hta YOURARG" would net the argument of "myhta.hta YOURARG", so I ran a split against the space.

Example code:

Sub Window_onLoad
if split(ucase(HTA.Commandline)," ")(1) <> "YOURARG" then
YourCheckbox.Disabled = "True"
YourCheckbox.Disabled = "False"
End If
End Sub

Happy HTA Scripting.


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.