Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to prevent access permissions on writing a file in an exe windows application c#....

Quote:
Korathu 2 - 6 mins ago
I am creating an exe file and creating database after installing the setup..then i am writing the server details etc to a txt file with in c drive and converting into zs file..But file isn't getting created....Access denied permission shown....


Quote:
Korathu 2 - 4 mins ago
I want to set write permission code behind
Posted
Updated 18-Apr-13 3:12am
v2
Comments
Johnny J. 18-Apr-13 8:43am    
Don't understand! Please try to reformulate your question and give some more information about what you're trying to do.
OriginalGriff 18-Apr-13 8:54am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Korathu 2 18-Apr-13 9:04am    
I am creating an exe file and creating database after installing the setup..then i am writing the server details etc to a txt file with in c drive and converting into zs file..But file isn't getting created....Access denied permission shown....
Korathu 2 18-Apr-13 9:06am    
I want to set write permission code behind
Maciej Los 18-Apr-13 9:13am    
Please, use "Improve question" to update it.

My immediate guess is this:

You have to run your application with Admin rights to save the file. It's not enough that your user account is an admin account.

You can do this by changing the program manifest: Right click your project in the solutions explorer, add new item and choose application manifest.

Open the manifest and change

HTML
<requestedexecutionlevel level="asInvoker" uiaccess="false" />

to
HTML
<requestedexecutionlevel level="requireAdministrator" uiaccess="false" />


Just my guess...

Also be aware that Windows will try to protect some parts of your file system more than others. It can be hard to get access to write a file in the C-root or in e.g. C:\Windows.

It's easier to get permission to write in the document folder or the app's program data folder.
 
Share this answer
 
v3
Visual Studio Solution:

in setup project, go to file system editor, create a new folder in User Application Data Folder. for an example, we assume that you are naming this new folder as 'MyApplicationDataFolder'

then create/write your file in 'this' folder (MyApplicationDataFolder). Becauseyour setup has created this folder, your application will have write permissions on its files.

if your business logic requires that the file is in C: drive only, then after creating the file, try to copy that into C: drive. Copy, NOT move.

and yes, as Johny J. suggested, you will need to have admin rights.
 
Share this answer
 
v2
Comments
Korathu 2 18-Apr-13 11:17am    
Can you explain more in detail..Want to do so code behind or during deploment...
Install in another partition[not install in C]
it works with me :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900