none
How to run a simple script after a specific application is stopped/ended by the user? RRS feed

  • General discussion

  • Hi There,

    my users (family) all run Windows 10 on all their computers and Firefox as teh webbrowser. Firefox is installed locally. In the  local network I have a RAID protected NAS with automated backup.

    Now I want to create a setup where

    * after Firefox is closed/stopped/ended by the user,

    * automatically a script is startet which

    * checks, if the NAS is accessible (indicates that the computer is at home in the local LAN/WLAN)

    * if the above is positive, the folder containing the Firefox profile is copied to the NAS

    The script is already there and I can start it manually, what would be the best way to get ist started automatically every time when Firefox is ended?

    I'm looking forward to your creative ideas!

    Best regards

    Bernhard



    • Edited by KarlDall Tuesday, August 16, 2016 8:29 AM
    Tuesday, August 16, 2016 8:15 AM

All replies

  • Hi,

    You could have a windows service that performs a scan of the current processes that are running on the computer. In pseudo code it would be something like:

    1. Start scan current processes that are running on the computer.
    2. Is "firefox.exe" a running process?
    3. If 2. = false, if Firefox is registered as running, run some script.
    4. If 2. = true, if Firefox is not registered as running, do register Firefox as running.

    Walkthrough: Creating a Windows Service Application
    https://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    • Edited by AsusT9 Friday, August 19, 2016 10:48 AM
    Friday, August 19, 2016 10:47 AM
  • This script monitors notepad closing. When notepad exits the script springs to life and restarts notepad. Remove the message boxes.

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
    Set objEvents = objWMIService.ExecNotificationQuery _
        ("SELECT * FROM Win32_ProcessStopTrace")

    Do
        Set objReceivedEvent = objEvents.NextEvent
        msgbox objReceivedEvent.ProcessName
        If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
            Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
            WshShell.Run "c:\Windows\notepad.exe", 1, false
        End If
    Loop

    To copy a folder

    Set fso = CreateObject("Scripting.FileSystemObject")

    FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"

    To test a drive is available

    Set fso = CreateObject("Scripting.FileSystemObject")

    object.DriveExists(drivespec) 


    David Candy


    • Edited by DavidMCandy Monday, August 22, 2016 2:00 AM
    Monday, August 22, 2016 1:58 AM