acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges?
acces to file requires priviledges? acces to file requires priviledges?
acces to file requires priviledges?
Go Back  Xtreme Visual Basic Talk > > > acces to file requires priviledges?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2010, 09:10 AM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default acces to file requires priviledges?


I upgraded to 64bit.

I installed my app.

My app needs to delete and rewrite a text file called events.txt

now it used to work but now when i run the app it shows an error due not being to access the file in the "Program FIles (x86)/MyApp/" folder?

If I run the app as administrator it works fines!

So how do i give the app permission to write to that file without needing to run as admin?
__________________
Hey, Looking for entry level job in VB net programming. Got basic qualification, years of programming experience (mainly self taught) and good portfolio. (UK)
Reply With Quote
  #2  
Old 11-23-2010, 10:30 AM
AtmaWeapon's Avatar
AtmaWeaponacces to file requires priviledges? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You don't.

You probably also left out a detail when you said "I upgraded to 64-bit." My guess is you mean "I upgraded from Windows XP 32-bit to Windows Vista/7 64-bit."

Since at the latest Windows 2000, Microsoft has provided special directories for application data most people call AppData for short. Since Windows 2000, Microsoft has been telling developers they should not store data files in the Program Files directory. When Vista released, they made this problem more likely to affect people because by default administrative privileges are required to write to files in the program files directories.

Why? Since Windows had the capability to prevent access to certain directories, administrators have usually restricted access to the program files directory. This is an easy way to make sure employees have a more difficult time installing unapproved applications without running them through IT. However, many applications wrote to this directory due to habits formed in the days of DOS when the executable's directory was one of the few you could assume existed. These programs didn't work well if program files was locked down, so many administrators couldn't lock it down. So Microsoft introduced the AppData directory; this solves the problem by creating a specific place where programs should write there data and a guarantee that it will always exist. Microsoft also created an API to get the appropriate directory; they have changed its location a few times and it'd be annoying to have to hard-code them.

The guidelines for writing to this folder are to use a speccific directory scheme, but I don't think you have to follow them to the letter. To be thorough, they want you to use "company name\product name\version" as the directory. So if your company is "3dkingpinsoft" and your software is "awesome program" and it's version 3.0, the full directory would be "AppData\3dkingpinsoft\awesome program\3.0". For my programs, I tend to not use the company name or version, but there are some reasons you might want to separate files by version.

So where is it? I'm not going to tell you because you shouldn't hard-code it. You use the System.Environment class's GetFolderPath() method to retrieve the one you want. Here's the three values for SpecialFolder you should use and an explanation of what they get you:
  • CommonApplicationData points to a directory that is shared for all users. If your program has large data files that don't need to be unique for every user, use this directory as your base.
  • LocalApplicationData is data that will not move to new machines if the user is on a domain. If your application has very large user-specific files, you may want to use this.
  • ApplicationData is data that will "roam" with the user on a domain; when they log into a new computer the domain's policies might cause their roaming data to be downloaded to that machine. You usually put smaller files like user settings files here, but smaller user-specific data files might be a good idea too. Note you don't want to put very large files here because if their profile is downloaded to a new machine it might take a long time.
Use one or all of those three directories for your program's data and you'll be caught up with best practices from last decade while shedding the superstition of practices that made sense 30 years ago.

ALTERNATIVELY, you can take some poor workarounds:
  • You can change your application manifest to require that your application always runs with administrator priveleges. This will be a UAC prompt for your users and personally I don't use applications that require this unless it makes sense. (For example, I don't mind if Disk Defragmenter wants admin privileges but I would never let Firefox have them.)
  • You can ask your users to turn off UAC completely. This is like driving without a seatbelt and I feel like the polite term for it is "stupid". Again, if I bought a program that asked me to turn off UAC I'd ask for a refund.
  • You can ask your users to right-click the program and use the properties page to configure the application's compatibility settings. This doesn't actually let it write to Program Files but instead creates a directory somewhere else that is written to when the program tries to do so. You cannot automate installation of a program with compatibility settings; your users have to do it manually. Note that this is akin to trying to sell a used car while pointing out the engine doesn't leak oil so long as someone holds a plug in with their finger: it looks unprofessional.
I think it's easier to just change the spots where you write the files. If your code is structured well it should be less than 10 lines. If it involves digging through the code for a few dozen hard-coded paths, then you're learning a valuable lesson about why you shouldn't do that!
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 11-23-2010, 01:37 PM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default

ok thanks. I will do that.

But, is there a way to create app dir in roaming folder unique to each app location.

E.g if i run from debug it will not use the same folder used by the installed version

So im looking for way to uniquely identify a program depending on where its run from, like maybe a number identifier?
__________________
Hey, Looking for entry level job in VB net programming. Got basic qualification, years of programming experience (mainly self taught) and good portfolio. (UK)

Last edited by 3dkingpin; 11-23-2010 at 03:13 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges? acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges? acces to file requires priviledges?
acces to file requires priviledges?
acces to file requires priviledges?
 
acces to file requires priviledges?
acces to file requires priviledges?
 
-->