Hi all appreciate you help on msi custom action,

I have made a msi package which is need to check process running after time out it will terminate that process.
the script if running manually its working fine without issue, but when i put into msi custom action. after time out(20min) is reach it freezing.
below is my script


On Error Resume Next

 Dim strComputer:    strComputer    ="."
 Dim WshShell:         Set WshShell     = CreateObject("WScript.Shell")
 Dim service:    Set service = GetObject("winmgmts:" _
                            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 Dim EXCEL, WORD, iRet, StartTime, EndTime, Elapsed, info


Do
      EXCEL = false
      WORD = false

      For Each Process In Service.InstancesOf ("Win32_Process")
            If Process.Name = "EXCEL.EXE" Then
                  EXCEL = true
            End If
            If Process.Name = "WORD.exe" Then
                  WORD = true
            End if
      Next

      If not EXCEL and not WORD Then
            Exit Do
      End If

      info = "Following application(s) must be closed before uninstallation can start:" & vbcrlf & vbcrlf

      If EXCEL Then
            info = info & "EXCEL" & vbcrlf
      End If
      If WORD Then
            info = info & "WINWORD" & vbcrlf
      End If

      info = info & vbcrlf & vbcrlf & "Open application(s) will be automatically killed 20 minutes from now."

      iRet = WshShell.Popup(info, 1200, "Processes running", 4096+48)

      if iRet = -1  Then
        
            For Each Process In Service.InstancesOf ("Win32_Process")
                  Select case Process.Name
                        Case "EXCEL.EXE", "WINWORD.EXE"
                              Process.Terminate()
                              WScript.Sleep 5000
                  End Select
            Next
            Exit Do
      End If
Loop



1 Comment   [ + ] Show Comment

Comments

  • Don't know if it's a typo - but you reference 'word.exe' near the top of the script for the process name, and correctly 'winword.exe' near the bottom.
Please log in to comment

Community Chosen Answer

1
Good shout, Cap'n! But not "probably won't work", "definitely won't work" *IF* the CA uses embedded VBS. If the CA extracts and then executes the VBS, it will work.

@OP: this is because embedded VBSes don't use Windows Scripting Host when running.
Answered 03/21/2017 by: VBScab
Red Belt

Please log in to comment

Answers

0
I'll bet the CA is running in System context, in which case the script is trying to pop up a message window to a non-existent console.

This is a tricky scenario since you want to be able to tell the user that the processes are running and yet need the appropriate privileges to be able to complete the installation - we have to hope your ordinary users don't have installation rights!

This brings up the whole question of how to handle running processes. Pretty much every client I've worked at uses the same approach:

- tell users that on day 'x', Okey Cokey 2000 will be updated, that they need to be logged off of their PC and that IT will not be responsible for lost data if they fail to log off
- the day before 'x', send out a reminder about the update, the need to log off and the disclaimer
- send the same remainder on day 'x'

If they're still logged on when you do the update and they lose data, your HR department will probably want to reconsider that user's employment status.
Answered 03/20/2017 by: VBScab
Red Belt

Please log in to comment
0
Be careful using WScript.Sleep from a custom action too - it probably won't work.  I provided a couple of alternatives a while back: http://www.alkanesolutions.co.uk/2013/04/18/using-sleep-in-a-custom-action/

Answered 03/21/2017 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
Good clarification VBScab!   I'll give you a thumbs up for that!
Answered 03/21/2017 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
There is a small IBM-authored utility called "RunasCurrentUser" which has proved very useful when dealing with user profile stuff when deploying from a system account. Downloadable off the web as a freebie, don't have the link to hand ATM.
Answered 03/23/2017 by: EdT
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity