一定要在项目中添加引用Microsoft.CSharp
这里是打开写字板程序
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Runtime.InteropServices.Automation; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace InvokeNotepad { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { if (App.Current.HasElevatedPermissions) { using (dynamic cmd = AutomationFactory.CreateObject("WScript.Shell")) { cmd.Run(@"C:\WINDOWS\NOTEPAD.EXE", 1, true); } } } } }
本文介绍了一个使用C#编写的简单示例程序,该程序能够在Windows系统上调用写字板应用程序。通过创建WScript.Shell对象并利用其Run方法实现启动。此示例展示了如何在具备管理员权限的情况下执行外部程序。
236

被折叠的 条评论
为什么被折叠?



