Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > How to set Full Control Permission to a Folder in Windows Vista Programmatically?
 

How to set Full Control Permission to a Folder in Windows Vista Programmatically?

I am using Windows Forms (C#)

I need to Set Full Control Permission to a Folder (or a file) e.g. C:/Program Files(86)/MyProject

How can I do that programmatically?

Then I will need to put it as a Lauch Condition after the Installation Commit phase (that's why it's posted in this Forum).

I am the Administrator, but when the Folder is created by the applicationdoesn't have Full Control Permission.

OS doesn't let me use DirectorySecurity either.

Any idea?

Dynamic  Friday, July 04, 2008 10:59 AM

Just as an aside, the reason this is difficult is because Microsoft strongly advises against putting any kind of data or anything that needs to be updated and written to by your application in Program Files. They secured the Program Files area to increase the security of people's computers, and reduce the likelihood that someone could mess with your other software in a virus or some other type of malware.

Not even Adobe writes cached data to ProgramFiles any more; they actually create an Adobe folder under the users MyDocuments folder.

The recommended place to store any files that you want to update is Environment.SpecialFolders.LocalApplicationData or MyDocuments, under a folder you create with the same name as your application or company.

You can change over now and use the new methodology that will be in place in Vista and in subsequent Operating Systems released by Microsoft, or you can continue to swim upriver against the tide.

Just something to think about.

RobinS.

GoldMail.com

RobinDotNet  Friday, July 04, 2008 7:43 PM
I am also in the same boat, looking forward to see the response.

Btw, I have posted a similar enquiry to the forum: http://www.vistax64.com/showthread.php?p=766963#post766963

Regards,
MA
MA_NSW  Friday, July 04, 2008 12:59 PM

I found this link

http://weblogs.asp.net/cumpsd/archive/2004/02/08/69403.aspx

But the problem is that i can't find the System.Win32.Security class or any dll for it

If you found anything please can you share

Thanks

Dynamic  Friday, July 04, 2008 1:19 PM

Hello mate,

I found the dll from here Smile

http://www.codeproject.com/KB/dotnet/ntsecuritynet.aspx

Hopefully the problem will be resolved now!

No, doesn't seem to work

Stil looking ...

Dynamic  Friday, July 04, 2008 1:42 PM

Just as an aside, the reason this is difficult is because Microsoft strongly advises against putting any kind of data or anything that needs to be updated and written to by your application in Program Files. They secured the Program Files area to increase the security of people's computers, and reduce the likelihood that someone could mess with your other software in a virus or some other type of malware.

Not even Adobe writes cached data to ProgramFiles any more; they actually create an Adobe folder under the users MyDocuments folder.

The recommended place to store any files that you want to update is Environment.SpecialFolders.LocalApplicationData or MyDocuments, under a folder you create with the same name as your application or company.

You can change over now and use the new methodology that will be in place in Vista and in subsequent Operating Systems released by Microsoft, or you can continue to swim upriver against the tide.

Just something to think about.

RobinS.

GoldMail.com

RobinDotNet  Friday, July 04, 2008 7:43 PM

Hi Robin,

Thanks for your answer, it was good to know though I found a way to communicate with the Windows API for that.

Swimming against the flow teacheslessons which can not be learnt when swimming with the flow... Wink

But, I will go with your recommendation Smile

thanks

Dynamic  Friday, July 04, 2008 7:49 PM

LOL. Yes, sometimes you have to go against the flow, but you have to pick your moments.

Good luck, and post back if you have any more questions.

RobinS.

GoldMail.com

RobinDotNet  Sunday, July 06, 2008 5:38 AM

Thanks Robin,


Just a simple question

When I set the LocalApplicationData from the application, it refers to C:\users\me\AppData\Local

When setting up the application using the Setup Project, I assume the xml file I have (Parameters.xml) should be placed in that folder (like under a custom folder "MyProject"), though I see no Special Folder to refer to where LocalApplicationFolder refers to.

"User's Application Data Folder" refers to: C:\Users\me\Documents

"User's Personal Data Folder" referes to: C:\Users\me\AppData\Roaming

How do you suggest configuring the Setup Project to use LocalApplicationData?

I resolved my problem in another way;using "ApplicationData" instead in the application and"User's Personal Data Folder" in the Setup Project.

Dynamic  Tuesday, July 08, 2008 12:57 PM

When you do this:

Code Snippet

string userFilePath =

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

userFilePath is "C:\Users\me\Documents" ?? That should be what you get when you look at Environment.SpecialFolder.MyDocuments.

Where are you getting your definitions for "Users' Application Data Folder" and "User's Personal Data Folder" ?

RobinS.

GoldMail.com

RobinDotNet  Tuesday, July 08, 2008 3:33 PM

Hi Robin,

Using the code you wrote, for me theLocalApplicationData refers to C:\Users\me\AppData\Local not "C:\Users\me\Documents"

The other 2 are special folders specified in the Setup Project/View/File System

Dynamic  Tuesday, July 08, 2008 4:18 PM

In terms of my code, that's right. That's where you can put data for your application where you can get to it, and write to it, but you have to do it in your application. We do it in Program.cs before the forms are started up.

As for the setup project, I can't help you with that; my expertise (such as it is) is in ClickOnce deployment.

RobinS.

GoldMail.com

RobinDotNet  Monday, July 14, 2008 5:10 AM

Your approach:

Each time you have to copy the fileto the LocalApplicationFolder (or check its existence)at the startup of the application (as you said in Program.cs)thenwriting the data there.

My approach:

Whereas, I have put it in the Setup Project, so the file will be created only once when installaing the tool, not each time starting up the application.

I had used ClickOnce beforeand had some security issue, my client couldn't download the installation files but I will try it again.

Other thing, I found deploying database and upgrading it very difficult in Windows Based development since each client has its own copy of database objects, while in Web based its in one central place, much easier to do so.

I used Updater Application Block to do it, but was complex. Microsoft has suggested any other approach?

Maybe I should put it in another thread topic!

Regards

Dynamic  Monday, July 14, 2008 10:57 AM

We only do it the first time the user runs the application. This doesn't work with a SQLExpress database, by the way, as someone recently found out.

For deploying a SQLExpress database, you have to go to measures to handle that. You can move a SQLCE database or an Access database off to another folder, though. If you are using full-blown SQL on a server, that requires nothing but a connection string.

ClickOnce is for fairly simple applications, not for deploying apps that have a lot of complexity to the deployment, although some of that can be handled in prerequisites. For really complex deployments, a setup & deployment package is more appropriate.

Good luck!

RobinS.

GoldMail.com

RobinDotNet  Monday, July 14, 2008 5:50 PM

You can use google to search for other answers

Custom Search

More Threads

• Deploy - improperly formatted
• Is it possible to use a remote Application Directory
• Unable to build a Setup and Deployment Project
• How to create online installer in vb.net
• Display 'New Programs Installed' after installation
• Launch a specific ClickOnce version
• Delete old versions from client
• Setup project. [Manufacturer] parameter - VS2008
• Change Web Services Reference path
• Using Winforms in IE with Apache running