Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a program and in that when you click the button it will be create a folder and move the file to folder and delete it and this is the code i wrote for give it access its this
C#
File.SetAttributes(Application.StartupPath, FileAttributes.Normal);

with this code in all hard drive i can do it but in windows drive (drive: C) i can't do it and it says access denied
what should i do to it give me an access to it in drive windows(Drive: C)?
and i want access for folder and file
With Respect
Posted
Comments
BillWoodruff 10-Nov-14 10:07am    
If you are going to delete a file, why do you need to move it ?
Avenger1 10-Nov-14 10:31am    
its for update program
and thanks to all my problem fixed with this code
const int ERROR_CANCELLED = 1223; //The operation was canceled by the user.

ProcessStartInfo info = new ProcessStartInfo(@"your program name or address.exe");
info.UseShellExecute = true;
info.Verb = "runas";
Process.Start(info);

Create a user which will have the access to C drive and impersonate that user in your config file as below.
<identity impersonate="true" username="Username" password="password">
 
Share this answer
 
v2
Comments
Avenger1 10-Nov-14 10:09am    
i know application must run as administrator to it give access but i don't want to do it and i do it in my code how can i do it?
Shweta N Mishra 10-Nov-14 10:14am    
its as good as creating a user on that machine. If you do not have permission to create a user ask your system administrator to create the user and grant it with rights of read and write.
There are 2 ways you can do it.
1) If you start your visual studio in administrator mode it will allow you to create folders and files on windows mounted drive
2) you can add Application Manifest file(app.manifest) file and check the following tag-
<requestedexecutionlevel level="asInvoker" uiaccess="false">
set the "uiAccess=true" so every time your application will executed under admin mode and you will be able to create or operate any files and folders.
 
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