Provides an interface to the Windows Restart Manager. Supported on Windows Vista or newer.
See https://msdn.microsoft.com/en-us/library/windows/desktop/cc948910
Inheritance: System.MarshalByRefObject, IDisposable
コード例 #1
0
        public void TestListApps()
        {
            if (!WindowsUtils.IsWindowsVista) Assert.Ignore("Restart Manager only available on Windows Vista or higher");

            using (var restartManager = new WindowsRestartManager())
            {
                restartManager.RegisterResources(@"C:\Windows\explorer.exe");
                restartManager.ListApps(new SilentTaskHandler());
            }
        }
コード例 #2
0
        public void TestListApps()
        {
            Skip.IfNot(WindowsUtils.IsWindowsVista, reason: "Restart Manager only available on Windows Vista or higher");

            using (var restartManager = new WindowsRestartManager())
            {
                restartManager.RegisterResources(@"C:\Windows\explorer.exe");
                restartManager.ListApps(new SilentTaskHandler());
            }
        }
コード例 #3
0
        /// <summary>
        /// Uses the <see cref="WindowsRestartManager"/> to shut down applications holding references to files we want to update.
        /// </summary>
        private void RestartManagerShutdown()
        {
            if (!WindowsUtils.IsWindowsVista) return;

            _restartManager = new WindowsRestartManager();
            _restartManager.RegisterResources(GetFilesToWrite());
            _restartManager.RegisterResources(GetFilesToDelete());
            _restartManager.ShutdownApps(new SilentTaskHandler());
        }
コード例 #4
0
        /// <summary>
        /// Closes any open <see cref="WindowsRestartManager"/> sessions.
        /// </summary>
        private void RestartManagerFinish()
        {
            if (_restartManager == null) return;

            _restartManager.Dispose();
            _restartManager = null;
        }
コード例 #5
0
        /// <summary>
        /// Uses <see cref="WindowsRestartManager"/> to close any applications that have open references to the specified <paramref name="files"/> if possible and removes read-only attributes.
        /// </summary>
        /// <remarks>Closed applications will be restarted by <see cref="Dispose"/>.</remarks>
        protected void UnlockFiles(IEnumerable<string> files)
        {
            if (WindowsUtils.IsWindows)
            {
                var fileArray = files.ToArray();
                if (fileArray.Length == 0) return;

                if (WindowsUtils.IsWindowsVista)
                {
                    if (_restartManager == null)
                        _restartManager = new WindowsRestartManager();

                    _restartManager.RegisterResources(fileArray);
                    if (_restartManager.ListApps(Handler).Length == 0) NoRestart = true;
                    _restartManager.ShutdownApps(Handler);
                }

                foreach (string path in fileArray)
                    new FileInfo(path).IsReadOnly = false;
            }
        }