When using CFPreferences to set preferences on osx, there are different
Preference Domains.
By reading the apple development guide, I understand that for current-user, current-application, current-host preference, it will be stored in ~/Library/Preferences/< application bundle name >.plist. And for any-user, current-application, current-host preference, it will be stored in /Library/Preferences/< application bundle name >.plist.
But where to store preferences for other domain combinations? For example current-user, current-application, any-host? Will the preferences be propagated during set time (CFPreferencesSetAppValue follow by synchronize) to ~/Library/Preferences/< application bundle name >.plist on all hosts that are connected to the local network and logged in as the current user? Or the magic is done during read when all hosts are consulted (but how to handle conflict preferences from different hosts in that case)?
Same question for the any-application domain, where will the preference get stored for domain such as current-user, any-application, current-host?
The "default" for preferences is current-user, current-application, any-host. Using the bundle name com.example for an example, these preferences would be stored at
~/Library/Preferences/com.example.plist
What makes this "any-host" is the assumption that your home directory is stored on a network share. There is no additional mechanism to synchronize it across computers. Generally speaking, you should always use any-host unless you are setting a value which really does need to be specific to the physical machine the user is sitting at.
Preferences which are set for the current host are stored under the ByHost directory, with a file name that includes a UUID for the computer, such as:
~/Library/Preferences/ByHost/com.example.74263C97-28D5-4AF0-8E7A-3169F1CCB545.plist
Preferences which are set for all applications are stored under the bundle name .GlobalPreferences, e.g:
~/Library/Preferences/.GlobalPreferences.plist
and similarly for all applications, current-host:
~/Library/Preferences/ByHost/.GlobalPreferences.74263C97-28D5-4AF0-8E7A-3169F1CCB545.plist
Preferences which are set for all users follow the same pattern, except under /Library/Preferences.
Related
I'm working on a System Service project with SYSTEM privilege (cleaning utility)... It does not interactive with any user interface.
My goal is to check files in "Desktop" and "AppData" folders for any user that exists on the PC.
I'm using NetUserEnum() to get the user list on the PC. Then I want to get the path of each user's Desktop and AppData with SHGetKnownFolderPath(), but I can't find a way to get each user's access token for SHGetKnownFolderPath(). Without a token defined in SHGetKnownFolderPath(), it returns the path for SYSTEM and not specific users.
Q1. How can I get the token of each user for SHGetKnownFolderPath()?
Q2. If no answer for Q1, is there any documented way to get the desktop & appdata path of each user in the PC?
I understand this can be achieved with dirty way ---> Registry key with some string replacement. However, the Registry key method is undocumented, which may easily break in future updates to Windows.
Edit Update:
#RaymondChen Thanks for pointing out that some user profiles may not exist. Also,
About Q1 : #Remy Lebeau provides a solution with LogonUser/Ex(),login to each user with their credentials,might be the only answer that fits the need of Q1.
About Q2 : There might have no documented way to achieve this. The only method might have to stick with Windows Registry (Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders) , as #Remy Lebeau and #Olaf Hess said. I tried to dig more information on Microsoft Community Forum and I got Microsoft would never allow access other users' profile with their native API for security reason. They do not provide APIs that can possibly violate the security rules. Each user profile can only access by its credentials.
btw, I totally understand that "Cleaning utility" aka "Windows-breaking tool", especially when the tool is not being well codded(ex. compatibility problem). For the sake of avoiding to make it become a totally Windows-Destroyer, I tried to use more documented API as possible.
For Windows Vista with SP1 / Server 2008 and better you can query the existing user profiles using the WMI class Win32_UserProfile. This allows you to retrieve the profile path and check whether it is a local or roaming profile and to get status information. The rest (retrieving the paths to APPDATA, DESKTOP, etc.) is likely going to involve reading values straight from the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders or HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders).
All,
I have no idea how Windows service works, just curious when we register a windows service(such as auto run a server after reboot), if it requires a user profile to load info(such as pulling data from somewhere else), what user profile does it load?
Thanks,
You can select what user run each service registered and the system comes with users assigned per service. The most used by the system is SYSTEM.
To check this you have to:
Go to services.
Right click on the desired service and properties.
Go to the Log on tab and check.
If the Local System account is selected the username is SYSTEM which has special permissions on almost all folder and Windows sections including users' profiles data.
By the other hand if you would like to do something special with an specific account you can tell the system the service will start with the account specified. Just make sure to update the password information every time the user change it.
Regards,
Luis
I am trying to create a liberty cluster. While generating the keys, liberty is creating some keys under logged-in user's home directory which is c:\users\xyz\ .ssh.
How do I say liberty to save the keys under d:\users\xyz\ .ssh?
I need this because, i am working in citrix environment and c drive image is always replaced upon restart and I am loosing the keys forcing me to create the cluster again or save a copy of the keys before I log out for day.
Did you try displaying options for registerHost action like this:
D:\Liberty\wlp\bin>collective.bat help registerHost
it shows rpcUserHome param, which might be what you are looking for:
--rpcUserHome=path
Optional. The home directory for the user with which to authenticate
to the RPC mechanism. Defaults to the current OS user home directory.
This value is used when generating SSH keys.
I'm using Apache 2 to run my localhost on Mac (Mavericks), and every time I add a file or a folder in the default directory /Library/WebServer/Documents (and its subdirectories) the system asks me to authenticate:
This is a problem specially when using frameworks like Symfony or Zend Framework because they can't have writing access to folders. What can I do to solve this?
Mac/Linux grants access on different levels:
Per user
Per group
Per everybody
The folder Library/WebServer/Documents outside of the logged-in user paradigm (you) therefore write access (and other access like execute) is only granted to the administrator of the computer (or so-called root) which isn't you however on most Mac environment the password of root is your password (different users with the same password).
You will want to modify Apache2 configuration and change the directory to a folder located within your user's directory which is something like /Users/{whatever is your username} (you will probably need to create the folder).
Once, you moved the content of /Library/WebServer/Documents into the new folder, make sure the permission are set properly. Refer to the following documentation at the chapter "How to Modify Permissions with the Info Window".
The reason why your Mac is asking for permissions to write files outside of your user's directory is for security reasons. Imagine if you download a file, execute it and grant access (by giving the root password) then the file could potentially be a virus and erase or do all kind of things on your computer.
When I run my Eclipse RCP application, it creates a whole lot of directories in my $HOME/.eclipse directory. What is this?
I don't want the files there, how can I hinder them from getting there? The rational for this: the application must run very clean and only leave files at one specific location (not $HOME/.eclipse).
I'd figured it was controlled by osgi.instance.area so tried to set this to different values (a directory, #none, #noDfault etc...) but can't stop the application from creating directories in $HOME/.eclipse. -data and other arguments works as expected.
On my system the only thing that is stored in .eclipse is the Equinox Secure Storage. Here is the blurb on the doc page for that:
By default, secure storage is located in your home directory. On Windows that typically resolves to "C:\Documents and Settings\.eclipse\org.eclipse.equinox.security". This location is selected to allow multiple Eclipse-based applications to share the same secure storage.
If you would like to modify the location of the default secure storage, you can use the "-eclipse.keyring " runtime option. The is a path to the file which is used to persist the secure storage data.
Here is the online reference.