Wednesday, November 23, 2016

Process check Notification (Only twice)

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set WshShell = CreateObject("WScript.Shell")

strAppName = "CatiaV5R19"
intSecondsToWait = 10

strMessageTextENG =(vbCr & "You have been scheduled to Upgrade CatiaV5R19."&vbCrlf& "Please exit out of the following program before Upgrading:"_
&vbCrlf&"• CATIA V5")

strMessageText = strMessageTextENG & VbCR & strMessageTextDEU & VbCR & strMessageTextFRA & VbCR & strMessageTextITA & VbCR & strMessageTextESP

strProcessName = "cNext.exe"

CheckForRunningApp strMessageText, intSecondsToWait, strAppName, strProcessName

Function CheckForRunningApp (strMessageText, intSecondsToWait, strAppName, strProcessName)
    Do
        found = false
        Set colProcessList = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = '" & strProcessName & "'")
        For Each objProcess in colProcessList
            WshShell.Popup strMessageText, intSecondsToWait, strAppName, vbInformation + vbSystemmodal
            found = true
        Next
    Loop Until found = false
End Function



Dim objWMIService, objProcess, colProcess, strComputer, processName, instances,found,strMessageText,strMessageTextENG,WshShell,strAppName,intSecondsToWait
Set WshShell = CreateObject("WScript.Shell")

instances = 0
processName = "MsHta.exe"
strAppName = "CatiaV5R19"
intSecondsToWait = 10

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

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

For Each objProcess in colProcess
If objProcess.Name = processName Then instances = instances + 1
Next

Do

found=false
Set colProcess = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = '" & processName & "'")
strMessageTextENG =(vbCr & "You have been scheduled to Upgrade CatiaV5R19."&vbCrlf& "Please exit out of the following program before upgrading:"_
&vbCrlf&"• Catiav5 / 3d Com Launcher")

strMessageText = strMessageTextENG
For Each objProcess in colProcess

              
WshShell.Popup strMessageText, intSecondsToWait, strAppName, vbInformation + vbSystemmodal
if colProcess.Count = instances then
found=true
Else
WScript.Quit

End If
 Next
Loop until Found=false

No comments:

Post a Comment