在该项目中 新增 app.mainfest文件,并在其中 新增如下节点:requestedExecutionLevel level="requireAdministrator" uiAccess="false"最终效果如下:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace ApiDemo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnTest_Click(object sender, EventArgs e) { System.IO.File.WriteAllText("C:/test.txt","www.5t6t.com"); MessageBox.Show("写入成功"); } }}
评论