[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Please enter a computer name (running batch file from hta)

Posted on 2009-07-01
7
Medium Priority
?
503 Views
Last Modified: 2012-08-14
Hi guys,
I currently have the following batch file that works great.

Usage is:
script.bat [computer_name]

========================================= script.bat
@echo off

if [%1]==[] (
echo useage: script [computer_name]
echo         Please enter a computer name before running.
goto :eof
)

echo Checking the following 4 services on a machine %1 .....
 
rem check_services.bat <computername>
for /f "tokens=1-6 delims=[.] " %%a in ('ping %1 -n 1 ^| find "["') do set ip=%%c.%%d.%%e.%%f
ping -n 1 %1 >nul 2>&1
if %errorlevel%==0 (
   echo %1 [%ip%]: Up
) else (
   echo %1 [%ip%]: Down
)
echo sc \\%ip% query alerter
sc \\%ip% query alerter
sc \\%ip% query browser
sc \\%ip% query server

rem ============================ end of file

What id like to do is run the same thing but just in a hta window.

=============================================== script.hta

Please enter a computer name __________________  <Go>

Output seen in the hta as if running it from command line.

===================================== end of hta

Any help greatly appreciated.
========================================= script.bat
@echo off
 
if [%1]==[] (
echo useage: script [computer_name]
echo         Please enter a computer name before running.
goto :eof
)
 
echo Checking the following 4 services on a machine %1 .....
 
rem check_services.bat <computername>
for /f "tokens=1-6 delims=[.] " %%a in ('ping %1 -n 1 ^| find "["') do set ip=%%c.%%d.%%e.%%f
ping -n 1 %1 >nul 2>&1
if %errorlevel%==0 (
   echo %1 [%ip%]: Up
) else (
   echo %1 [%ip%]: Down
)
echo sc \\%ip% query alerter
sc \\%ip% query alerter
sc \\%ip% query browser
sc \\%ip% query server
 
rem ============================ end of file

Open in new window

0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 3

Expert Comment

by:astroviper
ID: 24759652
Using: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Q_20709676.html

Have script.bat in the same location as the hta.

<html>
<head>
<HTA:APPLICATION ID="oHTA"
      VERSION="1.0"
     APPLICATIONNAME="BatchFile"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     CONTEXTMENU="no"
     ICON=""
     INNERBORDER="yes"
     MAXIMIZEBUTTON=no"
     MINIMIZEBUTTON="no"
     NAVIGABLE="yes"
     SCROLL="no"
     SCROLLFLAT="yes"
     SELECTION="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="yes"
     SYSMENU="yes"
     WINDOWSTATE="normal"
/>
 
<script language="VBScript">
 
Dim objShell
Const ForReading = 1
 
Sub Run(Name)
	Set objShell = CreateObject("WScript.Shell")
	Return = objShell.Run(Name, 1, true)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objInput = objFSO.OpenTextFile("out.txt", ForReading)
	DataArea.InnerHTML = "<pre>" & objInput.ReadAll & "</pre>"
	objInput.Close
	objFSO.DeleteFile "out.txt"
End Sub
 
</script>
 
</head>
<body>
 
<a href="javascript:Run('script.bat > out.txt');">Hello</a><br>
<span id="DataArea"></span>
 
</body>
</html>

Open in new window

0
 
LVL 3

Expert Comment

by:astroviper
ID: 24759655
Wait, I missed a bit, give me a min.
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24759698
Apologies for the double posting

<html>
<head>
<HTA:APPLICATION ID="oHTA"
      VERSION="1.0"
     APPLICATIONNAME="BatchFile"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     CONTEXTMENU="no"
     ICON=""
     INNERBORDER="yes"
     MAXIMIZEBUTTON=no"
     MINIMIZEBUTTON="no"
     NAVIGABLE="yes"
     SCROLL="no"
     SCROLLFLAT="yes"
     SELECTION="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="yes"
     SYSMENU="yes"
     WINDOWSTATE="normal"
/>
 
<script language="VBScript">
 
Dim objShell
Const ForReading = 1
 
Sub Run
	Name = "script.bat " & comp.value & " > out.txt"
	Set objShell = CreateObject("WScript.Shell")
	Return = objShell.Run(Name, 1, true)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objInput = objFSO.OpenTextFile("out.txt", ForReading)
	DataArea.InnerHTML = DataArea.InnerHTML & "<pre>" & objInput.ReadAll & "</pre><br>"
	objInput.Close
	objFSO.DeleteFile "out.txt"
End Sub
 
</script>
 
</head>
<body>
 
Please enter a computer name <input type="text" name="comp">
<input type="button" Value="Go" onClick="Run"><br>
<span id="DataArea"></span>
 
</body>
</html>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:astroviper
ID: 24759715
Actually you might wanna change the SCROLL="no" to a yes. I set it up so you can run it multiple times and it appends to the last command.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24761608
Hi astro,
Youre a gun.
astro....last one.

Is there any way to add:
1) The abilty to refresh the hta? At the moment, you cant it seems.
2) The ability to hide the command window when you click on the Go button.

Really appreciate your help.
0
 
LVL 3

Accepted Solution

by:
astroviper earned 2000 total points
ID: 24761851
I only tested it on a a batch file with "echo hello" in it so it was pretty much instantaneous. Maybe your one requires the right environment to run in as the output i get is:
C:\Users\Mike\Desktop>script.bat
C:\Users\Mike\Desktop>script.bat
C:\Users\Mike\Desktop>script.bat
... times 1000's

<html>
<head>
<HTA:APPLICATION ID="oHTA"
     VERSION="1.0"
     APPLICATIONNAME="BatchFile"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     CONTEXTMENU="yes"
     ICON=""
     INNERBORDER="yes"
     MAXIMIZEBUTTON="yes"
     MINIMIZEBUTTON="yes"
     NAVIGABLE="yes"
     SCROLL="yes"
     SCROLLFLAT="yes"
     SELECTION="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="no"
     SYSMENU="yes"
     WINDOWSTATE="normal"
/>
 
<script language="VBScript">
 
Dim objShell
Const ForReading = 1
temp = "out.txt"
 
Sub Run
        Name = "script.bat " & comp.value & " > " & temp
        Set objShell = CreateObject("WScript.Shell")
        Return = objShell.Run(Name, 0, true)
        Refresh
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        objFSO.DeleteFile temp
End Sub
 
Sub Refresh
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        If objFSO.FileExists(temp) Then
            Set objInput = objFSO.OpenTextFile(temp, ForReading)
            output = objInput.ReadAll
            If Not output = "" Then DataArea.InnerHTML = "<pre>" & output & "</pre><br>"
            objInput.Close
        End If
End Sub
 
</script>
 
</head>
<body>
 
Please enter a computer name <input type="text" name="comp">
<input type="submit" Value="Go" onClick="Run">
<input type="button" Value="Refresh" onClick="Refresh"><br>
<span id="DataArea"></span>
 
</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24783872
Thanks so much astro!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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