views:

112

answers:

2

Hello SO's

i am trying to create a directory in drive C: (at a win7 target machine) with Directory.CreateDirectory but so far no luck.

I believe the problem has to do something with permissions-security... So here i am..

How can i create a directory in drive C?

+4  A: 

You need to run your application in elevated mode (via UAC). How this can be done is shown in the above StackOverflow thread:

UAC, Vista and C# - Programatically requesting elevation

Before executing the code to switch in elevated mode you should do a check if you application is running on Vista, Windows 7 or above.

Alexander
I would not partition the app as a first choice. It's more work than a simple manifest and if the app always needs to do the elevated thing it is complexity for no reason. Partitioning is probably my third choice.
Kate Gregory
+1  A: 

You should not use the root of C for an ordinary application. If you're just using it because you think it's a folder you can count on, use AppData or Temp instead. If this is not an ordinary application, but is instead an administrative application, then put a manifest on it requesting it elevate (requireAdministrator) so that it can gain access to the areas of the hard drive and registry protected by UAC.

Kate Gregory
For the dummies out there like me, i edited the app.manifest file, from <requestedExecutionLevel level="asInvoker" uiAccess="false" /> to <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />Thanks a ton!
Chocol8