VBScript -  Can I convert MSGBox prompts into Radio Buttons or Dropdown Menus?

Posted on 2009-05-20
Last Modified: 2012-05-07

I have a script that peforms the followings:
1. Pops a messagebox up that displays a list of groups that are found in a folder, and has the customer type a corresponding numnber in the message box.
2.  Depending on the answer, go to the particualr start folder and prompts them for the particular sub group that are found within that group
3.  Once that data is set is asked them whether they want to backup or restore.  And then either creates or accesses a backupfolder that is created from the first two response.

Everything works perfectly, but it is that user friendly.  Is there way that I can have thos prompts converted to either drop-down menus or Radio buttons on the .hta screen that I have calling the .vbs script?  If I were able to have the same functionality and be able to read the information into the script the same way that would be perfect.
Question by:aceklub97
  • 4
  • 3
  • 2
LVL 14

Expert Comment

Comment Utility
LVL 14

Expert Comment

Comment Utility
LVL 65

Expert Comment

Comment Utility
You can embed the script into the HTA, and instead of reading the InputBox values, you just use something like
strGroup = lst_groups.Value

to read which group name has been selected from a list box.

Perhaps if you post the scripts (the HTA and VBS) we could help you combine them.



Author Comment

Comment Utility

1. I have attached to porttion of the code that I need to read the information.  I didn't include the core part of the script because it is just copying files.
2.  I have included the .hta file that I have.  It is realatively simple.  I would like to be able to have the customer select a. There business group, and then b. the name of their trainer, and c.  Whether they want to backup or restore.

If you need any more information, please let me know
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

LVL 65

Expert Comment

Comment Utility
OK, I've changed the HTA a bit, to include the drop down and radio boxes, but currently, when you click Start, nothing happens.  You'll need to copy in the code from the VBS that actually does the operation based on the folders and values.  At the moment, you select your options, then click Start, and it just outputs what you've selected.  Once you're happy with that, you can add your code below this line

        'tmrExternal = window.setInterval("tmrExternal_timer", 1000, "VBScript")      

to have it perform additional steps based on the values selected.

I hope this helps so far.





    Nationwide Services Company - Training Room Data Migration Tool


  <link href="\\\scripts\Backup\nwlogo.ico" type="text/css" rel="stylesheet">

  <HTA:application scroll=no>


    div.clsIndent {margin-left: 30px}

    div.clsIndentRed {margin-left: 30px; color: red}


  <SCRIPT language=VBScript>

    Option Explicit

    Const WshRunning = 0

    Const WshFinished = 1

    Dim wshShell

    Dim wseExternal

    Dim tmrExternal

    Dim strComputer

    Dim objWMIService

    Dim colItems

    Dim intHorizontal

    Dim intVertical

    Dim objExplorer

    Dim colServices

    Dim intServices

    Dim intIncrement

	Dim strBackupStartFolder

	Dim strParentFolder

	Dim strHTML

	Dim objFSO

	Dim strLOBFolder

	Dim objSubFolder

	Dim backupOrRestoreResponse

    Sub cmdStart_onclick()

		'On Error Resume Next

		'Set wseExternal = _

		'  wshShell.Exec("Wscript.exe //NOLOGO \\\scripts\Backup\nss_Backup.vbs")

		'If Err.number <> 0 Then

		'  lblStatus.innerText = "Failed to start!"



		If optBackupOrRestore(0).Checked = True Then

			backupOrRestoreResponse = 0

		ElseIf optBackupOrRestore(1).Checked = True Then

			backupOrRestoreResponse = 1

		End If


        lblStatus.innerText = "Your Backup/Restore is in progress.  Please do not use your keyboard or mouse ... This process could take several minutes to complete." & VbCrLf & _

        "LOB: " & cbo_LOB.Value & VbCrLf & _

        "Trainer: " & cbo_Trainer.Value & VbCrLf & _

        "Backup Or Restore: " & backupOrRestoreResponse


        cmdStart.disabled = True

        cmdReset.disabled = True

        buttonClose.disabled = True

        'tmrExternal = window.setInterval("tmrExternal_timer", 1000, "VBScript")             	       

      ' End if


End sub

'sub cmdStart_Progress()

