Sudo and Kill commands for Windows
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 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.
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.
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?
It is the same application only that it is not auto-closing the window after the command executes.
Thanks for finding these tools!
How does “sudo” compared with “surun” tool? (http://kay-bruns.de/)
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.
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
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.
Ouch!
http://s7.postimg.org/bjm953r63/image.png
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.
https://www.virustotal.com/en/file/a473fbf5caf1c3b22aaea43b07167a4935bb5e63032eabfe63011f020f637e6c/analysis/
[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.
Thanks for the info!
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
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!
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.
“there other and better native tools to reset and recover Windows these days.”
Would you mind naming some of them?
Is ln (logical link) available?
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.
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.
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.
Or rather, you can use the
runas
command. consent.exe can’t be used directly but it is used to load the UAC UIs.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?
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.
Where is the link please ?
Here it is: http://krutonium.leshcatlabs.net/2015/09/16/new-tools-sudo-and-kill-for-windows/
Thanks !