Jerms3033
Jerms3033

Reputation: 101

Running a script when you launch a certain Program

Is it possible to run a Script when launching a particular file? (Access in this case) If so, is it possible using the windows task scheduler? Also, keep in mind I used powershell to develop the script.

Upvotes: 0

Views: 2502

Answers (1)

Knuckle-Dragger
Knuckle-Dragger

Reputation: 7046

Maybe you can use a WMI event watcher. This snippet waits for calc.exe to be launched, then runs a script to adjust the priority to low. Afterwords it loops in waiting for the next instance of calc.exe to be spawned.

PowerShell script that runs in background changing specific process priority to low whenever it is ran

$prog = Get-Process -Name calc | ?{$_.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::Idle}

    while($true)
    {
        $Query = "select * from __instanceCreationEvent within 1 where targetInstance isa 'win32_Process' AND TargetInstance.Name = 'calc.exe'"
            $Eventwatcher = New-Object management.managementEventWatcher $Query

            $Event = $Eventwatcher.waitForNextEvent()

            $prog = Get-Process -Name calc | ?{$_.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::Idle}
    }

Additional info.

http://blogs.technet.com/b/heyscriptingguy/archive/2012/06/08/an-insider-s-guide-to-using-wmi-events-and-powershell.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2009/01/19/how-can-i-be-notified-when-a-process-begins.aspx

another example.

https://superuser.com/questions/693596/how-to-know-which-service-is-responsible-for-any-exe-running/693601#693601

Upvotes: 1

Related Questions