"Sleb" <Sleb@newsgroup> wrote in message
news:BD725594-3A57-4C7F-8EA0-1337A19998B6@newsgroup
> Hi,
>
> My question is regarding an application in a terminal server (win2k3). I
> want that when a particular application is closed that a message appear
> with
> a warning. The goal here is that this application needs to be open all the
> time so I want a warning message that appears saying not to close the
> application and not to log off but to disconnect. Putting the application
> as
> a service is not an option here.
>
> I think that by gpo, I can configure a message to appears when there is a
> log off but I am more concerned about the closing of the application.
>
> Anyone has an idea how this can be done?
>
> Thanks Here is a script that will do it:
[01] '-----------------------------------------------
[02] 'Monitor when an application is closed.
[03] 'Based on an idea by the Scripting Guy.
[04] '-----------------------------------------------
[05] iPoll = 5 'Time in seconds between polls
[06] sProcess = "notepad" 'Name of application to be monitored
[07] DQ = """"""
[08]
[09] Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
[10] Set oWshShell = CreateObject("WScript.Shell")
[11]
[12] Set cMonitoredProcesses = oWMIService. _
[13] ExecNotificationQuery("select * from __instanceDeletionEvent " _
[14] & " within " & iPoll & " where TargetInstance isa 'Win32_Process'")
[15]
[16] Do
[17] Set oProcess = cMonitoredProcesses.NextEvent
[18] If InStr(oProcess.TargetInstance.CommandLine, sProcess) _
[19] Then oWshShell.Run "msg.exe * ""The application " & DQ _
[20] & sProcess & ".exe" & DQ & DQ & " was closed."""
[21] Loop
Instructions:
1. Copy & paste the code into c:\Windows\ProcessMonitor.vbs.
2. Unwrap lines that might have been wrapped around by your newsreader.
3. Remove the line numbers.
4. Save and close the file.
5. Run the script.
6. Open notepad.exe, wait 10 seconds, then close it. You should
see a pop-up message.
7. Press Ctrl+C to close the script.
8. Adjust lines 5 and 6 to suit your environment.
9. Invoke the script through your logon process.