Windows 7 Script for change files permissions

Discussion in 'Programming and Scripting' started by adamquadmon, Sep 30, 2011.

  1. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    Hi, I've a problem with a software that create some files, those Child objects do not inherit permissions from their parent as expected.

    To solve this issue I have to manually edit the parent permission and give to his childs the same permissions of the folder itself. The checkbox solud be: Replace all permissions for child objects with inheritable permissions derived from this object
    (I use an italian version of seven, so I don't know how this label is in english)

    I need to make a script that each x time (1 time a day) run this command.

    What should I look for?
    I can create a .bat or somthing like this and then shedule it.
    Bud I've never did this before, and I don't know how to find the right command

    any tips?
     
    shopchvvn likes this.
  2. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    Hi
    Id need the Full path of the location to the folder, What permission you are wanting , if its full access or deny access , ill wip you something up
     
  3. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    logged users should read the files
    the path is C:\Danea\Archivi

    if you can write a script I'd like to read it, and undrstand wat's up.

    thanks a lot for help me. :redface:
     
  4. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    your more than welcome.

    are you wanting read only on the content after "C:\Danea\Archivi/(here)" or full access , read write etc?
     
  5. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    if you can write such as

    full control (unticked)
    write (TICK)
    read (TICK)
     
  6. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    I need only read perms.
     
  7. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    ok ill work on it now for you
     
  8. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    ok these are based on the fact
    READ + EXEC
    READ
    WRITE - DENY
    SPECIAL PERMS -DENY

    there is no point implying a read only command if not DENY commands arnt set, as you can still write to the files

    here is the code used

    Code:
    @echo off
    cls
    title File Permissions
    
    echo.
    Echo Set File Permisions
    echo.
    echo Deny write + Read
    echo (execute also included as mandatory)
    echo.
    Echo 1) Apply Read only
    echo 2) Reset (Full Control)
    
    set choice= 
    set /p choice=Please select your option: 
    IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
    if '%choice%'=='1' goto enab
    if '%choice%'=='2' goto reset
    
    
    
    :enab
    cls
    cacls "C:\Danea\Archivi/*.*" /p %username%:n
    echo.
    cacls "C:\Danea\Archivi/*.*" /e /g %username%:r
    exit
    
    
    pause
    
    :reset 
    cacls "C:\Danea\Archivi/*.*" /e /g %username%:f
    pause
    
    
    copy it into notepad

    save it as "anythin you wnt ere".bat

    i.e Permissions.bat
    or
    Fileperms.bat

    wat ever
     
  9. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    good!

    I need to make this script run without any userinput, I should add it to a cron.

    I changed it as that:

    Code:
    @echo offcls
    title File Permissions
    
    
    cls
    cacls "C:\Danea Easyfatt\Archivi\Amodio - Allegati\Doc\*.*" /p "Authenticated Users":n
    echo.
    cacls "C:\Danea Easyfatt\Archivi\Amodio - Allegati\Doc\*.*" /e /g "Authenticated Users":r
    exit
    But when I run it, it ask for confirmation (Y/N)
     
  10. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    It must have user input , The cacls command doesnt have a switch /y command for an auto answer
     
  11. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    ouch!:frown:

    is there another way that don't require user input?
     
  12. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    Sorted it for you, Took me some time HOWEVER this works

    Code:
    :enab
    cls
    echo y| cacls "C:\Danea\Archivi/*.*" /p %username%:n
    echo.
    echo y| cacls "C:\Danea\Archivi/*.*" /e /g %username%:r
    exit
    
    

    I Have piped the command into the initial command
     
  13. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    perfect!

    thanks a lot!!!
     
  14. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    your welcome


    any more scripts or anything then let me no, we can create loads of different tasks from file hiding to locking etc
     
  15. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    I'd like to learn how make it by myself, where can I find a reference?
     
  16. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    well depends on what you want to acheieve,what you want to show or act etc

    id start basic, i would jump in the deep end creating mad stuff. start small... do something write text, then it clears

    so basics would be

    @echo off (always use this)
    cls - clear screen
    echo - echos text so to start would be
    pause - waits , press any key to continue

    @echo off
    cls
    echo hello
    pause

    the displays the word hello, and text after the echo
    to create space would be

    @echo off
    cls
    echo hello
    echo.
    echo how are you

    this would be like
    Code:
    Hello
    
    How are you
    
     
  17. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    Is there a reference with all the possible commands?
     
  18. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    Windows CMD Commands

    That has a list of commands, applying them into a script maybe a little harder than it looks BUT im here if u need help. Wat was u thinking of creating?
     
  19. adamquadmon

    adamquadmon New Member

    Joined:
    Sep 30, 2011
    Messages:
    18
    Likes Received:
    1
    moving files from a source to a destination, something very easy, the list you post is what I'm looking for... thanks for all!
     
  20. kaos

    kaos Senior Member

    Joined:
    May 9, 2011
    Messages:
    1,747
    Likes Received:
    33
    ok this is an example

    Code:
    
    @echo off
    cls
    color A 
    set /p f=Files to be moved:
    set /p d=Destination :
    xcopy %f%" "%d%
    pause
    
    
    so F is basically an open variable meaning that F can be anything i.e a path in our example. the D as our second as our destionation.. once these are set we use the normal command xcopy then outputting what we first specificed which was f and d

    you can drag a file onto the cmd window to auto populate the path but on the destination you have to make sure that the path endings with a /
    e.g c:/program files/document.txt
    to
    c:/program files/test folder /
    without that the file wont move
     

Share This Page

Loading...