Jump to content


Photo
- - - - -

Windows folders


  • Please log in to reply
29 replies to this topic

#1 Ulf

Ulf

    More Active

  • Members
  • PipPip
  • 28 posts
  • Location:Stockholm, Sweden
  • Version:LabVIEW 2011
  • Since:1996

Posted 26 April 2012 - 08:39 AM

Hi All!
When I build an application(and installation) I normally configure "application builde" to install the program under "\Program files\". I also place the ini-file in the same folder to make sure that correct settings are loaded when the application start. The problem starts if I want to write to the ini-file from the application, then the application have to run in admin-mode(you are not allowed to change anything in \program files if you not are an admin).

The solution to this problem is to move the ini-file/config file to a different folder outside "program files" or use the registry. If I choose to move the file to a different folder, which one do you think I should use? At first I placed the file under "c:\users\user name\documents\application name" but then I realized that there where several other folders that I could use.

What do you think the following folders are for? Should I use one theese folders instead of "c:\usesr\user name\documents"?

c:\ProgramData\ (hidden)
c:\Users\user name\AppData\Local

Best regards
Ulf

#2 Antoine Châlons

Antoine Châlons

    The 500 club

  • Members
  • PipPipPipPipPip
  • 590 posts
  • Version:LabVIEW 2012
  • Since:1999

Posted 26 April 2012 - 08:53 AM

Hi,
We use C:\ProgramData (and in most cases we like the fact that it is hidden) because that's what we get when we call the "Get System Dir" with "Public Application Data". That said, in the case of our application we don't want customers to play around with the config files, if you do want them to have access to it, you may want to place those config files in a folder that is not hidden.

#3 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,050 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 26 April 2012 - 09:22 AM

To expand on Antoine's post besides the hidden or non-hidden location you should consider if settings are user or machine specific. Things like hardware configuration you probably don't want to maintain on a per user base, but other things like applications settings (data formats, paths, etc) your most likely will want to keep separate for each user.

#4 Ulf

Ulf

    More Active

  • Members
  • PipPip
  • 28 posts
  • Location:Stockholm, Sweden
  • Version:LabVIEW 2011
  • Since:1996

Posted 26 April 2012 - 12:06 PM

Hi,
We use C:\ProgramData (and in most cases we like the fact that it is hidden) because that's what we get when we call the "Get System Dir" with "Public Application Data". That said, in the case of our application we don't want customers to play around with the config files, if you do want them to have access to it, you may want to place those config files in a folder that is not hidden.


Thank you! Do you known if the installation program "uninstall" stuff in the ProgramData? I guess it quite easy to test...

//Ulf

#5 Antoine Châlons

Antoine Châlons

    The 500 club

  • Members
  • PipPipPipPipPip
  • 590 posts
  • Version:LabVIEW 2012
  • Since:1999

Posted 26 April 2012 - 12:17 PM

It does, in fact I thinkit uninstalls everything that is installed directly by the install.

#6 ShaunR

ShaunR

    LabVIEW Archetype

  • Members
  • PipPipPipPipPipPip
  • 2,272 posts
  • Version:LabVIEW 2009
  • Since:1994

Posted 26 April 2012 - 12:39 PM

There is a VI in the "\vi.lib\utilities\lvdir.llb" called "Get Base Labview Directory.vi".

