1

Possible Duplicate:
Allow access permission to write in Program Files of Windows 7

okay, here is my code :

System.IO.File.WriteAllBytes(path1, path2);

however, there is a problem. user(windows 7 users dont have permission to copy file to c: by default)(...i mean for programs...) therefore, program fails. if user gives permission to copy file in c: program works fine. but you cant tell every user " go to permission.........." so how can i make something to allow user that i copy my file to c://

Community
  • 1
  • 1
Foresp
  • 425
  • 1
  • 7
  • 15
  • WriteAllBytes does not takes two paths. – Miguel Angelo May 15 '11 at 18:54
  • Not being able to write to a directory without permission is kind of *the point* of permissions, no? If any program could just circumvent this then the whole concept would be useless... – SirViver May 15 '11 at 18:59
  • miguel, yes it does. i use it to copy a file. path 1 is the path im going to copy and 2 is the path where my file is – Foresp May 15 '11 at 20:11

3 Answers3

6

You may add the Application Manifest File in your project by Selection Add New Item. Update the requestedExecutionLevel to

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

This way user will be asked that the application needs to run in Administrative mode. Hope this help.

FIre Panda
  • 6,537
  • 2
  • 25
  • 38
  • thank you much. this works like charm! however, i have a question. what does uiAccess do ? when i set it to true to see the difference... program fails. not because i dont have permission but because its set to true. why ? what does uiaccess do ? – Foresp May 15 '11 at 20:05
1

Your application shouldn't be writing to the C drive. Only users with permission, or administrators, can grant an application to do that. Instead, try writing to folders that aren't limited by tight security. You can see some of them here.

keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • Windows ??? seriously ? writing to c: isnt allowed but i can change windows files ? – Foresp May 15 '11 at 20:06
  • The permission given to you as a user isn't necessarily the same as the permission given to an application. Imagine you let random applications go wild on your computer and start deleting all your system files. Wouldn't be much fun. Security measures are there to ensure that these things don't happen or that the user is aware that they are granting an application a certain level of access. – keyboardP May 15 '11 at 20:20
0

You can't. You have to give the user permissions.

Jeff LaFay
  • 12,882
  • 13
  • 71
  • 101
  • then how do installers work ? if it wasnt possible, there were no installers. – Foresp May 15 '11 at 20:06
  • The application permissions are based on the permissions of the users currently using it. You can't just overtake permissions in the filesystem without having permissions to do so. That would completely eradicate the purpose of having permissions in the first place. There's no trick for you gaining permissions that aren't given to you. – Jeff LaFay May 16 '11 at 00:21
  • what i asking was how can i make that user to give me permissions. – Foresp May 16 '11 at 04:33
  • You or your installer? If you want the user to give YOU permissions, just ask. If you want the installer to have the correct permissions, it needs to be ran by a user with the permissions applied to their account. – Jeff LaFay May 16 '11 at 12:48