Tutorial Windows – Kill a process using the command-line [ Step by step ]

How to kill system process in windows 10. ‘access is denied’ message is sent

I have Angular 8 installed on the server which uses port 4200. But today I can’t run angular on port 4200. The error message is “An unhandled exception occurred: listen EACCES: permission denied 127.0.0.1:4200”.

Using netstat -a I noticed that the port is listening and it is used by the system.
I tried to kill the process taskkill /F /PID 1242 but couldn’t. The error message is “Access is denied”.

How can I kill the process?

Kill a process using image name:

We can kill all the processes running a specific executable using the below command.

taskkill /IM executablename

Example:Kill all processes running mspaint.exe:

c:>taskkill /IM mspaint.exe
SUCCESS: Sent termination signal to the process "mspaint.exe" with PID 1972.

Kill process like task manager (windows 8) do, because of access denied

I have the following problem:
I try to Kill a Process of a Online Game from c# code. I always get “access denied”! It has an Anti Hack Shield, I think that’s the problem…

[Edit]
I added /T to the TaskKill Commandline and get now the Error child Process with PID “access denied”.
I can not find this PID neither in Process.GetProcessById() nor in the Threads List of the Main Process.. Someone know how to Find this?

But with the Window Task Manager I can kill it!
I get my Process by finding the Window with P/invoke FindWindow() and GetWindowThreadProcessId()
I checked the PID it is the same!
I use the P/Invoke because I need it anyway for SetFourgroundWindow()

I also found this active in kernel mode[1] it’s an online game so its using the network adapter, can this be the problem? but why I can kill it with Task manager?
In this case I find the SetKernelObjectSecurity: http://csharptest.net/coding/ I’m not sure if I did it right I just changed AceQualifier.AccessDenied to AccessAllowed not working.

:/>  Old Calculator for Windows 10 - классический калькулятор

So how can I Kill it the same way as the Task Manager do?
Or can I call the Method of the Task Manager?
Maybe I need to change some Parameter/ Rights before?

I searched and I find something with SeDebugPrivilege: [2] I used it but still the same “access denied” I also tried it with Process.EnterDebugMode();

That’s my ways I tried: I run Visual Studio as administrator

public void KillKal(IntPtr _WindowPointer)
{
    uint ProcessID;

    GetWindowThreadProcessId(_WindowPointer, out ProcessID);
    try
    {
        #region SeDebugPrivilege 
        IntPtr hToken;
        LUID luidSEDebugNameValue;
        TOKEN_PRIVILEGES tkpPrivileges;

        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out hToken))
        {
            Console.WriteLine("OpenProcessToken() failed, error = {0} . SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
            return;
        }
        else
        {
            Console.WriteLine("OpenProcessToken() successfully");
        }

        if (!LookupPrivilegeValue(null, SE_DEBUG_NAME, out luidSEDebugNameValue))
        {
            Console.WriteLine("LookupPrivilegeValue() failed, error = {0} .SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
            CloseHandle(hToken);
            return;
        }
        else
        {
            Console.WriteLine("LookupPrivilegeValue() successfully");
        }

        tkpPrivileges.PrivilegeCount = 1;
        tkpPrivileges.Luid = luidSEDebugNameValue;
        tkpPrivileges.Attributes = SE_PRIVILEGE_ENABLED;

        if (!AdjustTokenPrivileges(hToken, false, ref tkpPrivileges, 0, IntPtr.Zero, IntPtr.Zero))
        {
            Console.WriteLine("LookupPrivilegeValue() failed, error = {0} .SeDebugPrivilege is not available", Marshal.GetLastWin32Error());
        }
        else
        {
            Console.WriteLine("SeDebugPrivilege is now available");
        }

        Process.EnterDebugMode();
        #endregion SeDebugPrivilege
        Process p = Process.GetProcessById((int)ProcessID);

        //1. try
        Process.Start(new ProcessStartInfo
        {
            FileName = "cmd.exe",
            CreateNoWindow = true,
            UseShellExecute = false,
            Verb = "runas",
            Arguments = string.Format("/c taskkill /pid {0} /f", ProcessID)
        });
        //2.try
        Process.Start(new ProcessStartInfo
        {
            FileName = "net.exe",
            CreateNoWindow = true,
            UseShellExecute = false,
            Verb = "runas",
            Arguments = string.Format("stop {0}", p.ProcessName)
        });
        //3. try
        Process.Start("cmd", string.Format("/c "taskkill /f /pid {0}"", ProcessID));

        //4. try get exception: access denided
        p.Kill();

        //5. try get exception:Process must exit before requested information can be determined.
        TerminateProcess(p.Handle, (uint)p.ExitCode);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.ToString());
    }
}

I also tried with PsKill and task kill in administration cmd ! https://postimg.org/image/qp5nkjvtn/

[1] http://msconfig.ru/questions/14038165/kill-process-windows-8-issues

[2] http://hintdesk.com/c-how-to-enable-sedebugprivilege/

Tutorial windows – kill a process using the command-line [ step by step ]

Start a new command-line prompt.

:/>  Как поменять пароль на компьютере windows 8 при входе в систему

Windows DOS Prompt

List the processes running on the computer.

Here is the command output.

Copy to Clipboard

Kill a process using the process ID.

In our example, we killed the process named MSPAINT, which had the process ID 3724.

Change the process ID number to the process that you want to kill.

Kill a process using the process name.

In our example, we killed all processes named MSPAINT.EXE.

Change the process name to the process that you want to kill.

You may also use wildcards on the process name.

In our example, we killed all processes in which the name started with MSPAIN.

Congratulations! You are able to terminate processes using the command-line.

Оставьте комментарий