Command-line sudo and chmod under Windows

I’m quite not a fan of GUI utilities but I’m a great fan of command-line and batch processing.

I’ve recently changed profiles under a Windows box and had to move some files over them. At first wondered about logging in as the old user, copy all the files to a temp folder, log back as my new user and copy them to my new folder. But hell, too much time spent.

There’s must be a command-line solution, even on Windows!

So, I started Googling around for sudo like commands and then I’ve found Windows’ built-in runas

runas

Basic syntax for runas is as follow:

runas /user:MACHINENAME\username command

Example: Spawning an Administrator shell

runas /user:DEVEL\Administrator cmd

See all the options on runas /?.

cacls

This is the Windows’ chmod. It allows you to change files and dirs permissions for Windows’ ACL’s under Read/Write/Change/Full Control schema.

CACLS (Change ACLs) also lets you to edit the ACL instead of replacing it through the /E directive. It has three basic operations: Grant /G, Replace /P or Demote /D.

cacls FILENAME /P USER:PERMS

Access type (PERMS) can be:

N
None (only with /P)
R
Read
W
Write
C
Change
F
Full Access

Example: Granting user full-access under certain directory

cacls mydir\* /P jseidl:F

Of course, you must have the propper permissions to set the permissions, so it’s a good companion for runas.

Hope it helped!

Contents

comments powered by Disqus