Simon336697
asked on
Running a command in a hta
Hi guys,
Id like to know what you guys suggest for the following.
Let's say i run the following from a command line:
dsquery user -name simonha*
In the above, the parameter is simonha*
What Id like to do is convert this into a hta so, I have the following when I run the hta:
-------------------------- ---------- ---------- ---------- ---------- ---------- ------ script.hta
Please enter in a username you wish to return the dn path for:
__________________________
<Run>
-------------
In the above, I would enter in the username, then click Run.
The output would be shown in the hta itself.
My question is, is that I want to run the dsquery command when I click the Run button.
If I had the below template for a hta in the code snippet, guys how would i add the command:
dsquery user -name simonha*
to it?
Any help greatly appreciated.
Id like to know what you guys suggest for the following.
Let's say i run the following from a command line:
dsquery user -name simonha*
In the above, the parameter is simonha*
What Id like to do is convert this into a hta so, I have the following when I run the hta:
--------------------------
Please enter in a username you wish to return the dn path for:
__________________________
<Run>
-------------
In the above, I would enter in the username, then click Run.
The output would be shown in the hta itself.
My question is, is that I want to run the dsquery command when I click the Run button.
If I had the below template for a hta in the code snippet, guys how would i add the command:
dsquery user -name simonha*
to it?
Any help greatly appreciated.
<html><head><title>HTA Test</title><HTA:APPLICATION ID="objTest" APPLICATIONNAME="HTA Test" SCROLL="yes" SINGLEINSTANCE="yes"></head>
<SCRIPT LANGUAGE="VBScript">
' PUT YOUR SUBROUTINES HERE
</SCRIPT>
<body>
<!-- PUT THE HTML TAGS HERE -->
</body>
ASKER
Hi sj, youre a gun mate.
That works great.
sj,
This returns the output in a command window.
Is there a way to:
1) Not display the command window at all.
2) Have the output written to the hta window?
Your a champion.
That works great.
sj,
This returns the output in a command window.
Is there a way to:
1) Not display the command window at all.
2) Have the output written to the hta window?
Your a champion.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi sj,
Ive given it a go.
It kind of works, but would love some help.
When I enter a username, and then click on Run, it opens up a command window, displays nothing, so I then close the command window manually. When I return to see what is in the hta window, the results are there as id like them, but im not understanding why im getting a blank dos window, and have to close it then see the results in the hta. Im pretty sure my code has some defects.
Here it is below.
Ive given it a go.
It kind of works, but would love some help.
When I enter a username, and then click on Run, it opens up a command window, displays nothing, so I then close the command window manually. When I return to see what is in the hta window, the results are there as id like them, but im not understanding why im getting a blank dos window, and have to close it then see the results in the hta. Im pretty sure my code has some defects.
Here it is below.
<html>
<head>
<!-- hta section below -->
<HTA:APPLICATION
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="yes"
minimizeButton="yes"
showInTaskbar="no"
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes"
/>
<SCRIPT LANGUAGE="VBScript">
Sub btnRun_Click
'Create an instance of the Wscript.shell object:
set objShell = CreateObject("Wscript.shell")
'Now create an exec object:
set objWshScriptExec = objShell.Exec("cmd /k dsquery user -name " & txtUsername.value & "*")
'Now get to the output of running the dsquery by defining a variable to hold the StdOut property of the exec object:
set objStdOut = objWshScriptExec.StdOut
strhtml = ""
Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
strhtml = strhtml & strLine & "<br>"
Loop
strhtml = strhtml
DataArea.InnerHTML = strhtml
End Sub
</script>
<body>
<h1>DSQuery</h1>
<p>Please enter in a username you wish to return the dn path for: :</p><input type="text" id="txtUsername" name="txtUsername" size='50'>
<p><input type="button" id="btnRun" name="btnRun" value="Run" onclick="btnRun_Click"></button>
<span id = "DataArea"></span>
</body>
</html>
Hmm, don't think it's possible to hide the cmd window, because the app you're running is a command line app. You can make apps run in a hidden window using sh.Run, but then you can't get the stdout to display the results in the HTA. Probably possible to retrieve the data from AD directly from the script using ADSI, so you wouldn't need to launch the exe, but will be a bit more complex.
ASKER
Hi sj,
With non-hta vbscript, is this true below?
Do Until objExec.Status
Wscript.Sleep 250
Loop
Wscript.Echo objExec.StdOut.ReadAll()
Ref for above is:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/may06/hey0519.mspx
Im just wondering if this waits until the command line tool is complete, and then returns results, then is there something comparable for htas? That is, something that would do the same as:
Wscript.Sleep 250
Without having to use wscript, which you cant use in a hta?
With non-hta vbscript, is this true below?
Do Until objExec.Status
Wscript.Sleep 250
Loop
Wscript.Echo objExec.StdOut.ReadAll()
Ref for above is:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/may06/hey0519.mspx
Im just wondering if this waits until the command line tool is complete, and then returns results, then is there something comparable for htas? That is, something that would do the same as:
Wscript.Sleep 250
Without having to use wscript, which you cant use in a hta?
Hmm, maybe I was mistaken about hiding the command window - that article seems to indicate otherwise. When you shell.exec, don't use "cmd..." just use "dsquery...". That might hide the window.
Regarding wscript.sleep and wscript.echo, you can't use the WScript object in HTA, so they won't work. As for alternatives for wscript.sleep - try googling it. I've seen solution before using ping and by running a wait script. Don't have any on had tho.
Regarding wscript.sleep and wscript.echo, you can't use the WScript object in HTA, so they won't work. As for alternatives for wscript.sleep - try googling it. I've seen solution before using ping and by running a wait script. Don't have any on had tho.
Open in new window