Shell32.dll l'interface .NET dépend du système d'exploitation
Question
Je veux trouver toutes les applications énumérées dans le menu du programme utilisateur. J'utilise la routine suivante:
private static void ProcessDirectoryLnkFiles(string path, bool recurse,
UpdateProcessFromLnkDelegate sProcFile)
{
try
{
string[] sPrograms = Directory.GetFiles(path, "*.lnk",
SearchOption.TopDirectoryOnly);
string[] sSubdirs = Directory.GetDirectories(path);
Shell32.Shell shell = new Shell32.Shell();
foreach (string p in sPrograms) {
Shell32.Folder sLinkFolder;
Shell32.FolderItem sLinkFolderItem;
Shell32.ShellLinkObject sLinkObject;
string sLinkFullpath;
// Get link full path
sLinkFullpath = Path.GetFullPath(p);
// Get link folder
sLinkFolder = shell.NameSpace(
Path.GetDirectoryName(sLinkFullpath));
// Get link item
sLinkFolderItem = sLinkFolder.Items().
Item(Path.GetFileName(sLinkFullpath));
// Get link object
sLinkObject = (Shell32.ShellLinkObject)
sLinkFolderItem.GetLink;
if (sLinkObject.Target.IsFolder == false)
sProcFile(sLinkObject);
}
if (recurse == true)
foreach (string dir in sSubdirs)
ProcessDirectoryLnkFiles(dir, true, sProcFile);
}
catch (UnauthorizedAccessException eUnauthorizedAccessException) {
sLog.Warn("Unable to iterate on directory {0} ({1}).",
path, eUnauthorizedAccessException.Message);
}
catch (IOException eIOException) {
sLog.Warn("Unable to iterate on directory {0} ({1}).",
path, eIOException.Message);
}
catch (COMException eCOMException) {
}
catch {
throw;
}
}
Cela va très bien sur Windows 7 x64. Mais malheureusement, sous Windows XP x86 l'objet Shell32.Shell
ne déclare pas la propriété Shell32.Shell.Target
. Comment puis-je faire ce code exécuté sous Windows XP?
La solution
Utilisez la propriété Path, qui vous donne le chemin vers la cible. System.IO.Directory.Exists () peut alors vous dire si elle est ou non répertoire.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow