hi,
I want c# source code for process killer as task manger
-> it forcefully kill the process which i want
<->it may be system process

This reeks of "virus". You'll now have to convince me otherwise, or this thread is closed.

Edited 6 Years Ago by Nick Evan: n/a

I am developing an anti-virus in which i want to use this code.
it's only for ethical purpose
i can tell u complete detail of this software what i want to do with it.


1->when a virus found the system will check about the file name and the dependent process of file and forcefully close it.i want want to do only this its not for unethical purpose
2-> And also it's not against the rules

Thanks

Have a look at the below, the System.Diagnostics.Process class.

Process[] processes = Process.GetProcesses();
...                      
Process p = Process.GetProcessesByName("aname");
p.Kill();

I am also using the same code but

->i didn't know how to get the file name of a process
that's main problem occurring know

You mean like this:

foreach(Process p in Process.GetProcesses())
{
    ProcessModule pm = p.MainModule;
    if(pm.FileName == "aname")
    {
        p.Kill();
    }
}

If thats not good enough you could look at using wmi like this

private void wmiProcessDetails()
        {
            string queryString = "SELECT * FROM Win32_Process";

            SelectQuery query = new SelectQuery(queryString);

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(queryString);
            ManagementObjectCollection processes = searcher.Get();


            foreach (ManagementObject mo in processes)
            {
                messageView.AppendText(String.Format("Name:\t{0} {1}\n", mo["Name"], mo["Handle"]));
                messageView.AppendText(String.Format("Path:\t{0}\n", mo["ExecutablePath"]));
                messageView.AppendText(String.Format("Install Date:\t{0}\n", mo["InstallDate"]));
                messageView.AppendText(String.Format("Command Line:\t{0}\n", mo["CommandLine"]));
                messageView.AppendText(String.Format("Caption:\t{0}\n\n",mo["Caption"]));
            }
        }

sir when i am using this code when i kill the process of system volume information i get an error which show access denied

can u help me again

You are realy my great teacher
Thank's Again:)

Edited 6 Years Ago by onlinessp: spell mistake

According to microsoft the user account used by the program must either of created a process or be an administrator to kill it.

That basically means that you will have to run the program using an admin account and if its vista or Win 7 using run as administrator.

But Dear Sir,


According to my information anti virus are doing scanning from limited user are able to kill that process then how they do it?

Thanks Again,

But Dear Sir,


According to my information anti virus are doing scanning from limited user are able to kill that process then how they do it?

Thanks Again,

Most AntiVirus programs run a number of services on the System account and a tray app within the current user. Look at "Inter Process Communication (IPC)" or using a intermediate database to do this.

The actual thread killing part will have to be in an admin account for your purposes.

This question has already been answered. Start a new discussion instead.