All Forums >> [Scripting] >> WSH & Client Side VBScript >> [resolved]update user screen while external app runs (CreateObject("WScript.Shell").Run "") Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I have written a HTA application for reseting services on remote computers. During the stop or start service process, my script updates a text in a text box to simulate a progress bar. Everytime the script completes a wait loop, it appends the string and updates the textbox with the appended text.
This works great as long as the methods being performed are within the script. The problem I have is that I launch IISRESET to reset the webservices on remote servers. I do this because it handles the service dependancies better/easier. When my script launches it, it is a synchronous process, meaning my script has to wait until it completes before it can continue.
My question is, how can I perform this function and update the screen whille IISReset is running. Basically making a script multithreaded. The following are parts of my script with the needed functions. I have also included the service control function so that you can see the concept of the screen update. If the entire script is needed, I can post it so that it can be troubleshot, but I am interested more in concept than specifics. (I know that I could just allow the executed app to appear on the screen, updating the user with progress, but I want to make the whole tool/application uniform in the way it displays status.)
< Message edited by CondoPC -- 8/17/2007 3:12:35 PM >
I'm thinking that maybe the Exec method may allow me to run asychronously like the service control funtion
here is the working example from MSDN http://msdn2.microsoft.com/en-us/library/ateytk4a.aspx. I assume that the script is performing the sleep loop until the application exits. This would work fine for my IISReset since it exits when finished.
Dim WshShell, oExec Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc") Do While oExec.Status = 0 WScript.Sleep 100 Loop
Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You might be able to use the Exec method and use your sleep function to give the HTA time to update appropriately.
Dim objShell : Set objShell = CreateObject("WScript.Shell") Dim objExec : Set objExec = objShell.Exec("ipconfig /all")
Do Until objExec.StdOut.AtEndOfStream WScript.Echo objExec.StdOut.ReadLine WScript.Sleep 1000 Loop
For more control I would modify the ServiceControl function to handle dependencies as well or you could also use InternetExplorer to provide progress information.
When I first wrote this script, I was in a hurry and gave up on some of the error control and troubleshooting. With that said, after the fourth rewrote/rework of the service control functions, I left them as shown and inserted the use of IISRESET to handle IIIS. This was because I had services (IISADMIN) that had dependants (HTTP, HTTPS, WWW) that also had dependants (WWW). Because WWW wasn't stopped, HTTPS couldn't stop (or something like that).
Since then (about 3 weeks), I have learned quite a bit and have the time to review the script and clean it up. I agree with you that the Exec method would work, and I successfully tested it. I also took the time to rewrite a bunch of the functions so that I can find dependants better. The following is an example of the reworked stop services function which also will poll for service state.
Instead of using standard msgbox or wscript.echo command, I always put the text I want to display in a sub called DisplayOutput. This allows me to reuse code snippets without replacing all the output. I just modify the DisplayOutput sub to handle the medium i need. Here is the following so that the code above will display.
Note: in response to a few posts about finding the state of a service - if you uncomment the line: 'sP = "[" & iResult & "]" it will show you that the InterrogateService method does indeed give you different states of a service as it goes through its shutdown. It's just not as verbose, but i like it better than requerying WMI, which I think can be heavy on slower/bogged systems or across the network. I wrote these scripts to manage services across a farm and to perform the service resets across numerous servers at once.
Once I finish tweaking the display and cleanse it of company data, I will post it for use. It's a good framework tool to expand on.
< Message edited by CondoPC -- 8/17/2007 4:19:42 PM >