'End sub


    Sub cmdReset_onclick()

      lblStatus.innerText = "Click the Start Button to begin the process:"

      lblResults.innerHTML = " "

      lblMore.innerHTML = ""

      cmdReset.disabled = true

      cmdStart.disabled = False

    End Sub


   'Button Close

		Sub ButtonCloseClick()

      If msgbox ("Are you sure you want to Close?",4,"Close Backup?") = vbYes then


      End if

		End Sub 

    Sub Continue()

      lblMore.innerHTML = _

          "The Data Migration process has completed.<br>" _

        & vbCrLf & "If you have just backed up your PC, please go to your new PC and run this process again, selecting '1' for restore.<P>" _

        & vbCrLf & "If you have just restored you data to the new PC, then your work is done. Please double check to make sure everything was successfully transfered.<br>" _

        & vbCrLf & "If you have any computer related issues, please call the IT Service Desk at 515-508-8515." _

        & VbCrLf & VbCrLf

    cmdReset.disabled = true

    buttonClose.disabled = false

    cmdStart.disabled = False

    End Sub

    Sub tmrExternal_timer()

      With lblStatus

        If wseExternal.Status = WshRunning Then

          If .className = "clsIndentRed" Then

            .className = "clsIndent"


            .className = "clsIndentRed"

          End If


          window.clearInterval tmrExternal

          .innerText = _

              "Finished. Exit code " _

            & CStr(wseExternal.ExitCode)

          .className = "clsIndent"

          Set wseExternal = Nothing

          window.setTimeout "Continue", 200, "VBScript"

        End If

      End With

    End Sub

    Sub window_onload()

      Set wshShell = CreateObject("WScript.Shell")


    End Sub

    Sub window_onunload()

      Set wshShell = Nothing

    End Sub


	Sub Populate_LOB

		Set objFSO = CreateObject("Scripting.FileSystemObject")

		strLOBFolder = "\\\Line_of_Business\"

		If Right(strLOBFolder, 1) = "\" Then strLOBFolder = Left(strLOBFolder, Len(strLOBFolder) - 1)

		strHTML = "<select size='1' name='cbo_lob' onchange='Populate_Trainer'" & VbCrLf

		strHTML = strHTML & "<option selected value='cbo_select_lob'> --- Select Line Of Business --- </option>" & VbCrLf

		For Each objSubFolder In objFSO.GetFolder(strLOBFolder).SubFolders

			strHTML = strHTML & "<option value='" & objSubFolder.Name & "'>" & objSubFolder.Name & "</option>" & VbCrLf


		strHTML = strHTML & "</select>"

		span_lob.InnerHTML = strHTML

   End Sub

	Sub Populate_Trainer

      	Dim boolValid

      	boolValid = True


      	strBackupStartFolder = cbo_lob.Value

		If strBackupStartFolder = "Nationwide Sales Solutions" Then

			strParentFolder = "\\\training\"

		ElseIf strBackupStartFolder = "Commercial Lines Processing Center" Then

			strParentFolder = "\\\Training_CLPC\"

		ElseIf strBackupStartFolder = "Commercial Lines Service Center" Then

			strParentFolder = "\\\Training_CSC\"					

		ElseIf strBackupStartFolder = "PLSC_Customer Service Unit" Then

			strParentFolder = "\\\Training_CSU\"

		ElseIf strBackupStartFolder = "PLSC_Exclusive Channel" Then

			strParentFolder = "\\\Training_PLSCEC\"

		ElseIf strBackupStartFolder = "PLSC_Independent Channel" Then

			strParentFolder = "\\\Training_PLSCIC\"

		ElseIf strBackupStartFolder = "Speciality Products & Boat" Then

			strParentFolder = "\\\Training_SPECPROD\"

		ElseIf strBackupStartFolder = "Des Moines Claims Call Center" Then

			strParentFolder = "\\\Training_DMCCC\"

		ElseIf strBackupStartFolder = "Claims_CLASS" Then

			strParentFolder = "\\\Training_Claims_CLASS\"


			MsgBox "You did not select a valid LOB."	


			boolValid = False

		End If


		If boolValid = True Then

			If Right(strParentFolder, 1) = "\" Then strParentFolder = Left(strParentFolder, Len(strParentFolder) - 1)


			strHTML = "<select size='1' name='cbo_trainer'" & VbCrLf

			strHTML = strHTML & "<option selected value='cbo_select_trainer'> --- Select Trainer --- </option>" & VbCrLf

			For Each objSubFolder In objFSO.GetFolder(strParentFolder).SubFolders

				strHTML = strHTML & "<option value='" & objSubFolder.Name & "'>" & objSubFolder.Name & "</option>" & VbCrLf


			strHTML = strHTML & "</select>"

			span_trainer.InnerHTML = strHTML

		End If

	End Sub