With it you can get the common/user locations that labview uses (like "C:\Users\<user_name>\Documents\LabVIEW Data"
A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!

#7 Jon Kokott

Jon Kokott

    Very Active

  • Members
  • PipPipPip
  • 176 posts
  • Location:Milwaukee, WI
  • Version:LabVIEW 2010
  • Since:2006

Posted 26 April 2012 - 12:52 PM

In Windows XP:

We use "C:/Documents and Settings/All Users/Application Data/<Application Name>"

Supposedly that is guaranteed to give access to everyone.

I'm on my home computer right now and the Program Data folder folder looks promising, I always like a shorter path. Should probably check the official Microsoft recommended stance on this, I know it changed from XP to Vista/7.
Certified LabVIEW Architect

#8 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 26 April 2012 - 01:07 PM

I thought I had read somewhere that I/O to the protected Program Files folder was supposed to failover automatically to a mirror ProgramData directory. Anyone know what I'm talking about?

#9 Jon Kokott

Jon Kokott

    Very Active

  • Members
  • PipPipPip
  • 176 posts
  • Location:Milwaukee, WI
  • Version:LabVIEW 2010
  • Since:2006

Posted 26 April 2012 - 02:05 PM

OK this is a little more definitive.

C:/Documents and Settings/All Users/Application Data/ = C:\ProgramData or C:Users\username\AppData\Roaming folder. I'm getting conflicting forum guidance on that detail.


There is an NTFS Junction point linking those two folders. Win 7 supports symbolic links, so there must be a performance/usability advantage to using a junction instead (or maybe its just more proprietaryier <-lol.)
at any rate, the username can create restrictions between users, use the "All Users" folder and it will be safer.



Certified LabVIEW Architect

#10 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,748 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 26 April 2012 - 05:29 PM

I prefer to use the registry. We have reuse VIs that read application ini files in their application folder, then when MS really started locking down Program Files, we made drop-in replacements that work with the application's entry in the registry. Plus, that gives us a much easier way to overwrite or add keys outside fo the application's installer (eg: say an installed instance includes a couple of our products + a custom OI: we can install the standard stuff and keep it encapsulated as products, then overwrite any important custom stuff with the custom OI's installer) - works great iff you install stuff in order (there's something not quite right about LabVIEW's installer when it comes to registry keys).

post-181-1170858537.png


#11 JamesMc86

JamesMc86

    Very Active

  • NI
  • 208 posts
  • Location:UK
  • Version:LabVIEW 2012
  • Since:2006

Posted 26 April 2012 - 09:16 PM

I would beware of ProgramData. It can cause upgrade issues going to Win7 due to access restrictions, seen this catch a few people out.

(null)

James McNally

AE Specialist, NI UK & Ireland & CLA


#12 Antoine Châlons

Antoine Châlons

    The 500 club

  • Members
  • PipPipPipPipPip
  • 590 posts
  • Version:LabVIEW 2012
  • Since:1999

Posted 27 April 2012 - 05:48 AM

Hi James,
Can you tell us a bit more about issues with ProgramData?
This is were my installers place the config files for which it needs read/write access. If there are specific issues, I'd like to know :-o

Reminder

#13 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,050 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 27 April 2012 - 06:39 AM

I would beware of ProgramData. It can cause upgrade issues going to Win7 due to access restrictions, seen this catch a few people out.

(null)


I want to know that too. I'm using Windows 7 Professional here in 32 Bit and 64 Bit on another machine and ProgramData/<Company Name> seemed to work quite well so far. Or where they trying to access it with hardwired names, instead of requesting the location from the OS? Or is it restricted for Guest accounts or similar?

#14 Ulf

Ulf

    More Active

  • Members
  • PipPip
  • 28 posts
  • Location:Stockholm, Sweden
  • Version:LabVIEW 2011
  • Since:1996

Posted 27 April 2012 - 06:51 AM

Hi James,
Can you tell us a bit more about issues with ProgramData?
This is were my installers place the config files for which it needs read/write access. If there are specific issues, I'd like to know :-o

Reminder

Thank you for the Reminder link. I missed that one

#15 JamesMc86

JamesMc86

    Very Active

  • NI
  • 208 posts
  • Location:UK
  • Version:LabVIEW 2012
  • Since:2006

Posted 27 April 2012 - 08:50 AM

For standard accounts you only have read access to ProgramData, not read/write so if the application is to be run by someone it would have to be elevated to admin before being able to write. Rolfk: I wonder whether you have always had admin priveledges or I believe if you have just one user there is some kicker in Win7 which gives the user that creates the folder R/W permissions (I am not sure about this, someone may be able to elaborate better).

The recommendation from Microsoft is that your installer should set permissions for your folder entry in here if you need it. This is not straightforward from LabVIEW but I believe it can be done with a batch file. Another option is that you can sit a mainfest file with your exe which tells Windows that your application must always run elevated (but I suspect this is not recommended practice!). This appears to have caused confusion and problems for programmers across all languages!

Mads link in the reminder is pretty good and will have to keep it on stock. Here it is again and reading the comments you can see the frustration this can cause! http://blogs.msdn.co...ndex=2#comments. Primarily because you will have no such issues with the equivalent in XP.

James McNally

AE Specialist, NI UK & Ireland & CLA


#16 Antoine Châlons

Antoine Châlons

    The 500 club

  • Members
  • PipPipPipPipPip
  • 590 posts
  • Version:LabVIEW 2012
  • Since:1999

Posted 27 April 2012 - 09:57 AM

This blog post does give some good info, but it doesn't clearly tell us about if an App (or a user) would need to be ran as admin to have write access on the files.

#17 JamesMc86

JamesMc86

    Very Active

  • NI
  • 208 posts
  • Location:UK
  • Version:LabVIEW 2012
  • Since:2006

Posted 27 April 2012 - 10:01 AM

Very true, the short answer is if you are not doing something about it, yes you will need to run as admin to have write access in this folder.

James McNally

AE Specialist, NI UK & Ireland & CLA


#18 hooovahh

hooovahh

    The 500 club

  • Members
  • PipPipPipPipPip
  • 809 posts
  • Version:LabVIEW 2011
  • Since:2004

Posted 27 April 2012 - 04:08 PM

Just a thought (and probably not a good one) but what if you install to program files like always, and have the ini file in program files along side the EXE, but then during the install run function that will set the privileges of the INI to be written by any level user?

The EXE doesn't need to have elevated privlages, the file can just have lower ones. I know there is a Windows command line function to set file permissions but I can't seem to find it at the moment. One downside is the file isn't as hidden as other places, but it also feels like a patch when it sounds like the proper way would be to store the data in ProgramData.

"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin

"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd


#19 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,050 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 27 April 2012 - 04:23 PM

For standard accounts you only have read access to ProgramData, not read/write so if the application is to be run by someone it would have to be elevated to admin before being able to write. Rolfk: I wonder whether you have always had admin priveledges or I believe if you have just one user there is some kicker in Win7 which gives the user that creates the folder R/W permissions (I am not sure about this, someone may be able to elaborate better).

The recommendation from Microsoft is that your installer should set permissions for your folder entry in here if you need it. This is not straightforward from LabVIEW but I believe it can be done with a batch file. Another option is that you can sit a mainfest file with your exe which tells Windows that your application must always run elevated (but I suspect this is not recommended practice!). This appears to have caused confusion and problems for programmers across all languages!

Mads link in the reminder is pretty good and will have to keep it on stock. Here it is again and reading the comments you can see the frustration this can cause! http://blogs.msdn.co...ndex=2#comments. Primarily because you will have no such issues with the equivalent in XP.


Ok on my own machine I usually run with an account that is part of the admin group and the other computer is a standalone system with only one local user with local admin rights.

But reading through it, it all makes sense. Since Vista, MS has tightened security according to the principle that a user should only have access to resources that do not influence other users on a system. This includes the entire registry except the user specific hive, the filesystem including all setting directories that are used by all users. So ProgramData logically belongs to that. I just added a small piece of code that checks in the configuration dialog the write rights for the configuration file, and if that is not there of the directory and only enables the Save button if this is true. A dialog informs the user that the application needs to be started as admin in order to be able to make changes to the relevant configuration items.

Just a thought (and probably not a good one) but what if you install to program files like always, and have the ini file in program files along side the EXE, but then during the install run function that will set the privileges of the INI to be written by any level user?

The EXE doesn't need to have elevated privlages, the file can just have lower ones. I know there is a Windows command line function to set file permissions but I can't seem to find it at the moment. One downside is the file isn't as hidden as other places, but it also feels like a patch when it sounds like the proper way would be to store the data in ProgramData.


Since Vista you have to differentiate between elevated rights and a user account that has admin rights. The difference is that in order to be elevated one has to start the process explicitedly as admin with an extra password login dialog, even if the current user is already part of the admin group.

Your solution has one possible drawback. Only changing the rights of the config file alone is likely not enough as the directory needs to have its rights also changed. And that allows access to the directory to add more files to anybody, although it should be not possible to change existing files that don't have write rights for normal users.

#20 hooovahh

hooovahh

    The 500 club

  • Members
  • PipPipPipPipPip
  • 809 posts
  • Version:LabVIEW 2011
  • Since:2004

Posted 30 April 2012 - 09:39 PM

Your solution has one possible drawback. Only changing the rights of the config file alone is likely not enough as the directory needs to have its rights also changed.

This is not the case at all. I can't seem to find the stupid batch file I created, but it would run an installer (with some silent switches) then run the command line program Icacls (built into Windows 7) to allow the INI file that got installed to be written by anyone in the Users local group. This batch file of course would need to be ran by someone with elevated privileges the first time. But then again only someone with those privileges should be installing updates anyway.

Then the application (stored in the Program Files) could modify the INI file that was in the same folder as the EXE, even when the logged in user only had limited rights. This also only modifies the security of the INI file, the directory it self still cannot be modified by someone in the Users group.

"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin

"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd