0

I make an application and make setup file using VS setup project. This work fine and create default text files into Program Files Folder for winodw 7/vista .but can not modify these files or create any new files.

There are few text files need to create ,modify during application running ,but in windows 7/vista unable to create,modify files.I am using full default admin right for these OS. If iuse C: root path then application work fine or for win XP no problem.

I think UAC restricting to perform these opeartion. But i do not know how to change these restriction using vb.net, whenever application start.

I found one solution that , if change user rights manually then this problem solved. Follow these step to change your account settings. Control Panel-->User Accounts and Family Safety-->User Accounts-->Change User Account Control settings-->Never notify(Set tab to never notify). After this change need to restart system. Now can make all changes like windows XP into Windows 7.can also make changes into program files.

Its working fine, but need to make these changes manually in OS.

but its not efficent solution.

So if any one knows how can make these changes by coding that will nice.

  • possible duplicate of [Does Windows 7 have the same problem as Vista?](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista) – Cody Gray - on strike Jul 27 '11 at 08:52
  • 2
    **Do not make these changes in code!** You need to *comply* with UAC, not work against it. **No Windows application should assume it has write privileges to the Program Files directory. EVER.** – Cody Gray - on strike Jul 27 '11 at 08:52
  • yes vista also have the same problem – muhammad hanif Jul 28 '11 at 01:21
  • Yes, but it's not a "problem". It's a solution. Use the Application Data directory designed for this purpose. Apps can't write to system or program directories. Period. Not sure where the question here is other than "I don't like that". Tough. Users didn't like you monkeying around with system files, either. – Cody Gray - on strike Jul 28 '11 at 01:28

1 Answers1

2

I seriously doubt whether you can create and delete files under Program Files Folder through code in windows7/vista. Even if there is a way, I would consider doing this a bad design and a security flaw.

If you want to create/modify/delete files during you app execution. you can create them "C:\Users\\AppData\Local\\ and do whatever you want to do over there.

Program Files Folder is not the place for storing temporary data.

Deepansh Gupta
  • 593
  • 4
  • 9
  • gupta thanks for your answer.Yeh its not good place to copy,modify files. prg file is the folder hold installed applications also.So my app folder reside in prg files and there are few files need to keep there and make changes into those files. – muhammad hanif Jul 27 '11 at 08:29
  • @muhammadhanif: Irrelevant what kind of data it is. You do not have write privileges to the application directory. That's completely by design. Use the AppData folder, as suggested. More info [here](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista/5210642#5210642). – Cody Gray - on strike Jul 27 '11 at 08:53
  • 1
    @muhammad hanif, one of Microsoft's biggest hurdles over the decades is the problem of developers writing files all over the system. In the older days people would write directly to the root of the hard drive or the windows/system folders causing bloat and conflicting files, especially when everyone just names their file "config.ini". So Microsoft finally took a stance and said "Programs" go into "Program Files" and program data goes into "AppData". You may think you have an exception to the rule, but then again so did everyone 20 years ago. – Chris Haas Jul 27 '11 at 13:14
  • Right. The "exceptions" are why the rule was created. Like most rules operating systems now impose on developers. Back in the "olden days", the OS could actually trust application software to be responsible and do the right thing. Those days are *long* gone, as evidenced by the flood of such questions on SO and the refusal of people to accept the good advice that has been provided to them. – Cody Gray - on strike Jul 28 '11 at 01:26
  • I agree with Chris and Cody that as application developers, we need to be responsible in terms of what parts of OS are being touched by our code. – Deepansh Gupta Jul 28 '11 at 10:22