dan_neal
asked on
HTA using vbscript
I am putting together an HTA that uses vbscript for running task on Active Directory. I have one task that creates a new user, assignes all standard properties for our domain, and creates the new users home directory folder. I want to put a status message on the page that will show what the task is currently doing. I found a vbscript file that creates an Internet explorer window and displays defined messages as the process runs but this only works from a command prompt. After decifering the script I see that it is using the wscript.sleep * command to designate the process to pause for * milliseconds, this give the interface a chance to refresh and display the message. Is there any way to access this from inside the vbscript in a hta application? If no is there anything else that can be used to give the same effect?
ASKER
so what you are saying is to use a separate html file to display my status information instead of using the hta form?
ASKER
Here is the file that displays the status box and uses the wscript.sleep function:
dim oIE, oS, k, strIETitle, blnFlag
strIETitle = "Test Program" & string(40,"-")
blnFlag = True
set oS = createobject("wscript.shel l")
InitIE "Program Initializing"
Wscript.sleep 2000
for k = 0 to 10
MsgIE "Iteration " & k & vbcrlf & "To abort, close this box"
Wscript.sleep 1000
if blnFlag = false then
wscript.echo "Program Aborted after " & k & " iterations"
wscript.quit
end if
next
MsgIE "Loop Complete"
wscript.sleep 2000
MsgIE "Program Finished"
If blnFlag = false then
wscript.echo "Program Aborted after iterations complete"
wscript.quit
end if
wscript.sleep 2000
MsgIE "IE_Quit"
Set oIE = nothing
set oS = nothing
wscript.echo "done"
Sub MsgIE(strMsg)
on error resume next
if strMsg = "IE_Quit" then
blnFlag = false
oIE.Quit
else
oIE.Document.Body.InnerTex t = strMsg
if err.Number <> 0 then
err.clear
blnFlag = false
exit sub
end if
oS.AppActivate strIETitle
end if
end sub
sub InitIE(strMsg)
dim intWidth, intHeight, intWidthW, intHeightW
set oIE = createobject("InternetExpl orer.Appli cation")
With oIE
.toolbar = false
.statusbar = false
.resizable = false
.navigate("about:blank")
do until .readystate = 4
wscript.sleep 100
loop
with .document
with .parentWindow
intWidth = .screen.AvailWidth
intHeight = .screen.availheight
intWidthW = .screen.availwidth * .40
intHeightW = .screen.availheight * .05
.resizeto intwidthW, intheightW
.moveto (intWidth - intwidthw)/2, (intHeight - intHeightW)/2
end with
.write "<body> " & strMsg & " </body></html>"
with .parentwindow.document.bod y
.style.backgroundcolor = "LightBlue"
.scroll = "no"
.style.font = "10pt 'Tahoma'"
.style.borderStyle = "outset"
.style.borderWidth = "4px"
end with
.Title = strIETitle
oIE.visible = true
wscript.sleep 100
oS.AppActivate strIETitle
end with
end with
end sub
This file works great as a stand-alone script but not to incorrporate into an hta.
dim oIE, oS, k, strIETitle, blnFlag
strIETitle = "Test Program" & string(40,"-")
blnFlag = True
set oS = createobject("wscript.shel
InitIE "Program Initializing"
Wscript.sleep 2000
for k = 0 to 10
MsgIE "Iteration " & k & vbcrlf & "To abort, close this box"
Wscript.sleep 1000
if blnFlag = false then
wscript.echo "Program Aborted after " & k & " iterations"
wscript.quit
end if
next
MsgIE "Loop Complete"
wscript.sleep 2000
MsgIE "Program Finished"
If blnFlag = false then
wscript.echo "Program Aborted after iterations complete"
wscript.quit
end if
wscript.sleep 2000
MsgIE "IE_Quit"
Set oIE = nothing
set oS = nothing
wscript.echo "done"
Sub MsgIE(strMsg)
on error resume next
if strMsg = "IE_Quit" then
blnFlag = false
oIE.Quit
else
oIE.Document.Body.InnerTex
if err.Number <> 0 then
err.clear
blnFlag = false
exit sub
end if
oS.AppActivate strIETitle
end if
end sub
sub InitIE(strMsg)
dim intWidth, intHeight, intWidthW, intHeightW
set oIE = createobject("InternetExpl
With oIE
.toolbar = false
.statusbar = false
.resizable = false
.navigate("about:blank")
do until .readystate = 4
wscript.sleep 100
loop
with .document
with .parentWindow
intWidth = .screen.AvailWidth
intHeight = .screen.availheight
intWidthW = .screen.availwidth * .40
intHeightW = .screen.availheight * .05
.resizeto intwidthW, intheightW
.moveto (intWidth - intwidthw)/2, (intHeight - intHeightW)/2
end with
.write "<body> " & strMsg & " </body></html>"
with .parentwindow.document.bod
.style.backgroundcolor = "LightBlue"
.scroll = "no"
.style.font = "10pt 'Tahoma'"
.style.borderStyle = "outset"
.style.borderWidth = "4px"
end with
.Title = strIETitle
oIE.visible = true
wscript.sleep 100
oS.AppActivate strIETitle
end with
end with
end sub
This file works great as a stand-alone script but not to incorrporate into an hta.
ASKER
Have solved problem myself. Thank you for your response.
if not a secret what solution did you come up with?
dan_neal, I asked you before and maybe you didn't see it, so if not a secret what solution did you come up with?
ASKER
created a sub routine that runs the ping command for a selected amount of time. Here is the sub:
Sub ccSleep(seconds)
set oShell = CreateObject("Wscript.Shel l")
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oShell.Run cmd,0,1
End Sub
Just place a call to this sub at any point you want to pause a routine to do something else such as in my case I wanted a status message to be updated as the routine ran to give the user an idea of where the process is at any given time. Here is how I called the routine:
Results.style.display = "block"
btnResultsReturn.disabled = true
lblStatus.innertext = "Validating data..."
ccSleep 1
if not e then
lblerr.style.display = "block"
lblstatus.innertext = "Errors found"
ccsleep 1
fname.focus
dresults.style.display = "none"
exit sub
else
lblerr.style.display = "none"
ccsleep 1
end if
lblstatus.innertext = "Validation complete"
ccSleep 1
lblstatus.innertext = "Generating account name..."
ccsleep 1
acname = left(fname.value,1) & lname.value
l = 1
do until chkuser(acname)
if l = 1 then
acname = left(fname.value,1) & mi.value & lname.value
else
acname = left(fname.value,1) & lname.value
end if
l = l + 1
loop
lblUsername.innertext = acname
lblstatus.innertext = "Available name generated..."
ccsleep 1
each ccsleep 1 runs the sub ccsleep for 1 second.
Sub ccSleep(seconds)
set oShell = CreateObject("Wscript.Shel
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oShell.Run cmd,0,1
End Sub
Just place a call to this sub at any point you want to pause a routine to do something else such as in my case I wanted a status message to be updated as the routine ran to give the user an idea of where the process is at any given time. Here is how I called the routine:
Results.style.display = "block"
btnResultsReturn.disabled = true
lblStatus.innertext = "Validating data..."
ccSleep 1
if not e then
lblerr.style.display = "block"
lblstatus.innertext = "Errors found"
ccsleep 1
fname.focus
dresults.style.display = "none"
exit sub
else
lblerr.style.display = "none"
ccsleep 1
end if
lblstatus.innertext = "Validation complete"
ccSleep 1
lblstatus.innertext = "Generating account name..."
ccsleep 1
acname = left(fname.value,1) & lname.value
l = 1
do until chkuser(acname)
if l = 1 then
acname = left(fname.value,1) & mi.value & lname.value
else
acname = left(fname.value,1) & lname.value
end if
l = l + 1
loop
lblUsername.innertext = acname
lblstatus.innertext = "Available name generated..."
ccsleep 1
each ccsleep 1 runs the sub ccsleep for 1 second.
ASKER
do so makes sure the form is given a chance to update the status message.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
briefly what I would do is: I'd use
dim win
win=window.open("page.html
and then you can manipulate any object/layer in that "page.html" file by calling
win.document.getElementbyI
wscript.sleep would be nice to use, but I don't think it would be necessary