Exemple #1
0
        //https://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx
        private static ProcessInfo ManagementObjectToProcessInfo(ManagementObject queryObj, Process process)
        {
            var result = new ProcessInfo
            {
                Name          = queryObj.TryGetProperty <string>("Name"),
                PrivateBytes  = process?.PrivateMemorySize64 ?? 0,
                WorkingSet    = (long)queryObj.TryGetProperty <ulong>("WorkingSetSize"),
                Id            = (int)queryObj.TryGetProperty <uint>("ProcessId"),
                ParentProcess = (int)queryObj.TryGetProperty <uint>("ParentProcessId"),
                StartTime     =
                    (ManagementExtensions.ToDateTimeSafe(queryObj.TryGetProperty <string>("CreationDate")) ??
                     ExceptionUtilities.EatExceptions(() => process?.StartTime) ?? DateTime.MinValue)
                    .ToUniversalTime(),
                Filename         = queryObj.TryGetProperty <string>("ExecutablePath"),
                CommandLine      = queryObj.TryGetProperty <string>("CommandLine"),
                MainWindowHandle = (long)(process?.MainWindowHandle ?? IntPtr.Zero)
            };

            ApplyProcessInformation(process, result, queryObj.TryGetProperty <string>("ExecutablePath"));

            return(result);
        }
        public static List <IFileExplorerEntry> GetComputerDirectoryEntries()
        {
#if !NET45
            if (CoreHelper.RunningOnXP)
            {
                return
                    (DriveInfo.GetDrives()
                     .Select(x => GetDirectoryEntry(new DirectoryInfoEx(x.RootDirectory.FullName), null))
                     .Cast <IFileExplorerEntry>()
                     .ToList());
            }
#endif

            var entries = GetDirectoryEntries(DirectoryInfoEx.MyComputerDirectory);
            if (!CoreHelper.RunningOnWin8OrGreater)
            {
                bool success = false;
                try
                {
                    var librariesDirectory = new DirectoryInfoEx(KnownFolderIds.Libraries);
                    entries.InsertRange(0, librariesDirectory.GetDirectories().Select(x => GetDirectoryEntry(x, null)).Cast <IFileExplorerEntry>());
                    success = true;
                }
                catch (Exception)
                {
                    // ignored
                }

                if (!success)
                {
                    var musicEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)),
                                null));
                    if (musicEntry != null)
                    {
                        entries.Insert(0, musicEntry);
                    }

                    var documentsEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),
                                null));
                    if (documentsEntry != null)
                    {
                        entries.Insert(0, documentsEntry);
                    }

                    var picturesEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)),
                                null));
                    if (picturesEntry != null)
                    {
                        entries.Insert(0, picturesEntry);
                    }
                }
            }

            return(entries);
        }