Jump to content
Sign in to follow this  
Keniger

Setting permissions on folder/file

Recommended Posts

Keniger

Hello Guys !

I have a little problem, I create programm. And I need change permission to file, as example I wanna to change security tab permission to only read file, (Cant be run only read)

Is that possible to do ?

I don't want FileSetAttrib - Its not the same thing that I wanted ;x

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, Keniger. Are you talking about setting NTFS permissions on a per-user basis? Below is something I threw together a couple years ago that works for setting permissions on a directory; needs some consolidating but it may give you a place to start:

$UID = InputBox("Grant Access", "Enter the user ID")
$dir = InputBox("Directory", "UNC path to parent directory")
$perm = InputBox("Level of Access", "Enter the level of Access: C(hange), F(ull control), R(ead only), W(rite)")

While 1
$dir2 = FileSelectFolder("Choose a folder.", $dir, 1)
     RunWait( 'CACLS "' & $dir2 & '" /E /G ' & $UID & ':' & $perm, "", @SW_HIDE )
     $ok = MsgBox(4, "Complete", "Would you like to specify another directory?")
If $ok = 7 Then ExitLoop
WEnd

MsgBox(0, "Access Granted", "Access has been granted to the specified directories.")
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

Keniger,

Seems that cacls is deprecated with Win7 (if that is what you are using) although some report that it still works...see this thread

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
JLogan3o13

I just tried this script on a couple directories (as I admit, it has been some time since I played with it). It seemed to set the permissions just fine on Win7 x64.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

I just tried this script on a couple directories (as I admit, it has been some time since I played with it). It seemed to set the permissions just fine on Win7 x64.

Yes, the threads I've read report mixed reuslts in Win7...

Just thought th OP should be aware of this..

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Kondro

This is great! Ive been looking for a way to change folder permisions for our apps the require Admin rights to run, but without giving full local admin rights. it works great when i input my AD user name but does not work if i enter "Domain Users". I modified the script to not promp and directly told it what user and folder to modify. (Script Below) Any idea what i could try to make it find a AD group VS a user?

 

$UID = "Domain Users";InputBox("Grant Access", "Enter the user ID")
$dir = "C:Temp";("Directory", "UNC path to parent directory")
$perm = "W";InputBox("Level of Access", "Enter the level of Access: C(hange), F(ull control), R(ead only), W(rite)")

While 1
$dir2 = "C:Temp";FileSelectFolder("Choose a folder.", $dir, 1)
     RunWait( 'CACLS "' & $dir2 & '" /E /G ' & $UID & ':' & $perm, "", @SW_HIDE )
     $ok = MsgBox(4, "Complete", "Would you like to specify another directory?")
If $ok = 7 Then ExitLoop
WEnd

MsgBox(0, "Access Granted", "Access has been granted to the specified directories.")

Edited by Kondro

Share this post


Link to post
Share on other sites
Kondro

I figured it out - changed domin users call to

'"Domain Users"'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×