C# Programmatically Setting Permissions and Compressing a Folder (NTFS)

S

steggun

Hello,

I'm writing a C# windows form application and need some guidance on a couple
of issues.

First, my application needs to change the permissions on a folder. The
application creates a local group and I need to give that group Full Control
permissions to a folder on the file system. Would anyone know how to
accomplish this?

Next, my application also needs to programmatically set the properties of a
folder so that it's compressed. Would anyone know how to accomplish this?

Thanks!
 
W

Willy Denoyette [MVP]

| Hello,
|
| I'm writing a C# windows form application and need some guidance on a
couple
| of issues.
|
| First, my application needs to change the permissions on a folder. The
| application creates a local group and I need to give that group Full
Control
| permissions to a folder on the file system. Would anyone know how to
| accomplish this?
|
| Next, my application also needs to programmatically set the properties of
a
| folder so that it's compressed. Would anyone know how to accomplish this?
|
| Thanks!
|
|
|

When using V2 of the FCL you can use the FileSecurity class in the
System.Security.AccessControl namespace to change the access rights of a
filesystem object. The "compressed" FileAttribute of the DirectoryInfo class
can be used to set the compressed attribute of a folder. However, be aware
that you need to run as an administrator to be able to do this, which is a
bad idea, user applications should never run with administrative privileges.
Much better is to delegate this to an "administrative" application that
could be run as a COM+ server type application (check the
System.EnterpriseServices namespace), this application can run as
administrator while yours keep running with restricted privileges.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top