Scripting Question

Setting Permissions

09/21/2015 1681 views

I need help in setting permissions to files. I need to collect all files in %temp% and log them to a files.txt file and then need to change permission in files.txt and set it back to its original permissions.

any help is appreciated.
1 Comment   [ + ] Show comment


  • I got it I used the below cmd lines and it worked for me thanks all for your suggestions.

    fpr /F "tokens=*" %%J in (%temp%\Dirlist.txt) do icacls "%%J" /grant BUILTIN\Users:(m)

All Answers


Your request is a bit confusing.  Users have R/W access to the temp folder, so what has to be changed?  If you need to change file permissions from a CMD window, look into the ATTRIB command.

If you need to create a TXT file which contains the list of files in the folder, simply redirect the output of a DIR command into a file like so:

DIR *.* > %TEMP%\DirList.txt

Answered 09/21/2015 by: vjaneczko
9th Degree Black Belt

  • Yes you are right Users folder have R/W access but when I scan some users folder in our organization and we came to know that some of the files in %temp% folder does not have R/W access to other users except the users who created. so in order to modify that file I need to take over the rights on those files. So the first answer I got
    I can direct the output by this CMD DIR *.* > %TEMP%\DirList.txt and then how I can I change permissions in DirList.txt and then set it back to its original permissions.
If, by "permissions", you mean the ACLs, there are no native commands to deal with those. Obtain and use either SubInACL or, as I prefer, SetACL.
Answered 09/22/2015 by: VBScab
Red Belt

  • How can I setACL to all the files which are in only %TEMP%\DirList.txt
  • iCacls?
    • can you give an example how to set modify permission in "%temp%\DirList.txt'
      NOTE: need to give permission to the files which are in DirList.txt and not to DirList.txt
Capture this with RayPack , RayPack has the ability to capture Permission Changes on the target machine.
Very easy because you can now first make sure the permissions are set correctly and then finalize the capture.

download a free evaluation here: https://raypack.raynet.de/en/contact 

Answered 09/22/2015 by: jaybee96
Red Belt

>How can I setACL to all the files which are in only %TEMP%\Dirlist.txt?

You need to create a script but why bother, when your command line lists all files, i.e. *.*? And why do you need to change permissions back? Used correctly, SetACL adds the specified account to the ACL, it doesn't replace the existing permissions.
Answered 09/23/2015 by: VBScab
Red Belt

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