lunes, 29 de marzo de 2021

 

Changing access permissions in Windows by cmd


1. You have to open the command prompt as a privileged user. That can be found under Start > "All Programs" > Windows system. Right-click on the "Command prompt" icon and select "Run-As".

2. Once prompted, enter username and password.

3. On the command line, you can use a comman called CACLS. 

Here's the full list of things that it can do:


Displays or modifies access control lists (ACLs) of files
CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
               [/P user:perm [...]] [/D user [...]]
   filename      Displays ACLs.
   /T            Changes ACLs of specified files in
                 the current directory and all subdirectories.
   /E            Edit ACL instead of replacing it.
   /C            Continue on access denied errors.
   /G user:perm  Grant specified user access rights.
                 Perm can be: R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /R user       Revoke specified user's access rights (only valid with /E).
   /P user:perm  Replace specified user's access rights.
                 Perm can be: N  None
                              R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /D user       Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.

Abbreviations:
   CI - Container Inherit.
        The ACE will be inherited by directories.
   OI - Object Inherit.
        The ACE will be inherited by files.
   IO - Inherit Only.
        The ACE does not apply to the current file/directory.


So if you want to add permissions to a folder called "MyFolder", located on C: drive for Everyone, do the following:

C:\cacls c:\MyFolder /e /p Everyone:F

Where /e is to preserve old permissions;
/p is to add new permissions;
Everyone is the user
f stands for Full Control (R Read, W Write, C Change (write), F Full control)

If you don't include /e, the permissions assigned will be the only permissions on the file/directory.


More examples:


If you want to add permissions to hosts file for a user, do the following:

C:\cacls C:\Windows\System32\Drivers\etc\hosts /e /p UserID:W

If you want to remove permissions to a file called "test.txt", located on desktop for Everyone, do the following:

C:\cacls C:\Users\UserdID\Desktop\test.txt /e /p Everyone:N

No hay comentarios:

Publicar un comentario