Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: ICACLS command line doubts.  (Read 3299 times)

0 Members and 1 Guest are viewing this topic.

Jonathas

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 10
    ICACLS command line doubts.
    « on: May 31, 2018, 09:08:38 AM »
    Good Morning.

    I have searched these last days about giving permission in folders through the CMD, and I have almost arrived where I wanted, missing a detail that I do not know if it is possible or not.
    See if you can help me.
    It has a folder, eg C: \ "Hardware_Test", which is always created on the local disk, but does not have a default, can be in C, D etc.
    Using the ICACLS command I wanted to give full permission on this folder to all users.
    But I would like to know if there is any command or something of the genre that searches for that folder and the permission, without having to keep putting all the possible disks in the batch.
    For example:

    Code: [Select]
    ICACLS C: \ Hardware_Test / grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" / T
    ICACLS D: \ Hardware_Test / grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" / T
    ICACLS E: \ Hardware_Test / grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" / T

    And so on, if you could search for the folder name and execute ICACLS, you would not have to write multiple command lines, just one.
    That is, a command that searches where the folder is, and then run ICACLS.
    Does anyone know if this is possible?

    Salmon Trout

    • Guest
    Re: ICACLS command line doubts.
    « Reply #1 on: June 01, 2018, 12:21:17 AM »
    I think you may have put extra spaces in your command line above.  This checks all fixed disks:

    Code: [Select]
    for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do (
        ICACLS %%d\Hardware_Test /grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" /T
    )
    « Last Edit: June 01, 2018, 12:42:58 AM by Salmon Trout »

    Salmon Trout

    • Guest
    Re: ICACLS command line doubts.
    « Reply #2 on: June 01, 2018, 12:46:07 AM »
    Or just do this if you already know what drive letters you need to check:
    Code: [Select]
    REM disks to check separated by spaces
    for %%d in (c: d: e: f: g:) do (
        ICACLS %%d\Hardware_Test /grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" /T
    )

    Jonathas

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 10
      Re: ICACLS command line doubts.
      « Reply #3 on: June 01, 2018, 08:43:38 AM »
      I think you may have put extra spaces in your command line above.  This checks all fixed disks:

      Code: [Select]
      for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do (
          ICACLS %%d\Hardware_Test /grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" /T
      )

      Thank you very much for the quick response.
      This command line that you passed, somehow is giving error.

      Code: [Select]
      \ Hardware_Test: The filename, directory name, or volume label syntax is incorrect.
      Successfully processed 0 files; Failed processing 1 files
      \ Hardware_Test: The filename, directory name, or volume label syntax is incorrect.
      Successfully processed 0 files; Failed processing 1 files
      \ Hardware_Test: The filename, directory name, or volume label syntax is incorrect.
      Successfully processed 0 files; Failed processing 1 files

      Changing the command line, in place of ICACLS I put ECHO %% d, the result gave this:

      Code: [Select]
      C:
      D:
      E:

      I looked at the FOR command (which I did not know) and saw that it was all right (for me at least).
      Because the command is transforming the C: | D: | E: in variable %% d.
      You are then placing this variable in place of the Local Disk before the rest of the folder.
      What could be making this mistake?

      OBS: The second alternative that you showed me, worked, but I liked this first more.
      OBS2: As test in the computer has the Local Disk C, D and E.

      Salmon Trout

      • Guest
      Re: ICACLS command line doubts.
      « Reply #4 on: June 01, 2018, 01:37:08 PM »
      Where did you get that ICACLS command from? It isn't right.
      Code: [Select]
      ICACLS C: \ Hardware_Test / grant "All: (OI) (CI) F" "Administrator: (OI) (CI) F" / T

      Salmon Trout

      • Guest
      Re: ICACLS command line doubts.
      « Reply #5 on: June 01, 2018, 01:46:33 PM »
      I fixed the FOR structure, and more importantly your ICACLS syntax. Did you even test it? You may have to get proper ICACLS permissions for this to work. I cannot help you with that.

      Code: [Select]
      @echo off
      for /f "skip=1 tokens=1-4 delims= " %%a in ('wmic logicaldisk get caption^,providername^,drivetype^,volumename') do (
      if "%%b"=="3" ICACLS %%a:\Hardware_Test /grant "All:(OI)(CI)F" "Administrator:(OI)(CI)F" /T
      )

      Jonathas

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows 10
        Re: ICACLS command line doubts.
        « Reply #6 on: June 01, 2018, 01:56:42 PM »
        Oh really?  ???
        I'm a beginner in this area, I needed to automate the folder permissions, so I simply went searching and searching until I found something and got this command.
        Now, if it's not right, I need more help if it's not uncomfortable  :).
        Let me keep you abreast of the situation, many times (for reasons I do not know) the folders of a program (where I work) and the folder PRINTERS, lose permission on some clients, causing them to have to release all manually.
        I thought about creating a script that would automatically free these folders.
        But as I said, it depends on the client gets on the local disk C another in D and etc.
        Can you help me?
        EDIT: I saw your second answer after I sent you my message, I'll test it.
        Thank you very much.