0

I just downloaded this Open-Source Program:
http://fabi.me/tools/processfreezer/
and I want to modify something in it. But I really don't know how...

This program allows you to freeze a process. You select the process through a Listbox. But I just want to freeze a one specific program which is manually given in a string.

For example:

string process = "C:\\Program Files (x86)\\yolo\\yolo.exe";

How can I override the Listbox and give that information to the suspend function?

Here's the code

Process[] GetCheckedProcesses()
{
    Process[] procs = new Process[lvProcesses.CheckedItems.Count];
    for (int i = 0; i < procs.Length; i++)
        procs[i] = (Process)lvProcesses.CheckedItems[i].Tag;

    return procs;
}

private void btnSuspend_Click(object sender, EventArgs e)
{
    Process[] procs = GetCheckedProcesses();

    for (int i = 0; i < procs.Length; i++)
    {
        try { ProcessFreezer.SuspendProcess(procs[i]); ; }
        catch (Exception ex) { MessageBox.Show(ex.ToString(), "FEHLER"); }
    }
}

Here's a snippet of ProcessIsSuspend

public static bool ProcessIsSuspended(Process proc)
{
    bool suspended = true;
    foreach (ProcessThread pT in proc.Threads)
        suspended &= (  pT.ThreadState == System.Diagnostics.ThreadState.Wait
                      && pT.WaitReason == ThreadWaitReason.Suspended  );
    return suspended;
}

So the Button should just freeze the process without asking which...
Hopefully its understandable. I just started with C# and its a bit different to C++

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
user3202845
  • 41
  • 1
  • 7
  • What (if anything) have you tried so far? Where is the problem exactly? You've told us the issue you are trying to solve but not what the problem you have in doing so. – Chris Jan 16 '14 at 15:54
  • The Problem is that I dont understand how I change a Listbox with many items to a Button with only one Item f.x. chrome.exe . I just want to click to the Button and the Programm should freeze chrome.exe . I dont want to have the Option which shows a List where every Processes are listed :/ I really dont get it :( – user3202845 Jan 21 '14 at 15:37

1 Answers1

0

A process to file name mapping is an n-to-1 relationship (consider two instances of Visual Studio for example).

In order to find processes based on a file name you can use the file of the 'main module':

Process proc;
try 
{ 
    string fileName = proc.MainModule.FileName
    //check if the file matches what you are looking for.

} 
catch (Win32Exception e) 
{
  //some processes are protected, you 
  //will not be allowed to access the file name
  //even as an administrator
}

So basically filter the list of processes based on your file name.

Bas
  • 26,772
  • 8
  • 53
  • 86