Recent

Author Topic: Windows 7 - have no permission to own file  (Read 12824 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Windows 7 - have no permission to own file
« on: June 09, 2011, 10:05:30 pm »
Hi,

I'm a linux user from couple years. I'm using windows only sometimes, so I'm not up to date, but I notify that from Vista, windows have some specific permissions for running application (I don't notify that on XP). Now I wrote crosscompile application for windows 7 too and some users tell me that my application can't create config.xml file in own folder (Program Files) without administrator permission. How this is possible that user can run installator which copy files to "Program Files" but executable can't create files in own folder? Is this free pascal compilator behavior or windows configuration?

Regards

Zoran

  • Hero Member
  • *****
  • Posts: 1469
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Windows 7 - have no permission to own file
« Reply #1 on: June 09, 2011, 10:42:38 pm »
I don't know much about new Windows behaviour either, but for config files, instead of the application folder, you should put them in folder which you get from GetAppConfigDir function (your application will probably need to create this directory first). It is also the safe multiplatform way, see: http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Configuration_files
« Last Edit: June 09, 2011, 10:46:57 pm by Zoran »

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: Windows 7 - have no permission to own file
« Reply #2 on: June 09, 2011, 10:56:59 pm »
I remember that new versions of windows have some equivalent of linux "/home/username" in "C:\Users\UserName", but I always thought that it is only optional solution for configuration files. Realy we cannot create files in program files in new windows? So now I have a problem, because I always create portable applications (they create and store data in executable local folder) so users can copy it to pendrive etc. and it works, installator is only tool for beginner users. Now I must detect that my application can run as not portable, I try just check if some files of installer are in local (program files) directory like "uninstall.exe"
« Last Edit: June 09, 2011, 11:01:56 pm by Dibo »

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Windows 7 - have no permission to own file
« Reply #3 on: June 09, 2011, 11:36:00 pm »
In general: with UAC switched on you need admin rights to write something in Program Files. That also is the case for installing programs. If Win lets you write a file without admin rights it will physically end up in the 'VirtualStore' (default path is C:\Users\<user name>\AppData\Local\VirtualStore).

Quote
So now I have a problem, because I always create portable applications (they create and store data in executable local folder) so users can copy it to pendrive etc. and it works, installator is only tool for beginner users.
You could let users install your program in another folder than Program Files for portable use. You would only have to determine the actual config folder once at program start.

Gr.
Dirk.

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: Windows 7 - have no permission to own file
« Reply #4 on: June 10, 2011, 12:12:12 am »
Hm, I think I just do this scenario:
1. If my application have rights to wright in local folder (ExtracFilePath(ParamStr(0)) then I store data in this folder (if user copy exe to another directory like pendrive etc. so i suspect that he know what he doing and he should check permissions first)
2. If my application doesn't have rights then I store in folder returned by GetAppConfigDir

I try to find cross-platform function for check rights on folder but maybe someone remember it and can tell me now?

lainz

  • Guest
Re: Windows 7 - have no permission to own file
« Reply #5 on: June 10, 2011, 12:35:36 am »
I remember that new versions of windows have some equivalent of linux "/home/username" in "C:\Users\UserName", but I always thought that it is only optional solution for configuration files. Realy we cannot create files in program files in new windows? So now I have a problem, because I always create portable applications (they create and store data in executable local folder) so users can copy it to pendrive etc. and it works, installator is only tool for beginner users. Now I must detect that my application can run as not portable, I try just check if some files of installer are in local (program files) directory like "uninstall.exe"

If you want installer you must store the configuration files in AppData. For all users or for each user.

You can't write in ProgramFiles from an application if you don't ask the user administration rights.

You can create a file like 'portable.dat' inside the application to make it portable (like CCleaner does).

I did an installer with InnoSetup that provides an option to select Installer mode or Portable mode:

[Setup]
CreateUninstallRegKey=not IsTaskSelected('portablemode')
Uninstallable=not IsTaskSelected('portablemode')

[Tasks]
Name: installermode; Description: {cm:instalar}; GroupDescription: YourAppNameHere; Flags: exclusive
Name: portablemode; Description: {cm:extraer}; GroupDescription: YourAppNameHere; Flags: exclusive unchecked

[CustomMessages]
english.instalar=Install (Recomended)
english.extraer=Decompress (Portable)

In [Files] add the 'portable.dat' with 'Tasks: portablemode' to copy the file only if the user chose 'Portable'.

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: Windows 7 - have no permission to own file
« Reply #6 on: June 10, 2011, 12:42:43 am »
Interesting, I am using Inno Setup too :D . I am using InnoIDE to save a time and I don't saw this option but I try your configuration. Thanks
« Last Edit: June 10, 2011, 12:45:10 am by Dibo »

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: Windows 7 - have no permission to own file
« Reply #7 on: June 10, 2011, 12:55:01 am »
But I must figure it out how merge this in linux version of my application (I have no .deb package etc. it is only zip). Ehh I always thought that store data in local folder is the best choice. And so I must check if I have permission to local folder

lainz

  • Guest
Re: Windows 7 - have no permission to own file
« Reply #8 on: June 10, 2011, 01:50:06 am »
But I must figure it out how merge this in linux version of my application (I have no .deb package etc. it is only zip). Ehh I always thought that store data in local folder is the best choice. And so I must check if I have permission to local folder

Well if you want you can do a pseudo-"install", that is using..

For all users:

[Setup]
DefaultDirName={commondocs}\{#MyAppName}

commondocs >> C\Users\Public\Documents\YourAppName

Installation per-user:

[Setup]
AppID={{YOUR-GUID-CODE-GOES-HERE}{username}
PrivilegesRequired=lowest
DefaultDirName={userdocs}\{#MyAppName}
UninstallDisplayName={#MyAppVerName} ({username})

AppID includes {username} because in control panel is listed only for this user.
UninstallDisplayName includes ({username}) same reason as AppID.
userdocs >> C:\Users\$USERNAME$\Documents\YourAppName
PrivilegesRequired=lowest >> all shortcuts, registry, etc will be per-user.

___________

In commondocs all users can put files (if permissions aren't changed, the most common setting).

In userdocs only the user that's know the account password can write in the folder (also the applications he run). Also administrators can modify other user folders.
« Last Edit: June 10, 2011, 01:53:08 am by lainz »

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: Windows 7 - have no permission to own file
« Reply #9 on: June 10, 2011, 05:55:20 am »
About your linux version of the application.
you can store files in a hidden folder like:

/home/username/.yourapp/ (with the dot, the folder is hidden)

if you don't want to create deb packages, you can still provide a zip
and create a config file on the same directory the application is.
any file starting with a dot is hidden too.
I.E. on my CpickSniff, i have a .cpicksniff.cfg file on both windows and linux.
« Last Edit: June 10, 2011, 06:02:47 am by FabienWang »
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint