Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing windows files permissions by code
Message
From
22/11/2006 07:28:28
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
 
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01171171
Message ID:
01171705
Views:
19
Or even without WSH you can use shellexecute example:
DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
	    INTEGER nWinHandle,;
	    STRING cOperation,;   
	    STRING cFileName,;
	    STRING cParameters,;
	    STRING cDirectory,;
	    INTEGER nShowWindow

lcOperation = "Open"
lcFilename = "cacls.exe"
*
* /T Means Change permissions on the current dir, 
* files under that dir and also all subdirs and files under that subdirs.
* /E means EDIT permissions instead of replacing
* /P means replace if the user already exist and the syntax is
* /P UserAccount:N for None
* /P UserAccount:R for Read
* /P UserAccount:W for Write
* /P UserAccount:C for Change the modify oprion in windows explorer
* /P UserAccount:F for Full control
* more parameters and switches can be found if you run cacls.exe in any command window.
*
lcParams = "c:\directory /T /E /P Everyone:F"
ShellExecute(0,lcOperation,lcFilename,lcParams,"",0)
Cacls.exe is present on any Windows version from nt4 or above, not in Win95/98 or millennium.

Now if you where to use .NET 2.0 this could also be done inside the framework not needing to call any outside exe's.

>Good tip.
>
>If WSH is allowed, one can use that for the use of CACLS. The advantage is that, as compared to using RUN, the appearance of the dos-window can be suppressed with the 3rd parameter.
>
>
oShell = createobject("WScript.Shell")
>lcRun = "CACLS file.txt /P JIM:F < yes.txt"
>lnRC = oShell.Run(lcRun, 1, .T.)
>
>
>>What about using CACLS.EXE since that is present on any machine running winnt 4 or above.
>>
>>>>True. However, it is more than nothing. What do you additionally suggest?
>>>
>>>I thought of SetFileSecurity but I don't have ready out of the box code for that one.
>>>Cetin
Alexandre Palma
Senior Application Architect
Previous
Reply
Map
View

Click here to load this message in the networking platform