I'm going to copy a file to this path(C:\Windows\Win32) in windows 7 using C# programming(the "Win32" Folder created by me) but I can't.Because the operation system don't allow me.so I need to full access . I write this code for solving the problem , but I see this error in the program running : " Attempted to perform an unauthorized operation." . please help me !!! .thanks
using System.IO;
using System.Security.AccessControl;
using System.Management;
using System.Management.Instrumentation;
1. private void Sample2_Click(object sender, EventArgs e)
2. {
3. System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\Windows\Win32");
4. FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow);
5. DirectorySecurity ds = null;
6. if (!di.Exists)
7. {
8. System.IO.Directory.CreateDirectory(@"C:\Windows\Win32");
9. }
10. ds = di.GetAccessControl();
11. ds.AddAccessRule(fsar);
12. di.SetAccessControl(ds);
13. File.Copy(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg", @"C:\Windows\Win32\Desert.jpg");
14. MessageBox.Show("successfully copy!!!!");
15. }