Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with script hanging, need to watch processes

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I created a script to load call a process to restore a backup, wait until that backup is done, then reset the computer. I wanted to put a counter on the screen that's shown while the backup is restore (using HTA), but I am having difficulty, here is what I have so far

Code:
<html>
    <HTA:APPLICATION ID="oMyApp" 
    APPLICATIONNAME="Restore" 
    BORDER="none"
    CAPTION="no"
    SHOWINTASKBAR="no"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="maximize">

    <script language = "VBScript">
	    Sub Restore_onclick
			MsgBox "Are you sure you want to restore the environment? The C:\ Drive will be restored, and data not stored on the D:\ Drive will be lost", VBOKCancel + vbDefaultButton2 + vbExclamation, "Test"
			Dim MyObj
			Set MyObj=CreateObject("WScript.Shell")
			'MyObj.Run """E:\program files\acronis\trueimageworkstation\trueimagecmd.exe"" /filerestore /filename:""E:\Backup.tib"""
			DataArea.InnerHTML = "Do not close any windows or use this station.  It will reboot as soon as the C: Drive is restored"
			idTimer = window.setTimeout("CheckForRestore", 5000, "VBScript")
	    End Sub 
		
		Sub CheckForRestore
			Dim myDateString
			myDateString = Time()
			Dim i 
			
			strComputer = "."

			Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" _ 
			& strComputer & "\root\cimv2") 

			Set colProcess = objWMIService.ExecQuery _
			("Select Name from Win32_Process Where Name = 'trueimagecmd.exe'")
			
			For Each objProcess in colProcess
				
				i = 1
				
			Next
			
			if i = 0 Then
					Call Cancel_onclick() 
			end if
			
			Do While i = 1
			idTimer2 = window.setTimeout("Pause", 10000, "VBScript")
				i = 0
				Set colProcess2 = objWMIService.ExecQuery _
				("Select Name from Win32_Process Where Name = 'trueimagecmd.exe'")
			
				For Each objProcess2 in colProcess2
					
						i = 1
					
				Next
			
				if i = 0 Then
					Call Cancel_onclick() 
				end if
				
				
				MsgBox DateDiff("n", myDateString, Time) & ":" & DateDiff("s", myDateString, Time)
				
			Loop
			
		End Sub
		
		Sub Pause
		
		End Sub
		
		Sub Cancel_onclick
			'Set WSHShell = WScript.CreateObject("WScript.Shell")
			'WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
			self.Close
		End Sub
    </script>

    <body onLoad="window.focus()" onBlur="window.focus()">
	 <p>
	 <font size='36' color='red'>
	 <br>
	 <br>
	 <br>
	 <br>
	 <center>
	 <span id = "DataArea">
        Message with buttons
		<INPUT TYPE="BUTTON" NAME="Restore" VALUE="Restore Environment">
		<INPUT TYPE="BUTTON" NAME="Cancel" VALUE="Cancel">
	</span>
	<br>
	<span id = "CounterArea"></span>
	</center>
	</font>
	</p>
	</body>
</html>

The problem is that it does not wait 10 seconds before it queries again, it just does it continuously. Any help is greatly appreciated
 
Why the following loop ?
Do While i = 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Don't I need to update the list of processes to see when the restore ends? I want to call a restart after the Restore process ends, which takes about a 1/2 hour.
 
I've come up with a solution, so no body needs to respond. I'll post what I came up with if anyone is intereseted
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top