如何从Windows Forms应用调用UWP启动器打开Windows设置?
在Windows Forms中打开Windows设置的可行方案
一、直接使用UWP启动器API
完全可以在Windows Forms应用中调用UWP的Windows.System.Launcher接口,步骤如下:
- 确保项目目标框架为**.NET 5+** 或 .NET Framework 4.6.2及以上
- 通过NuGet安装
Microsoft.Windows.SDK.Contracts包,添加对Windows运行时组件的引用 - 编写异步调用代码:
using Windows.System; using System.Windows.Forms; private async void OpenCameraSettings_Click(object sender, EventArgs e) { bool isOpened = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam")); if (!isOpened) { MessageBox.Show("无法打开相机隐私设置"); } }
二、兼容Win10/Win11的Process方案
原Process.Start("ms-settings:display")在Win11失效的原因是默认UseShellExecute为false,调整为true即可解决,这是最简便的兼容方案:
using System.Diagnostics; using System.Windows.Forms; private void OpenDisplaySettings_Click(object sender, EventArgs e) { try { Process.Start(new ProcessStartInfo("ms-settings:display") { UseShellExecute = true }); } catch (Exception ex) { MessageBox.Show($"打开设置失败:{ex.Message}"); } }
该方式无需额外依赖,通过系统Shell处理URI,同时支持Win10和Win11。
三、RunDLL替代方案
如果需要更传统的方式,可以调用系统的rundll32.exe打开对应设置页面,示例如下:
Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL desk.cpl,,0"); // 打开显示设置
缺点是需要记忆不同设置页面对应的DLL和参数,不如URI方式直观。
内容的提问来源于stack exchange,提问作者Horst Walter
相关产品推荐
相关产品推荐

