Page 1 of 1

XnView et "User Account Control Data Redirection"

Posted: Fri Sep 24, 2010 10:33 pm
by fplanglois
Bonjour Pierre,

J'ai rencontré un problème curieux, soudainement j'ai perdu toutes mes catégories.

J'ai dans un premier temps recréé mes catégories (je les reconstitue rapidement à partir de recherches dans les mots Clefs IPTC, peut-être l'occasion de formuler le voeu de catégories dynamiques dans XnView, mais ce n'est pas le sujet aujourd'hui).

Puis je me suis posé la question de ce qui était arrivé.

En fouillant j'ai retrouvé la base category.db dans deux répertoires :
%userprofile%\AppData\Local\VirtualStore\XnView
et
%userprofile%\AppData\Roaming\XnView

L'ancienne base, celle qui avait bien toutes mes anciennes catégories, se trouvait dans le deuxième répertoire (Roaming) alors que la nouvelle que je venais de constituer se trouve dans le premier répertoire (VirtualStore).

Entre temps, vous devez avoir déjà compris, j'avais changé le réglage de l'UAC.

J'ai alors fouillé sur le net et trouvé cet article qui fait bien le point :
http://windowsteamblog.com/windows/b/de ... ction.aspx
(il s'agit des normes de programmation pour rendre pleinement compatible une application avec Windows Seven)

On est typiquement dans le cas de figure évoqué dans l'article :
•After turning User Account Control (UAC) on or off, your application is unable to find files in the Program Files or Windows directories
J'ai poursuivi mes tests et je confirme bien, que selon le réglage de l'UAC, XnView va lire et écrire la base category.db dans
1- %userprofile%\AppData\Roaming\XnView si le niveau de l'UAC est à 0 (curseur en bas).
2- %userprofile%\AppData\Local\VirtualStore\XnView si le niveau de l'UAC est sur le niveau 3 (valeur par défaut de Windows).


Une correction pourra-t-elle être envisagé, afin de n'avoir pas à chercher partout ses fichiers de configuration à chaque réglage de l'UAC.

Le problème s'est posé ici sous Windows Seven.

Re: XnView et "User Account Control Data Redirection"

Posted: Mon Sep 27, 2010 1:39 pm
by xnview
fplanglois wrote: Une correction pourra-t-elle être envisagé, afin de n'avoir pas à chercher partout ses fichiers de configuration à chaque réglage de l'UAC.
Le probleme c'est que Windows renvoie un chemin différent pour sauver les fichiers de config suivant l'UAC..

Re: XnView et "User Account Control Data Redirection"

Posted: Mon Sep 27, 2010 3:33 pm
by fplanglois
Bonjour,
xnview wrote:Le probleme c'est que Windows renvoie un chemin différent pour sauver les fichiers de config suivant l'UAC..
Oui si on utilise %userprofile%\AppData

L'article que j'ai mis en lien donne toutes les pistes pour rendre 100% compatible une application avec Seven.

On voit bien ici qu'on se trouve rapidement à sur une situation bloquée : pertes des paramètres et des catégories.
Solution

Virtualization is intended only to assist in application compatibility with existing programs. New applications designed for Microsoft Windows 7 should NOT perform write operations to sensitive system areas, nor should they rely on virtualization to provide redress for incorrect application behavior. Always develop applications for use with standard user privileges and don’t count on the application running under administrator privileges. Test your application with standard user privileges and not administrator privileges.

If you are experiencing UAC virtualization with applications developed prior to Windows 7, re-design your applications to write files to the appropriate locations. When updating existing code to run on Windows 7, you should:

•Ensure that during run-time, applications store data only in per-user locations or in computer locations within %alluserprofile% that have properly set access control list (ACL) settings. For more information about ACLs, see Access Control Lists.
•Determine the known folder to which you want to write the data files. Generic data used by all users should be written to a global public location that is shared by all users. All other data should be written to a per-user location.
◦Generic data files can include, but are not limited to log files, settings files (INI/XML), saved state applications such as saved games, and so on
◦User documents are different; they should be saved to the Documents folder (or to a location the user specifies)
•Ensure that you do not hard-code paths once you have determined the appropriate locations. Instead, use one of the following programming models and APIs to retrieve the correct paths of specific Windows known folders:
◦C/C++ native applications: Use the SHGetKnownFolderPath function that retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID, a GUID parameter indicating the known location you would like to obtain:
■FOLDERID_ProgramData – Shared program data directory for all users
■FOLDERID_LocalAppData – Per-user program data directory (non-roaming)
■FOLDERID_RoamingAppData – Per-user program data directory (roaming)
◦Managed Code: Use the System.Environment.GetFolderPath function. GetFolderPath takes a parameter indicating the Known Location you would like to obtain
■Environment.SpecialFolder.CommonApplicationData – Shared program data directory for all users
■Environment.SpecialFolder.LocalApplicationData – Per-user program data directory (non-roaming)
■Environment.SpecialFolder.ApplicationData – Per-user program data directory (roaming)
◦If none of the above-mentioned options are available, use the environment variable:
■%ALLUSERSPROFILE% – Shared program data directory for all users
■%LOCALAPPDATA% – Per-user program data directory (non-roaming) - Windows Vista or later
■%APPDATA% – Per-user program data directory (roaming) - Windows Vista or later
Steps to Determine the Most Appropriate Solution

So far, we have presented the symptoms associated with UAC virtualization, explained why redirection is taking place, and suggested a solution. This section contains tests and procedures you should perform in order to pinpoint the real problem and plot a way to resolve it.

Test #1:

•Launch the application with standard user privileges
•Run through the scenario that results in a write operation to any given protected folder such as the Program Files or system root (C:\) directories
•Expected results: The application “succeeds” in writing the file to the protected folder; however, you can't find the file in the expected location
•Conclusion: This suggests that UAC data virtualization is redirecting the file to a different location
Test #2:

•Using Windows Explorer, search for your files in the VirtualStore folder
◦The VirtualStore folder is a folder in your profile which stores redirected files
◦The VirtualStore folder’s name and location are subject to change in later versions of Windows
•First, attempt to find it under %localappdata%\VirtualStore
•If you are unable to find it there, try issuing dir %userprofile%\yourfile.dat /s /a at a command line (usually found C:\Users\<user name>\AppData\Local\VirtualStore)
•Expected results: You should find your file at the virtual store folder or sub folders
•Conclusion: This is proof that UAC virtualization is taking place
Test #3

•Log in as an administrator and launch your application with administrator privileges.
◦To launch the application with administrator privileges, right-click the file executable and select Run as Administrator
◦When an application runs with administrator privileges, virtualization is turned off, and the application now has sufficient privileges to write to the protected folders
•Do not rely on permanently marking your application to require administrator privileges as a way to bypass virtualization, as doing so will leave the system more vulnerable to attack, will prevent the application from running with limited or standard user privileges, and will needlessly annoy users with a UAC prompt
•Expected results: The application succeeds in writing the file to the protected folder, and you can find the file at the expected location
•Conclusion: Running the application with administrator privileges turns off virtualization and grants privileges
Test #4

•Launch Process Monitor (ProcMon)
◦To learn more about Process Monitor, visit the Windows Sysinternals Process Monitor Web site on Microsoft TechNet
◦During the hands-on lab, we will walk you through a detailed step-by-step process to use Process Monitor
•Configure filtering to show only file operations and only those operations performed by your process
◦When you launch Process Monitor, the Process Monitor Filter dialog box appears

•Add the following entry to the filter: "Column=Process Name, Relation=is, Value=YourApp.exe, Action=Include"
•To invoke the Process Monitor Filter dialog box again, click this toolbar button
•After clicking OK, configure Process Monitor to log only file events by enabling the following toolbar buttons as shown:
•Press CTRL-X to clear the log; press CTRL-E to toggle logging on/off
•Expected results: You will see file operations whose results are REPARSE; the next line (with result SUCCESS) will usually be the redirected operation:

•Double-click the line representing the operation with REPARSE as the result and click the Stack tab to show the call stack at the time of the operation:

•The pink K and blue U letters on the left of each stack frame show whether the stack frame is in kernel mode (K) or in user mode (U);in this case, we are interested only in user-mode stack frames
•In this example, the SaveFile function (at frame 21) in BrokenAppNative.exe is the one performing the operation which will be redirected
•You should configure symbols for a more meaningful display' for more information about configuring symbols, refer to the Debugging Tools for Windows Web site
•Conclusion: This test proves that UAC Virtualization did take place and shows you what operations in your application need to be corrected
Task #5

•Add a manifest to your application which contains a UAC directive
◦This will mark your application as UAC-aware and will disable UAC virtualization
◦A manifest is an XML document that developers embed as a resource in a DLL or .exe file, but can be a standalone file named YourApp.exe.manifest or YourDLL.dll.manifest
◦Manifests can contain a variety of information that usually pertains to application compatibility, such as the exact version of Visual C++ runtime to load, the version of Common Controls Library to load, as well as UAC settings
◦Read more about UAC settings in the manifest in the Windows Vista Developer Story: Create and Embed an Application Manifest (UAC)
•Expected results: The application now fails to write to any of the protected folders, returning an “access denied” error
◦This is a GOOD result, because the UAC data virtualization didn’t kick into action
◦As the developer, you should be able to recognize this (because you marked the application as UAC-aware in the manifest) and avoid writing to any of the protected areas
•Conclusion: Windows enables virtualization because the application isn’t marked as UAC-aware. Marking your application as UAC-aware disables virtualization. If your app tries to write to protected store while marked as UAC-aware, you will get an access denied exception
Hands On Labs and Additional Material


Re: XnView et "User Account Control Data Redirection"

Posted: Mon Sep 27, 2010 3:45 pm
by xnview
fplanglois wrote:
xnview wrote:Le probleme c'est que Windows renvoie un chemin différent pour sauver les fichiers de config suivant l'UAC..
Oui si on utilise %userprofile%\AppData
Ils sont vraiment pénibles chez $soft, il fallait utiliser avant SHGetSpecialFolderLocation et maintenant SHGetKnownFolderPath...
Par contre, le changement risque de faire le bazar pour bcq d'utilisateurs...

Re: XnView et "User Account Control Data Redirection"

Posted: Mon Sep 27, 2010 3:54 pm
by fplanglois
xnview wrote: Ils sont vraiment pénibles chez $soft, il fallait utiliser avant SHGetSpecialFolderLocation et maintenant SHGetKnownFolderPath...
Par contre, le changement risque de faire le bazar pour bcq d'utilisateurs...
Ça, je suis bien d'accord avec vous Pierre. C'est comme le format Winhelp HLP inventé par Microsoft et pour lequel il est interdit aujourd'hui de diffuser le moteur (non intégré depuis Vista bien sûr).

C'est aussi la virtualisation des répertoires destinée à rendre compatible Seven et Vista avec les anciennes applications, mais qui rend toute tentative d'organisation du PC vraiment pénible : ranger dans des dossiers les applications du menu démarrer par exemple.

À chaque nouvelle version, ça se complique.
xnview wrote:Par contre, le changement risque de faire le bazar pour bcq d'utilisateurs...
Il faudrait que l'installateur de la nouvelle version aille chercher les paramètres dans l'ancien répertoire, selon le réglage actuel de l'UAC et les recopie au bon endroit.