How do I run a .bat file (onload) from an .hta (HTML application)?

I am building a type of interface for a script and need the .hta interface to load this script when it starts. Therefore I will run the Screen.hta and it must run the script called Startup.bat. Everything is in the same root folder. Also, where do I place the snippet in the below script for it to execute correctly? I have looked everywhere on the net and tried several examples but could not get it to work.

<html>
<head>
<HTA:APPLICATION
     ID="objScreen" 
     APPLICATIONNAME="Screen" 
     BORDER="none" 
     BORDERSTYLE="normal" 
     CAPTION="no" 
     ICON="" 
     MAXIMIZEBUTTON="no" 
     MINIMIZEBUTTON="no" 
     SHOWINTASKBAR="yes" 
     SINGLEINSTANCE="yes" 
     SYSMENU="no" 
     SCROLL="no" 
     VERSION="1.0" 
     CONTEXTMENU="no" 
     WINDOWSTATE="maximize"
     INNERBORDER="no"/> 




</head>



<SPAN
   STYLE="
      top: 203;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 263;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 323;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 383;
      left: 572;
      width: 20px;
      height: 20px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 443;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 503;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 563;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>





<Script Language="VBScript"> 

   Sub Window_OnLoad 
      ' Size and position main window
      window.resizeTo 1366,768 
      window.moveTo 0,0

      ' Display current time
      myClock.innerText = Now()

      ' Set up a timer event so we can update the screen periodically
      iTimerID = window.setInterval("myVBSClock", 1000) 
   End Sub    

   Sub myVBSClock 
      ' Update current time
      myClock.innerText = Now()

      ' Refresh colors from status file
      CheckStatusFile
   End Sub 

   Function ComputerName()
      ' Get computername
      Set wshShell = CreateObject("WScript.Shell")
      ComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
      Set wshShell = Nothing
   End Function

   Sub CheckStatusFile
      ' Constants for file I/O
      Const ForReading = 1
      Const ForWriting = 2
      Const TriStateUseDefault = -2

      ' Name of status file
      strStatusFile = "Status.txt"

      ' Create file system object
      Set objFSO = CreateObject("Scripting.FileSystemObject")

      ' Make sure status file exists
      If objFSO.FileExists(strStatusFile) Then
         ' Open it for reading
         Set objStatusFile = objFSO.OpenTextFile(strStatusFile, ForReading, False, TriStateUseDefault)
         ' Read status file, slit lines into array elements
         arrStatus = Split(objStatusFile.ReadAll, vbCrLf)
         ' Close file, release objects
         objStatusFile.Close
         Set objStatusFile = Nothing
         Set objFSO = Nothing

         ' Process each line of the status file (skip blank lines)
         For Each strStatus in arrStatus
            If strStatus <> "" Then
               ' Split status line into array at comma
               arrField = Split(strStatus, ",")
               ' Process lines based on first field on line (item name to update), and set item color to status file value
               Select Case arrField(0)
                  Case "Security-Environment"
                     SecurityEnvironment.style.background = arrField(1)
                  Case "Help-Menu"
                     HelpMenu.style.background = arrField(1)
                  Case "Biometric-License"
                     BiometricLicense.style.background = arrField(1)
                  Case "Card-Printer"
                     CardPrinter.style.background = arrField(1)
                  Case "GPS-Device"
                     GPSDevice.style.background = arrField(1)
                  Case "Battery-Controller"
                     BatteryController.style.background = arrField(1)
                  Case "Biometric-Application"
                     BiometricApplication.style.background = arrField(1)
               End Select
            End If
         Next 
      End If
   End Sub

</SCRIPT> 


<BODY
     BACKGROUND="bgimageV3.jpg"
     TOPMARGIN="10"
     RIGHTMARGIN="10"
     LEFTMARGIN="10"
     BGCOLOR="#7e7e7e"> 

<SPAN
   id="SecurityEnvironment"
   style="
      top: 200;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
SECURITY ENVIRONMENT
</SPAN>

<SPAN
   id="HelpMenu"
   style="
      top: 260;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
HELP MENU
</SPAN>

<SPAN
   id="BiometricLicense"
   style="
      top: 320;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BIOMETRIC LICENSE
</SPAN>

<SPAN
   id="CardPrinter"
   style="
      top: 380;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
CARD PRINTER
</SPAN>

<SPAN
   id="GpsDevice"
   style="
      top: 440;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
GPS DEVICE
</SPAN>