<BODY bgcolor="white">

    <img src="\\\scripts\Backup\image002.gif" alt="Go"><br><br><br><br><br><br>

  <H3>Data Migration Status:</H3>

  <DIV id=lblStatus class=clsIndent>Ready to begin</DIV>

  Select your Line of Business:

  <span id="span_lob">

	  <select size="1" name="cbo_lob">

	  	<option selected value="cbo_select_lob"> --- Select Line of Business --- </option> 



  <br>Select your Trainer:

  <span id="span_trainer">

	  <select size="1" name="cbo_trainer">

	  	<option selected value="cbo_select_trainer"> --- Select Trainer --- </option> 




	<input type='radio' name='optBackupOrRestore' value='optBackup' CHECKED> Backup<br>

	<input type='radio' name='optBackupOrRestore' value='optRestore'> Restore<br>


  <H3><span style="text-decoration:underline">Click the Start Button</span> to begin the process. <br><span style="text-decoration:underline">Click the Close Button</span> when the process has finished:</H3><br>

    <DIV id=lblMore class=clsIndent></DIV><br>


    <INPUT type=button id=cmdStart value="Start"> 

    <INPUT type=button id=cmdReset value=Reset disabled>

    <button accesskey=C id=buttonClose onclick=ButtonCloseClick><U>C</U>lose</button><br><br><br>

    <img src="\\\scripts\Backup\image001.gif" alt="Go"><br><br><br><br>


		<object classid="clsid:35053A22-8589-11D1-B16A-00C0F0283628" id="ProgressBar1" height="20" width="400">

    <param name="Min" value="0">

    <param name="Max" value="100">

    <param name="Orientation" value="0">

    <param name="Scrolling" value="1">






Open in new window


Author Comment

Comment Utility

Ok.  This make a lot of sense.  I will work on this when I get into the office today.   Just to clarify to make sure that I have what you are saying I have included the full script I have so far.

are you saying:
1. To go down through the rest of the VBscript and tranfer each "function" to a the .hta as a Sub similar to way you currently have Sub Populate_trainer?
2. I am a little confused.  Are we able to transfer all of the code to the .hta and not need the external script anymore?  Or do we still need to call both.

Thanks for the help to so far.  This coming along great.  VBS code attached.

Author Comment

Comment Utility

I am trying to include the VBSCript into  the .hta.  I am able to get all the const and variables entered in. but when I list the instance, I get a vbscript runtime error.  The orignal VBS works fine, but now when I pasted:

'GLOBAL OBJECT INSTANCES DECLARATIONS ********************************************************************

Set fso     = wscript.createobject("Scripting.FileSystemObject")
Set shell   = wscript.createobject("")
Set network = wscript.createobject("")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTrainers = CreateObject("Scripting.Dictionary")
Set objLOB = CreateObject("Scripting.Dictionary")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set WshShell = WScript.CreateObject("WScript.Shell")

I get :
An error occured in the script of this page.
Line 80
Char 1
Error Variable is undefined: "wscript"
Code 0

The line in question is, "Set fso     = wscript.createobject("Scripting.FileSystemObject")".   I don't see whats wrong.  fso is already declared as DIM

am I doing something wrong?

LVL 65

Accepted Solution

RobSampson earned 500 total points
Comment Utility
Yeah, that's an easy one....the WScript object is not availabe in a HTA, when creating objects in this manner, so all you need to do is change
Set fso     = wscript.createobject("Scripting.FileSystemObject")
Set shell   = wscript.createobject("")
Set network = wscript.createobject("")

Set fso     = createobject("Scripting.FileSystemObject")
Set shell   = createobject("")
Set network = createobject("")

as the CreateObject call works perfectly well without the WScript bit.

I don't have time at the moment to go through your whole script, but if you get stuck, let me know....



Author Closing Comment

Comment Utility
That worked out great.  Things are so much easier to manage from the .hta as opposed to the MsgBox.  Thanks for all your help.   If I could just figure out how to get a viable progress bar to run on my form, I would be golden.  I have had an open question on that one for a while now.

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 86
Custom auto number 6 51
Messed up my code 6 21
Index Match Vlook up for a master file 7 48
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now