473,790 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ 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 9914
Use the System.IO.Direc toryInfo and System.IO.FileI nfo classes, in tandem
with the System.Security .AccessControl. DirectorySecuri ty 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.S etAccessControl method (to which an instance of the
DirectorySecuri ty is passed) to set the permissions for that Directory. For
each FileInfo, use the FileInfo.SetAcc essControl method to set the
permissions for that file. The method then calls the
DirectoryInfo.G etDirectories 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. DirectorySecuri ty
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*********@gm ail.comwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.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
2767
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 directory can be changed. I am doubt about it who can tell me how to change install directory?
1
1754
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 workgroup information file". I'm not using anything more than the system.mdw for the workgroup info file. There isn't even a password on the database. Any ideas? Thanks!
1
3777
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 ? ImportError: no module named datetime " The line 3 is writen: "from datetime import datetime,
4
1864
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 required property or there is some way to do that? What I see now is a poor documentation on the Internet about that. Thanks, Just D.
2
1765
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 directory's permissions is when the directory is made with mkdir() -- Karl Groves
3
13122
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
1214
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
4537
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, i also tried using Process and spawning a DOS rmdir command but that it quite inelegant. any ideas as to how to cleanly do this? thanks, dave
0
850
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 tryed it but not working.
0
10413
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
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 we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.