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

Schedule Automatic backup config in Cisco Nexus

Schedule Automatic backup config in Cisco Nexus Nexus-Sw1(config)#feature scheduler   //Enable scheduler service in Nexus Nexus-Sw1(config)#scheduler job name backup-daily      // Job Name Nexus-Sw1(config)#scheduler aaa-authentication username abcd password abcd@123     // AAA - Authentication for Job created above (If AAA configured) Nexus-Sw1(config)#scheduler job name backup-daily copy running-config tftp://192.168.1.23/$(SWITCHNAME)-cfg.$(TIMESTAMP)         //IP of TFTP SERVER , file will saved with switch name and timestamp exit Nexus-Sw1(config)#scheduler schedule name backup-daily   // Setup Schedule to run for the JOB Nexus-Sw1(config-schedule)# time ?   daily    Specify a daily schedule   monthly  Specify a monthly schedule   start    Specify a future time schedule   weekly   Specify a weekly schedule...

Duplicate IP Address has been Detected Rule

A duplicate IP address has been detected on the network Rule Knowledgebase Summary This rule generates an alert when Windows® detects that he local machine’s IP address is in conflict with one or more identical IP addresses on the network. Until the IP address conflict is resolved, remote clients and applications may have difficulty accessing resources on any of the effected computers. Additionally, the local computer may not be able to access network resources. Related Events This rule generates an alert whenever the following events occur and are recorded in the System Event Log: The system detected an address conflict for IP address %2 with the system having network hardware address %3. The local interface has been disabled. Source: TCPIP; Event ID: 4198; The system detected an address conflict for IP address %2 with the system having network hardware address %3. The local interface has been disabled. Source: TCP...

Shunned packet Error on Cisco ASA Firewall

           Shunning/Blocking on IPS for  ASA/PIX/IOS Router Configuration Example   Advanced Threat Detection feature – This feature does a bunch of things. It detects and alerts on activity that might be related to a Denial of Service attack or Scanning reconnaissance. Optionally, the ASA can automatically shun/block hosts that are detected as a scanning threat. Threat detection also can gather threat statistics for display on the new Firewall Dashboard inside the ASDM GUI. Top 10 graphs, charts, and lists for things like access list hits, services most used, and top IP SRC and IP DST hosts are tracked. On Cisco routers and Catalyst 6500 series switches, ARC creates blocks by applying ACLs or VACLs. ACLs and VACLs apply filters to interfaces, which includes direction, and VLANs, respectively in order to permit or deny traffic. . The PIX Firewall, FWSM, and ASA do not use ACLs or VACLs. The built-in shu...