【发布时间】:2020-05-21 10:15:59
【问题描述】:
这是我当前的代码,它可以工作,但它会重新启动资源管理器进程,这有点奇怪。
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace MyApp
{
class Program
{
static async Task Main(string[] args)
{
ShowSmallTaskbarIcons();
// ShowLargeTaskbarIcons();
Console.WriteLine("Press a key to exit...");
Console.ReadKey();
}
static void ShowSmallTaskbarIcons()
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSmallIcons", "1", RegistryValueKind.DWord);
RefreshExplorer();
}
static void ShowLargeTaskbarIcons()
{
var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", writable: true);
key.DeleteValue("TaskbarSmallIcons", throwOnMissingValue: false);
key.Close();
RefreshExplorer();
}
static void RefreshExplorer()
{
Process.Start("taskkill.exe", "/f /im explorer.exe");
Thread.Sleep(2000);
Process.Start("explorer.exe");
Thread.Sleep(10000);
}
}
}
我想对“设置”中的“使用小任务栏按钮”切换开关做同样的事情。
如何用 C# 做同样的事情?
【问题讨论】:
-
请问为什么不需要重启windows explorer?
-
东西突然从屏幕上消失有点令人不安。
-
it restarts the Explorer process and that's kinda weird你从来没有在你的帖子中描述过kinda weird是什么。您确实知道您正在自己杀死任务然后重新启动它,请以其他方式说明您的代码正在做什么。 -
我想模仿 Windows 的做法,似乎有办法重新启动或应用任务栏更改。
-
找到渲染任务栏的函数并只使用它们。根据需要更改变量。
标签: c# windows .net-core registry