Skip to main content

How to grant permission to users for a directory using command line in Windows?

 

How to Fix Access is Denied, File May Be In Use, or Sharing Violation Errors in Windows


If you get the Access is Denied or You don’t currently have permission to access this folder message, then you’re probably looking at a permissions problem. If you’re not an Administrator on the computer, you’re probably not going to be able to fix this issue, so first make sure you can get access to an admin account.

Access Is Denied Error

OR



This particular error is normally caused by NTFS permissions,  but it can also be caused by other issues like a corrupt user profile, encryption on the file or if the file is in use. We’ll talk about file in use errors in the next section.

To gain access to the file or folder, you’ll need to have the correct permissions configured for your account. Before you start doing any work, you should try to click on the Continue button that will show up in Windows 7 and Windows 8 automatically. This will try to give your user account permissions to the folder as long as you are the owner.


If you get the You have been denied permission to access this folder message after clicking Continue, that means you are not the owner and you’ll have to first take ownership of the folder before you can change any permissions.

Take Ownership of Files and Folders in Windows

Resolution : Grant Cmd.exe Read and Execute permissions


Open runas Administrator cmd.exe
cd <FolderPath>
takeown /R /F *.*
icacls * /T /grant [username]:(D)

If You want to Delete ( del *.* /S /Q )


Linux and Unixish system comes with chmod and other commands to setup/change access permission from command line/shell.

However, when it comes to windows chmod is not available. Windows comes with a special command line utility called CACLS.

You can use it as follows:

CACLS files /e /p {USERNAME}:{PERMISSION}

Where,

  • /p : Set new permission
  • /e : Edit permission and kept old permission as it is i.e. edit ACL instead of replacing it.
  • {USERNAME} : Name of user
  • {PERMISSION} : Permission can be:
    • R – Read
    • W – Write
    • C – Change (write)
    • F – Full control

For example grant Rocky Full (F) control with following command (type at Windows command prompt):

C:> CACLS files /e /p rocky:f

Read complete help by typing following command:

C:> cacls /?

Example 1: 

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

C:\cacls c:\Shared /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.

Example 2: icacls * /T /grant Everyone:(D)

you will not be able to get into that folder or file unless you are given permissions from an Administrator! Have any questions, post a comment. Enjoy!

Comments

Popular posts from this blog

How to enable SSH login access to a Cisco router

This guide walks you through how to setup SSH on a Cisco Router. SSH is by far more secure then telnet. Telnet allows your passwords to be sent in plain text that anyone can see and gain access to your network. SSH is all encrypted traffic. NOTE: This should work with any Cisco router provided the Cisco IOS on the router supports ssh. Firstly is ssh enabled? router#sh ip ssh SSH Disabled - version 2.0 %Please create RSA keys to enable SSH. Authentication timeout: 60 secs; Authentication retries: 5 In this case its not, if you got a error saying that sh ip ssh is not recognized then you would know that ssh is not supported or possibly that the command is different for your platform. How to enable SSH on a Cisco 800 series router# config term router(config)#crypto key generate rsa usage-keys label router-key The name for the keys will be: router-key Choose the size of the key modulus in the range of 360 to 2048 for your

INSTALL DOT NET FRAMEWORK ON MULTIPLE SERVERS USING POWERSHELL SCRIPT

Installing .Net 4.5.2 $servers = Array of Servers foreach($server in $servers) { Write-Host “Copying the installation file” copy-item  –path “-SOURCE” –destination “ destination ” Write-Host “Installing .NET 4.5.2” Invoke-Command –Computername $server –Credentials xxxx { C:\Temp\ NET 4.5.2  /passive /norestart }

Connection failed: enforce firewall policy failed (on win 7 / 64bit)

Connection failed: enforce firewall policy failed (on win 7 / 64bit)  error: connection failed: enforce firewall policy failed client: Check point endpoint security r75 build 835002205 on win 7 / 64 bit The solution is to find driver file vsdatant.sys and copy it to system32/drivers Ref :- https://forums.checkpoint.com/forums/thread.jspa?messageID=46927