I am writing a script to uninstall a program from a large number of workstations. I have every part of the script working except one.
Instead of just having the script sleep for an estimated time during the uninstall before it restarts, I am trying to poll the process to see when it quits.
I am doing this by using the winsmgmt object. I am reading all the processes into an array then filtering that array for the process I'm looking for. Then I test for the existence of the process if it finds it the script sleeps for a minute, clears the array, loops and starts over.
Everything works great until the process I am monitoring stops. Then the script doesn't exit the loop. I know the filter is working because it stops sending me the name of the process through the echo command. I know I am probably missing something simple here or there is a lot better way to do this than what I am trying to do. If anybody has any ideas please let me know.
Here is my code.
IsZenAlive = 1
Do While IsZenAlive = 1
i=0
For each Process in Service.InstancesOf ("Win32_Process")
i=i+1
Next
ReDim arrProcesses(i)
i=0
For each Process in Service.InstancesOf_ ("Win32_Process")
arrProcesses(i)=Process.Name
i=i+1
Next
arrZenProcess=Filter(arrProcesses,"zenworksuninstall",True,1)
UninstRunning=Join(arrZenProcess)
WScript.Echo UninstRunning
If UninstRunning <> "zenworksuninstall" Then
WScript.Sleep(60000)
Erase arrProcesses
IsZenAlive = 1
Else
IsZenAlive = 0
End If
Loop
Instead of just having the script sleep for an estimated time during the uninstall before it restarts, I am trying to poll the process to see when it quits.
I am doing this by using the winsmgmt object. I am reading all the processes into an array then filtering that array for the process I'm looking for. Then I test for the existence of the process if it finds it the script sleeps for a minute, clears the array, loops and starts over.
Everything works great until the process I am monitoring stops. Then the script doesn't exit the loop. I know the filter is working because it stops sending me the name of the process through the echo command. I know I am probably missing something simple here or there is a lot better way to do this than what I am trying to do. If anybody has any ideas please let me know.
Here is my code.
IsZenAlive = 1
Do While IsZenAlive = 1
i=0
For each Process in Service.InstancesOf ("Win32_Process")
i=i+1
Next
ReDim arrProcesses(i)
i=0
For each Process in Service.InstancesOf_ ("Win32_Process")
arrProcesses(i)=Process.Name
i=i+1
Next
arrZenProcess=Filter(arrProcesses,"zenworksuninstall",True,1)
UninstRunning=Join(arrZenProcess)
WScript.Echo UninstRunning
If UninstRunning <> "zenworksuninstall" Then
WScript.Sleep(60000)
Erase arrProcesses
IsZenAlive = 1
Else
IsZenAlive = 0
End If
Loop