<SPAN
   id="BatteryController"
   style="
      top: 500;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BATTERY CONTROLLER
</SPAN>

<SPAN
   id="BiometricApplication"
   style="
      top: 560;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BIOMETRIC APPLICATION"
</SPAN>

<SPAN
   style="
      top: 650;
      left: 50;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      text-align: left;
      color: fa8b0f;
      font-family: Arial;
      font-size : 60;
      visibility: show;">
<script type="text/javascript"> document.write(computername());</script>
</SPAN>

<SPAN
   style="
      top: 670;
      left: 515;
      width: 570px;
      height: 40px;
      position: absolute;
      z-index: 1;
      text-align: left;
      color: white;
      font-family: Arial;
      font-face : Arial;
      font-size : 25;
      font-weight: bold;
      visibility: show;">
<font color="white"><PRE ID=myClock></font>
</SPAN>






</BODY> 
</HTML>

Open in new window

Rebel_no_1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel AdebayoGlobal Windows Infrastructure Engineer - ConsultantCommented:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe 'C:\Startup.bat.bat'"

Please this before </head>

Also, you can place your starup.bat anywere as longa s you reference it correctly in your script above.
0
Bill PrewCommented:
Give this a try.

<html>
<head>
<HTA:APPLICATION
     ID="objScreen" 
     APPLICATIONNAME="Screen" 
     BORDER="none" 
     BORDERSTYLE="normal" 
     CAPTION="no" 
     ICON="" 
     MAXIMIZEBUTTON="no" 
     MINIMIZEBUTTON="no" 
     SHOWINTASKBAR="yes" 
     SINGLEINSTANCE="yes" 
     SYSMENU="no" 
     SCROLL="no" 
     VERSION="1.0" 
     CONTEXTMENU="no" 
     WINDOWSTATE="maximize"
     INNERBORDER="no"/> 




</head>



<SPAN
   STYLE="
      top: 203;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 263;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 323;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 383;
      left: 572;
      width: 20px;
      height: 20px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 443;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 503;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>
<SPAN
   STYLE="
      top: 563;
      left: 572;
      width: 42px;
      height: 43px; 
      position: absolute;
      z-index: 1;
      background-image: url('Busy.gif');
      visibility: show;">
</SPAN>





<Script Language="VBScript"> 

   Sub Window_OnLoad 
      ' Size and position main window
      window.resizeTo 1366,768 
      window.moveTo 0,0

      ' Display current time
      myClock.innerText = Now()

      ' Set up a timer event so we can update the screen periodically
      iTimerID = window.setInterval("myVBSClock", 1000)

      ' #####################################################
      Set WshShell = CreateObject("WScript.Shell")
      WshShell.Run "cmd.exe /c ""Startup.bat"""
      Set WshShell = Nothing
      ' #####################################################

   End Sub    

   Sub myVBSClock 
      ' Update current time
      myClock.innerText = Now()

      ' Refresh colors from status file
      CheckStatusFile
   End Sub 

   Function ComputerName()
      ' Get computername
      Set wshShell = CreateObject("WScript.Shell")
      ComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
      Set wshShell = Nothing
   End Function

   Sub CheckStatusFile
      ' Constants for file I/O
      Const ForReading = 1
      Const ForWriting = 2
      Const TriStateUseDefault = -2

      ' Name of status file
      strStatusFile = "Status.txt"

      ' Create file system object
      Set objFSO = CreateObject("Scripting.FileSystemObject")

      ' Make sure status file exists
      If objFSO.FileExists(strStatusFile) Then
         ' Open it for reading
         Set objStatusFile = objFSO.OpenTextFile(strStatusFile, ForReading, False, TriStateUseDefault)
         ' Read status file, slit lines into array elements
         arrStatus = Split(objStatusFile.ReadAll, vbCrLf)
         ' Close file, release objects
         objStatusFile.Close
         Set objStatusFile = Nothing
         Set objFSO = Nothing

         ' Process each line of the status file (skip blank lines)
         For Each strStatus in arrStatus
            If strStatus <> "" Then
               ' Split status line into array at comma
               arrField = Split(strStatus, ",")
               ' Process lines based on first field on line (item name to update), and set item color to status file value
               Select Case arrField(0)
                  Case "Security-Environment"
                     SecurityEnvironment.style.background = arrField(1)
                  Case "Help-Menu"
                     HelpMenu.style.background = arrField(1)
                  Case "Biometric-License"
                     BiometricLicense.style.background = arrField(1)
                  Case "Card-Printer"
                     CardPrinter.style.background = arrField(1)
                  Case "GPS-Device"
                     GPSDevice.style.background = arrField(1)
                  Case "Battery-Controller"
                     BatteryController.style.background = arrField(1)
                  Case "Biometric-Application"
                     BiometricApplication.style.background = arrField(1)
               End Select
            End If
         Next 
      End If
   End Sub

