Author Topic: Windows ProTip; RunAs.exe; similar to sudo.  (Read 312 times)

Joey

  • Hero Member
  • *****
  • Posts: 715
  • Unreason
    • View Profile
Windows ProTip; RunAs.exe; similar to sudo.
« on: October 29, 2011, 05:33:49 AM »
I had reinstalled my machine this week and decided to use a more secure approach when it comes to users. So I made an admin account, used that to enable the built-in Admin account, and used THAT account to make my own account a standard user. (this way, the built in admin account can be used instead of having an active and one disabled admin account.)

Then I tweaked the folders and drives to only allow certain access to Admin and I am certain that my system is way more secure than it was before.

HOWEVER, now I cannot change important system settings easily. Sure, I could create a shortcut to every program I use and right click 'run as administrator' all the time, or I could configure the program to always run as admin, but that is also not always necessary or convenient. Most apps these days will ask to be elevated when needed but not all apps do this and thus I looked for a way to do something sudo does, and apparantly, there is a feature in windows that does just this.

Similar to linux, where you would use
Code: [Select]
sudo COMMAND and then enter the password of the root user, in windows you can use
Code: [Select]
runas /user:administrator COMMAND where you enter the password and it will execute the command/program with elevated user rights. Of course, you can change administrator to whatever username your admin account has.


Naturally, you could also use this method to Revoke permissions. If you are admin, but don't want to run an app as such since it may be risky, simple
Code: [Select]
runas /user:standard COMMAND and it will have less privileges.
« Last Edit: October 29, 2011, 12:25:06 PM by Joey »
Please correct any grammatical error I may make; I wish to improve on my English as much as possible!

cms07

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Blog
Re: Windows ProTip; RunAs.exe; similar to sudo.
« Reply #1 on: November 27, 2011, 12:34:45 AM »
Naturally, you could also use this method to Revoke permissions. If you are admin, but don't want to run an app as such since it may be risky, simple
Code: [Select]
runas /user:standard COMMAND and it will have less privileges.
I understand the desire to run programs as an administrator from a standard user's position, but why would one be logged in as an administrator for a significant enough period of time as to require running something as a standard user?
Intel Core 2 Duo CPU T5470 @ 1.60GHz
Xfce4 on Arch Linux.

Primefalcon

  • Hero Member
  • *****
  • Posts: 2134
  • https://launchpad.net/~primefalcon
    • View Profile
    • Prime's Tech Talk
Re: Windows ProTip; RunAs.exe; similar to sudo.
« Reply #2 on: November 27, 2011, 01:37:09 AM »
hmm quick question but can you alias commands in windows?

something along the lines of

Code: [Select]
alias sudo='runas /user:administrator'
would be useful I'd imagine
Get 2.25G of space on Dropbox by CLICKING HERE, Rather than 2G otherwise. Sync files between multiple computers, Web and even share folders with your friends!

Pinako

  • Hero Member
  • *****
  • Posts: 1236
    • View Profile
    • inportb
Re: Windows ProTip; RunAs.exe; similar to sudo.
« Reply #3 on: November 27, 2011, 02:54:10 AM »
You'd probably make a batch script for that and install it in one of the PATH'd directories. Or, just do it the Microsoft Way: make a shortcut and tweak its privileges.

Primefalcon

  • Hero Member
  • *****
  • Posts: 2134
  • https://launchpad.net/~primefalcon
    • View Profile
    • Prime's Tech Talk
Re: Windows ProTip; RunAs.exe; similar to sudo.
« Reply #4 on: November 27, 2011, 04:04:07 AM »
Actually I just did a quick Google around and came across this...

http://www.powershellpro.com/powershell-tutorial-introduction/tutorial-powershell-aliases/
Get 2.25G of space on Dropbox by CLICKING HERE, Rather than 2G otherwise. Sync files between multiple computers, Web and even share folders with your friends!

Joey

  • Hero Member
  • *****
  • Posts: 715
  • Unreason
    • View Profile
Re: Windows ProTip; RunAs.exe; similar to sudo.
« Reply #5 on: November 27, 2011, 05:59:07 AM »
I simply made a sudo.bat

Code: [Select]
@echo off
If "%*" == "" goto error
runas /user:administrator "%*"
Exit
:error
echo No arguments were given!
Pause
Exit

I probably don't need to explain what it does :)
Please correct any grammatical error I may make; I wish to improve on my English as much as possible!