2

Iam working on POS software using winforms. Iam trying to programmatically writing XML file (which contain some encrypted information about software serial number) to C:\Windows\System32 directory. But when i write i get an error Access denied.

Can anyone please explain how can i write this file with full permissions in this directory in windows 7 as well as in windows XP???

Any other suggestion or better way to do this will also be welcome.

Thanks in advance.

user3004110
  • 929
  • 10
  • 24
  • 36
  • 1
    Do you have any good reason for trying to write to `System32`? I can't think of any reason why POS software would need to write to the system directory. – Jonathon Reinhart Mar 16 '14 at 04:01
  • Thanks for reply. Reason to write in system32 has so many files. So it wil l not be possible for user to find this file becoz I want to hide it from all users. Now what u suggest? – user3004110 Mar 16 '14 at 07:07
  • 2
    I suggest that you don't do something foolish like try to "hide" a file in `System32`. Security through obscurity is pointless, and I definitely don't want to have to give admin privileges to random software. Seriously. 99% of applications **do not need** access to system directories. This isn't 1995 anymore. – Jonathon Reinhart Mar 16 '14 at 08:02

1 Answers1

1

You'll need to be an administrator on the machine to write to the Windows directory. In addition, on Vista and later, your process will need to be "elevated" (otherwise known as Run As Administrator). You can configure this on your application's property sheet, as discussed here, or with a bit more work, do it programmatically.

It's bad practice to write to that directory, though, notwithstanding all the (misguided) software that does that. Save your files somewhere else. %appdata% or %localappdata% (directories specifically meant for application data) are good choices.

Community
  • 1
  • 1
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
  • But I want to hide files from other users. In app data or localappdata users can find these files. And other issue is that how can I programatically write files in appdata/localappdata folder because it give access denied error when I write files like programatically writing xml file. – user3004110 Mar 16 '14 at 07:14
  • Oh, I dunno, @user3004110, I'd say most users don't dig into the depths of %appdata% or %localappdata%. As far as *access denied* writing to those directories, you'd have to show us some sample code. I don't have any problem writing there. – Michael Petrotta Mar 19 '14 at 00:54