Sudo and Kill commands for Windows

Martin Brinkmann
Sep 17, 2015
Updated • Sep 17, 2015
Windows
|
25

If you ever worked on a Linux or Unix machine, you may have come to like certain commands that you could run on them.

Two of those commands that may have come in handy then are Sudo and Kill. When I think of Sudo, I always think of xkcd's Sandwich drawing in which the command is highlighted.

Sudo enables you to run commands with elevated rights and there is no equivalent available for Windows. While you can use PowerShell on the command line to run a command with elevated rights even if the originating command line window is not elevated, it is not as easy as starting the command with sudo.

Several third-party programs such as Hstart add this functionality to Windows, and so does the tiny command line utility Sudo.

All you need to do is write sudo followed by the command you want to run with elevated privileges, e.g. sudo cmd.exe to open an elevated command prompt from a command prompt window that is not elevated.

sudo windows

Sudo supports command line arguments as well which are executed just fine along with the specified command.

An UAC prompt is spawned whenever you use sudo to confirm the elevation.

Kill on the other hand terminates processes. Usage is even simpler as you can kill processes by name or process id.

Simply use kill 6396 1344 or kill chrome nightly to kill the processes with the IDs 6396 and 1344, or the Chrome and Nightly process.

Some kill commands may require elevated privileges which, you may have guessed it already, you can get by combining sudo with kill.

The command sudo kill 666 runs the kill command with administrative privileges to terminate process 666 on the system.

Sudo and Kill can be downloaded from the authors website. They are both 10k in size and can be run from any location on your system. There is also ASudo which works like Sudo but keeps the elevated command window open after the command completes.

Place them in a path directory to make them available system wide for extra convenience. To check the path, tap on Windows-Pause, select Advanced system settings and when the System Properties window opens Environment Variables.

environment variables

You can add a directory to the path with a click on new or simply place sudo and kill in a directory that is already listed as a path variable.

Summary
Sudo and Kill commands for Windows
Article Name
Sudo and Kill commands for Windows
Description
Find out how to run Sudo and Kill commands on Windows the same way you run them on Linux or Unix.
Author
Advertisement

Tutorials & Tips


Previous Post: «
Next Post: «