</SCRIPT> 


<BODY
     BACKGROUND="bgimageV3.jpg"
     TOPMARGIN="10"
     RIGHTMARGIN="10"
     LEFTMARGIN="10"
     BGCOLOR="#7e7e7e"> 

<SPAN
   id="SecurityEnvironment"
   style="
      top: 200;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
SECURITY ENVIRONMENT
</SPAN>

<SPAN
   id="HelpMenu"
   style="
      top: 260;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
HELP MENU
</SPAN>

<SPAN
   id="BiometricLicense"
   style="
      top: 320;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BIOMETRIC LICENSE
</SPAN>

<SPAN
   id="CardPrinter"
   style="
      top: 380;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
CARD PRINTER
</SPAN>

<SPAN
   id="GpsDevice"
   style="
      top: 440;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
GPS DEVICE
</SPAN>

<SPAN
   id="BatteryController"
   style="
      top: 500;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BATTERY CONTROLLER
</SPAN>

<SPAN
   id="BiometricApplication"
   style="
      top: 560;
      left: 47;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      background: grey;
      border-color: #000000;
      border-style: solid;
      border-top-width: 1px;
      border-bottom-width: 1px;
      border-left-width: 1px;
      border-right-width: 1px;
      text-align: left;
      color: white;
      font-family: Arial;
      font-size : 40;
      visibility: show;">
BIOMETRIC APPLICATION"
</SPAN>

<SPAN
   style="
      top: 650;
      left: 50;
      width: 570px;
      height: 40px; 
      position: absolute;
      z-index: 1;
      text-align: left;
      color: fa8b0f;
      font-family: Arial;
      font-size : 60;
      visibility: show;">
<script type="text/javascript"> document.write(computername());</script>
</SPAN>

<SPAN
   style="
      top: 670;
      left: 515;
      width: 570px;
      height: 40px;
      position: absolute;
      z-index: 1;
      text-align: left;
      color: white;
      font-family: Arial;
      font-face : Arial;
      font-size : 25;
      font-weight: bold;
      visibility: show;">
<font color="white"><PRE ID=myClock></font>
</SPAN>






</BODY> 
</HTML>

Open in new window

( edit: corrected typo on the following line: Set WshShell = Nothing )

~bp
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rebel_no_1Author Commented:
Thank you. This launches a .bat that I can use during testing. The final thing will most probably run a "compiled" .exe. May I ask so long, how would I run a Startup.exe instead of the Startup.bat?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Rebel_no_1Author Commented:
I might be accused of moving the goal posts now.... :-)
0
Bill PrewCommented:
To run an EXE you do not need the CMD.EXE processor, that is just for BAT files.  So you should be able to do:

WshShell.Run """Startup.exe"""

If there are no spaces in the EXE path that you are specifying, then you can get away with:

WshShell.Run "Startup.exe"

Also, you likely want to wait for the EXE to finish before continuing, but maybe not.  The defauly is not to wait for it to finish, but there is a parm on the .RUN method to controil this, docs at https://msdn.microsoft.com/en-us/subscriptions/d5fk67ky%28v=vs.84%29.aspx

~bp
0
Bill PrewCommented:
Also, it's your question to manage, but be aware there were some issues with the solution in http:#a41117746 that you also accepted.  I don't think the single quotes will work, and it started the wrong bat file name.  Also, I don't think it will work without either /C or /K option on the CMD execution.  Just clarifying for future readers, if you tested and it worked then let me know and I'll correct this post.

~bp
0
Rebel_no_1Author Commented:
I am guilty. I did not test both solutions as I should've. I just tested the last one and went with your solution Bill. Then when I wanted to assign the points I realized there was an answer before you which to my untrained eye seemed to also be correct. I thought splitting the points would be fair but in hindsight it was not as the solution did not work. Therefore it's my mistake, sorry.
0
Rebel_no_1Author Commented:
(Just for the record; there was a spelling mistake in your solution as well Bill) "Sheel" I corrected that before I tested.
0
Bill PrewCommented:
@Rebel_no_1

Thanks, I edited the post, and noted the edit at the bottom, after the code, for benefit of future readers...

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.