📎 AI Summary:
The thread revolves around a user seeking guidance on creating a C# command-line program to monitor Windows processes and notify when new processes start. A responder demonstrates a PowerShell script that monitors processes and displays notifications for new ones, clarifying that the script runs silently and requires waiting for process changes to trigger notifications. The original poster reports that running the script results in an unresponsive black CMD window with no output after waiting, prompting questions about how to make the notifications visible. The overall sentiment indicates interest but some confusion about script execution and output behavior.

Mihailo

New Member
Joined
Jul 3, 2018
Messages
3
Thread Author #1
I would like to know is it possible to make a cmd program in #C to monitor windows processes?

CMD Starts and automatically sends tasklist command every 10 seconds. If new process starts during that 10 seconds it opens TXT or another CMD windows to inform me that process name and location.



Thanks in advance.
 

Solution
Here is a Powershell version I put together
Code:
Add-Type -AssemblyName System.Windows.Forms

Function Invoke-Notification
{
    param
    (
        [String] $NotifyTitle,
        [String] $NotifyText,
        [Int] $Duration=2000,
        [System.Windows.Forms.NotifyIcon]$Notification
    )




    $Notification.BalloonTipText = $NotifyText
    $Notification.BalloonTipTitle = $NotifyTitle
    $Notification.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
    $Notification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\cmd.exe")
    $Notification.Visible = $true

    $Notification.ShowBalloonTip($Duration)
}


$ProcessList = $null

While($true)
{
    If($ProcessList)
    {
        # Most of the work is done here...

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
Most definitely, you could also do this in PowerShell just as easily.
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
Here is a Powershell version I put together
Code:
Add-Type -AssemblyName System.Windows.Forms

Function Invoke-Notification
{
    param
    (
        [String] $NotifyTitle,
        [String] $NotifyText,
        [Int] $Duration=2000,
        [System.Windows.Forms.NotifyIcon]$Notification
    )




    $Notification.BalloonTipText = $NotifyText
    $Notification.BalloonTipTitle = $NotifyTitle
    $Notification.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
    $Notification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\cmd.exe")
    $Notification.Visible = $true

    $Notification.ShowBalloonTip($Duration)
}


$ProcessList = $null

While($true)
{
    If($ProcessList)
    {
        # Most of the work is done here
        # Empty Differential
        $ProcessDifferentials = $null

        $CurrentProcesses = Get-Process
        $ProcessDifferentials = Compare-Object -ReferenceObject $ProcessList -DifferenceObject $CurrentProcesses

        If($ProcessDifferentials)
        {
            foreach($ProcessDifferential in $ProcessDifferentials)
            {
                If($ProcessDifferential.SideIndicator -eq "=>")
                {
                    # New process is running
                    $NotificationObject = New-Object System.Windows.Forms.NotifyIcon
                    Invoke-Notification -NotifyTitle "New Process Found" -NotifyText "Process: $($ProcessDifferential.InputObject.MainModule.FileName) found" -Duration 2000 -Notification $NotificationObject

                    $NotificationObject.Dispose()
                }
            }
        }

        $ProcessList = $CurrentProcesses
    }
    else
    {
        # First run
        $ProcessList = Get-Process
    }

    Start-Sleep -Seconds 10
}
 

Solution

Mihailo

New Member
Joined
Jul 3, 2018
Messages
3
Thread Author #4
Thank you for your time! When I run the script is shows me a black CMD window. It does nothing.
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
It won't show anything in the prompt. If you run it then open some other program and wait 10 seconds. You should get a notification of the new running process.

It's more of a sample. For example it's pulling the process main module name which some processes won't have it or it won't be viewable.
 

Mihailo

New Member
Joined
Jul 3, 2018
Messages
3
Thread Author #6
Hmm..I waited for 20 seconds and nothing happen...How to make it viewable?