显示“设备和打印机"通过 C# 窗口? [英] Display the "Devices and Printers" window via C#?

查看:23
本文介绍了显示“设备和打印机"通过 C# 窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 C#,如何显示此屏幕截图中所示的设备和打印机"窗口?

Using C#, how can I display the "Devices and Printers" window as shown in this screenshot?

推荐答案

应用程序可以通过执行 control.exe 在新进程中.MSDN 指出调用控制面板项的首选方法是使用其规范名称,该名称是非本地化且跨版本稳定的.从 Windows Vista 开始,每个控制面板项都有一个规范名称;MSDN 为标准 Windows 控制面板项目提供了列表.此列表表明设备和打印机项的规范名称是Microsoft.DevicesAndPrinters.

An application can open the Control Panel programmatically by executing control.exe in a new process. MSDN states that the preferred method to invoke a control panel item is to use its canonical name, which is nonlocalized and stable across versions. Beginning with Windows Vista, each Control Panel item has a canonical name; MSDN provides a list for the standard Windows control panel items. This list indicates that the canonical name for the Devices and Printers item is Microsoft.DevicesAndPrinters.

通过使用规范名称作为参数(/name <规范名称或GUID>)调用control.exe,可以在新进程中打开控制面板项:

Control panel items can be opened in a new process by invoking control.exe with the canonical name as a parameter (/name <canonical name or GUID>):

//note: assumes (using System.Diagnostics and System.IO)

string controlpath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.System),
    "control.exe"); // path to %windir%\system32\control.exe
                    // (ensures the correct control.exe)

Process.Start(controlpath, "/name Microsoft.DevicesAndPrinters");

这篇关于显示“设备和打印机"通过 C# 窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