Jump to content
Sign in to follow this  
mohammadezazi

I can't set correct permission to a folder

Recommended Posts

mohammadezazi

Hi.
Please help me to create a share folder with these permissions (in Domain invironment):

 

Just:
Everyone Read

CurrentUser Read and Write

 
I use a code such this : (But it is not that i want)

The Share permissions is not important for me, but the Security permissions is my weakness.

#include <Permissions.au3>
#include <Process.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>

_InitiatePermissionResources()
   
   If DirCreate("d:\"&@ComputerName) Then 
      $mypath = "d:\"&@ComputerName
   ElseIf DirCreate("E:\"&@ComputerName) Then 
      $mypath = "E:\"&@ComputerName
   ElseIf DirCreate("F:\"&@ComputerName) Then 
      $mypath = "F:\"&@ComputerName 
   ElseIf DirCreate(@DocumentsCommonDir&"\"&@ComputerName) Then 
      $mypath = @DocumentsCommonDir&"\"&@ComputerName
   EndIf
      
   Runwait(@ComSpec & " /c net share "&@ComputerName&"="&$mypath )
   $TI = TimerInit()
   $ret = _myGrantReadAccess($mypath,$SE_FILE_OBJECT,'Administrators')
   $ret = _myGrantAllAccess($mypath)
   $TD = TimerDiff($TI)
   _ClosePermissionResources()
  
Func _myGrantReadAccess($oName, $_SE_OBJECT_TYPE = $SE_FILE_OBJECT, $SetOwner ='Administrators', $Recurse = 1)
    Local $aPerm[6][3]  
   $aPerm[0][0] = 'Everyone'
   $aPerm[0][1] = 1
   $aPerm[0][2] = $GENERIC_WRITE
   ;$aPerm[1][0] = $regloginuser
   $aPerm[1][0] = 'Administrators'
   $aPerm[1][1] = 1
   $aPerm[1][2] = $GENERIC_ALL  
   $aPerm[2][0] = 'System'
   $aPerm[2][1] = 1
   $aPerm[2][2] = $GENERIC_ALL   
   Return _SetObjectPermissions($oName, $aPerm, $_SE_OBJECT_TYPE, $SetOwner, 1, $Recurse)   
 EndFunc ;==>_GrantReadAccess

 Func _myGrantAllAccess($oName, $_SE_OBJECT_TYPE = $SE_FILE_OBJECT, $SetOwner = 'Administrators', $Recurse = 1)
    Local $aPerm[1][3]
    $aPerm[0][0] = 'Everyone'
    $aPerm[0][1] = 1
    $aPerm[0][2] = $GENERIC_ALL
    Return _SetObjectPermissions($oName, $aPerm, $_SE_OBJECT_TYPE, $SetOwner, 1, $Recurse)
EndFunc ;==>_GrantAllAccess

Share this post


Link to post
Share on other sites
water

You need to add some error checking to your script. How do you know if there is a problem with _SetObjectPermissions and the permissions haven't been set properly?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×