473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

recursively change permissions of a directory

Aek
What is the best way to recursively change the permissions of the
directory we are installing into? Is there a nice way to do this in C#
..NET?

We are using an MSI installer and will need to add some custom actions
to change the permissions on the install directory and its sub
folders/files so that they can be accessed correctly via a network
share later on.

We would want to add Everyone full access to the install directory (its
a closed 3 node system running custom application on winXP pro, so
security isnt an issue)

I found a win32 C++ example but it was quite involved.

I would prefer some C# .NET.
The other alternative is to use cacls in a batch file but this is less
than ideal as we have less control over things when something goes
wrong for the user.. if we have C# code we can raise errors, log
things, popup nice informative error messages etc.

thanks

Josh

Jul 27 '06 #1
1 9894
Use the System.IO.DirectoryInfo and System.IO.FileInfo classes, in tandem
with the System.Security.AccessControl.DirectorySecurity and
System.Security.AccessControl.FileSecurity classes, in a recursive method.

What you do is to create a method to which you pass the path to a Directory.
The method gets a DirectoryInfo instance for that Directory, and uses that
to get an array of FileInfo instances, using the GetFiles method. It then
uses the DirectoryInfo.SetAccessControl method (to which an instance of the
DirectorySecurity is passed) to set the permissions for that Directory. For
each FileInfo, use the FileInfo.SetAccessControl method to set the
permissions for that file. The method then calls the
DirectoryInfo.GetDirectories method to get a list of DirectoryInfo instances
within that Directory, and calls itself for each DirectoryInfo in the list.

See
http://msdn2.microsoft.com/en-us/lib...ysecurity.aspx
for documentation about the System.Security.AccessControl.DirectorySecurity
and FileSecurity classes.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.
"Aek" <ae*********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
What is the best way to recursively change the permissions of the
directory we are installing into? Is there a nice way to do this in C#
.NET?

We are using an MSI installer and will need to add some custom actions
to change the permissions on the install directory and its sub
folders/files so that they can be accessed correctly via a network
share later on.

We would want to add Everyone full access to the install directory (its
a closed 3 node system running custom application on winXP pro, so
security isnt an issue)

I found a win32 C++ example but it was quite involved.

I would prefer some C# .NET.
The other alternative is to use cacls in a batch file but this is less
than ideal as we have less control over things when something goes
wrong for the user.. if we have C# code we can raise errors, log
things, popup nice informative error messages etc.

thanks

Josh

Jul 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simon Peng | last post by:
I install vs.net2003 in my pc which hasn't install it before I can't change install directory, it is only installed in C:\Program Files\Microsoft Visual Studio .NET 2003 But in other pc, this...
1
by: Jozef | last post by:
Hello, I have some code pasted below. It works down to the line where it sets the permissions for the document and throws an exception "Runtime error 3358; Cannot open the microsoft jet...
1
by: ye juan | last post by:
Hi, all I have some questions to ask: 1. How can I add a standard module named "datetime" in Jython when the error happens :"Traceback (innermost last): File "C:\python\test.py", line 3, in...
4
by: Just D. | last post by:
How can we change the property of one subdirectory of the Virtual Directory? One of the directories should be granted "Write". Should we delete this Virtual Directory to recreate it with the...
2
by: Karl Groves | last post by:
Can anyone tell me how to go about changing a directory's permissions once it already exists? I see in the manual how to do that to a file, but the only thing I've found when it comes to a...
3
by: gemstone | last post by:
hi guys, i wanna copy a directory with all its sub directories, to another directory. pls help. its urgent. i even tried xcopy, but in vain
1
by: DR | last post by:
How to change what directory tfs "get latest version" saves to? I made it desktop the first time it prompted me but want to change the directory to somewhere else..
3
by: Dave | last post by:
Directory.Delete(path, true (recursive)) throws an exception of the directory is not empty. silly as they could have overloaded the method further providing for deletions with files... anyway,...
0
by: navanathj | last post by:
I am installing windows installer on my machine but its not working. But when i change permissions of the app_data folder in which i store my database file. That time it will installed properly. I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.