1

If I am not an Administrator and start a program which writes to C:\ some textfile - will I need admin rights...in Windows 7 or Vista? I see in XP there are no problems to write to any folder including system32 - but I am not sure if a program in say .NET will be able to do that without admin permissions.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
johny
  • 119
  • 2
  • 4
  • 3
    use the temp directory; that's what it's for – David Heffernan Mar 05 '11 at 23:24
  • 1
    This seems like a strange question. What cause could you ever have for writing to the root directory of the disk? Yes, this was a serious security flaw in Windows XP. They finally fixed this. If your application breaks, you have only yourself to blame. You weren't supposed to write to these directories under previous versions of Windows, either. Follow Erik and/or David's excellent suggestions, and don't ever worry about this again. UAC protects you from yourself as much as it does the end user. – Cody Gray - on strike Mar 06 '11 at 07:57

3 Answers3

6

That depends on whether C:\ is a filesystem that supports permissions, and if so on the permissions set on the root directory, which can be modified by users with the correct privileges. Use GetTempPath() for temporary files, or SHGetFolderPath passing e.g. CSIDL_APPDATA

Erik
  • 88,732
  • 13
  • 198
  • 189
  • 2
    Following your own logic, even writing to AppData could fail should someone poke with its security settings accordingly. – Sertac Akyuz Mar 06 '11 at 01:05
  • 2
    Yes. This is however a lot more unlikely as it'd break very many applications that actually follow the guidelines on where to store stuff. Storing in C:\ is just wrong, and that's e.g. often reflected in a domain setup – Erik Mar 06 '11 at 01:08
2

No, you can't write to the root of disk even in Windows XP if you are not an administrator. It's just everyone works as administrator in XP; and this assumption is actually wrong.

Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68
-1

Yes. You won't be able to write to C:\Program Files\ or C:\Windows\, but just the root drive C:\ is fine.

Peter C
  • 6,219
  • 1
  • 25
  • 37
  • 4
    That's incorrect. It depends on permissions, that may differ from system to system. – Erik Mar 05 '11 at 20:54
  • 1
    @Erik: Well, I'm assuming he's using default permissions, given that he didn't specify otherwise. – Peter C Mar 05 '11 at 22:51
  • The default permissions on my Win7 system is to allow only creating _folders_ in C:\; you can't create _files_ in C:\ when non-elevated. – Alexey Ivanov Apr 08 '11 at 12:19