Sunday, August 28, 2016

[nugget] sudo on windows!

Hi Guys,

Today i'll give you a tiny tip that makes our lives on windows a little more comfortable.

When working with linux one have a fairly easy way of elevating his/her privileges, we have both sudo and su.
In windows, while running as an administrator on the computer, some privileged commands are inaccessible yet until we would confirm UAC (User Access Control). Furthermore, if we are using a command line tool, the command prompt usually doesn't even ask for it. It is up to us launching command prompt as an administrator.

Thus, I have devised a small little trick that I already use several years, making a "su" out of "cmd.exe"

  1. Copy system32\cmd.exe to the same folder
  2. Rename it to su.exe.
  3. Right click on su.exe -> Properties -> Compatibility -> "Run this program as an administrator"
That's it, you can now use su instead of right click, run as admin...

Now for sudo we'd just create a batch file in system32 called sudo.bat [I'm new to blogger, styling will come later]:


@echo off
su /c %*


now we can do, for example:
sudo notepad c:\windows\system32\drivers\etc\hosts

Have fun.

No comments: