How hta Changed the Way I Deliver Builds - Part 14 - Enable Button by Username

The other day we looked at how to kill the build by adding a button that will delete the appl.cfg files. The only problem with this is that once you've added it to the hta, everyone can kill it and we all know how users love to find ways of working around things they don't like.

Well, we can set up hta kill button so that it is only available to a few users.

To the 'Sub Window_onload' we can add:

If GetUsername = "Sean.Forward" Then
killbutton.disabled=False
else
killbutton.disabled=True
End IF

the 'GetUsername' function can be elsewhere in the hta and looks like:

'------------------------------------------------------------------------------------------
' GetUserName 
'------------------------------------------------------------------------------------------
Function GetUserName()
GetUserName = objShell.ExpandEnvironmentStrings("%USERNAME%")
End Function

Set this up for each user that needs access to the Kill button and you've made it a much safer button to use. Get a little inventive and set up a 'group' environment variable that the hta can user and you can start to lock out buttons based on the users group.

More soon.

Anonymous