Comments

  1. Paul(us) said on September 20, 2015 at 3:51 pm
    Reply

    On the same page there also writing about that ” Someone wanted a version of Sudo that keeps the Window open once your command completes, run it without any info to get a usage example. It’s called ASudo.”
    Martin what are you thoughts about ASudo?

    1. Martin Brinkmann said on September 20, 2015 at 4:33 pm
      Reply

      It is the same application only that it is not auto-closing the window after the command executes.

  2. DMV said on September 18, 2015 at 12:56 pm
    Reply

    Thanks for finding these tools!
    How does “sudo” compared with “surun” tool? (http://kay-bruns.de/)

  3. Ross said on September 18, 2015 at 7:32 am
    Reply

    TaskKill, part of Windows
    https://technet.microsoft.com/en-us/library/bb491009.aspx

    PSkill, distributed by sysinternals.com (which is now owned by Microsoft)
    https://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

    Self-elevating script, from Microsoft blogs:
    http://blogs.technet.com/b/elevationpowertoys/archive/2010/06/20/creating-a-self-elevating-script.aspx

    I have this last named as “elevate.cmd” kept in my path.

    1. Anonymous said on September 19, 2015 at 2:35 am
      Reply

      I posted in another thread here but you can do the same with powershell as that elevate script

      powershell Start-Process cmd -Verb runAs
      will run an elevated command prompt from a none elevated one

      also, speaking of sysinternals psexec is a great tool that’ll let you run processes as an elevated account, even system remote or local

  4. DonGateley said on September 17, 2015 at 11:44 pm
    Reply

    Kewl! I wanted kill the other day. There are certainly other ways to do it but that’s the one in my memory from my long past Unix days.

  5. Leandro said on September 17, 2015 at 7:26 pm
    Reply
    1. Krutonium said on September 21, 2015 at 11:49 pm
      Reply

      Unfortunately that will happen, since it’s sole purpose is to elevate another process… Which is something pretty well any virus under the sun would want.

  6. anon said on September 17, 2015 at 7:19 pm
    Reply

    [can’t reply directly]

    @Tim Walters, there’s the PC reset feature in Windows 8 and later that lets you restore Windows settings to default, which also removes any apps you installed (you can choose to remove your personal data too, which makes it a full reset). Windows 7 already had this but not the mode to not delete personal files. Additionally, you can create a system image and restore from it. Then there are the tools to create recovery media, which on Windows 8 and later support USB drives and allow you to optionally add the manufacturer’s recovery partition to it.

    All these are better than System Restore ever was since its inception in Windows ME (even though it got better since then). System Restore also poses compatibility issues between older and newer Windows versions in multiboot scenarios because the newer version’s restore points are deleted by the older versions when booted as they do not recognize them.

    1. Tim Walters said on September 17, 2015 at 7:22 pm
      Reply

      Thanks for the info!

      1. Anonymous said on September 18, 2015 at 4:28 am
        Reply

        regarding those tools

        powershell Start-Process cmd -Verb runAs
        will run an elevated command prompt from a none elevated one

        tasklist
        will list tasks at command prompt

        taskkill /F /IM deadtask*
        will force kill every process with the name deadtask in it

        taskkill /PID 1337 /T
        will kill process id 1337 and all its child processes

  7. jasray said on September 17, 2015 at 5:45 pm
    Reply

    Great tutorial until–“Place them in a path directory to make them available system wide for extra convenience. To check the path, tap on Windows-Pause, select Advanced system settings and when the System Properties window opens Environment Variables. You can add a directory to the path with a click on new or simply place sudo and kill in a directory that is already listed as a path variable.”

    The hilarity of users attempting such a task on Windows with no prior usage or little usage of Linux [and even less of Windows] makes me shake my head and smile. Any tech writer who tells his audience to go in to Windows and play with the Environmental Variables is either taking a huge “existential leap of blind faith” or inviting the wrath of many or overestimating the understanding and skill set of the audience.

    Windows isn’t Linux; Windows doesn’t work like Linux; and Windows is much more temperamental than Linux. Not even mentioning that a full image backup be made or at least a System Restore Point be made before “playing geek” is way out there in “daw-dee-u-crazy-man” land.

    Good luck, users. I think I’ll stick with Start, cmd, right click, run as admin, and enter command [not sudo or kill] for my Windows command line work. If I really need to kill a task that is stuck, pressing the power button for a long time works wonders, and contrary to popular belief, it does not harm Windows in any way. It’s as though lightening struck and the power went out. Start again!

    1. anon said on September 17, 2015 at 5:52 pm
      Reply

      But Windows NT not being UNIX or UNIX-like is precisely the point. As to it being “more temperamental”, I find that hard to believe since your average user is more likely to break a Linux distro by tweaking some random settings than from installing random software on Windows Vista and later.

      System Restore is disabled on Windows 10 by default, by the way. It’s likely going away in the future as there other and better native tools to reset and recover Windows these days.

      1. Tim Walters said on September 17, 2015 at 7:02 pm
        Reply

        “there other and better native tools to reset and recover Windows these days.”

        Would you mind naming some of them?

  8. Sukhen said on September 17, 2015 at 4:19 pm
    Reply

    Is ln (logical link) available?

    1. Al McCann said on September 18, 2015 at 1:13 am
      Reply

      Check out the Windows mklink.exe command:

      mklink /?
      Creates a symbolic link.

      MKLINK [[/D] | [/H] | [/J]] Link Target

      /D Creates a directory symbolic link. Default is a file symbolic link.
      /H Creates a hard link instead of a symbolic link.
      /J Creates a Directory Junction.

      Link specifies the new symbolic link name.
      Target specifies the path (relative or absolute) that the new link refers to.

  9. anon said on September 17, 2015 at 3:54 pm
    Reply

    What is the purpose of this? UAC already exists and you can use consent.exe from the console if you prefer to do things that way.

    As to kill, there are already native commands for that as well.

    1. Krutonium said on September 21, 2015 at 11:50 pm
      Reply

      I am well aware there are native commands, but what is easier to type?

      kill chrome

      taskkill /f /im chrome.exe

      As for UAC… Your point? All I’ve done is provide an easy way to make it prompt.

    2. anon said on September 17, 2015 at 4:34 pm
      Reply

      Or rather, you can use the runas command. consent.exe can’t be used directly but it is used to load the UAC UIs.

  10. Christoph said on September 17, 2015 at 11:41 am
    Reply

    Well, under linux kill is a command for sending a signal to a process. If the signal is a SIGTERM the process terminates. Nevertheless you could also send SIGUSR1 which is custom signal.
    Do I understand you right that this kill command described here could only send SIGKILL, don’t I?

    1. Krutonium said on September 21, 2015 at 11:52 pm
      Reply

      I am not sure about how that applies to Windows, but the way I am killing the processes is I actually ask the system to kill a process, and it does the rest for me.

  11. Bryan said on September 17, 2015 at 8:41 am
    Reply

    Where is the link please ?

    1. Martin Brinkmann said on September 17, 2015 at 9:13 am
      Reply
      1. Bryan said on September 17, 2015 at 9:18 am
        Reply

        Thanks !

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.