From 5e185e152ee2cb054d0b16cda960e93f765f7ac5 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Mon, 13 Mar 2023 21:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Form.cs | 922 +++++++++--------- Properties/AssemblyInfo.cs | 72 +- README.md | 10 +- ...45\260\217\345\267\245\345\205\267.csproj" | 258 ++--- ...0\217\345\267\245\345\205\267.csproj.user" | 22 +- 5 files changed, 660 insertions(+), 624 deletions(-) diff --git a/Form.cs b/Form.cs index b8aca4f..ac91d10 100644 --- a/Form.cs +++ b/Form.cs @@ -1,461 +1,461 @@ -using System; -using System.Diagnostics; -using System.Windows.Forms; -using System.IO; -using System.Text; -using IWshRuntimeLibrary; -using UAC白名单小工具.Properties; -using System.Threading.Tasks; -using System.Text.RegularExpressions; -using Microsoft.Win32; -using System.Drawing; - -namespace UAC白名单小工具 -{ - public partial class Form : System.Windows.Forms.Form - { - readonly string[] args; - - public FileDropAdmin_cs.FileDropAdmin FileDroper; - public Form(string[] args) - { - InitializeComponent(); - this.args = args; - } - string J_VerInfo;// 软件版本号 - // 程序创建前 - private void Form1_Load(object sender, EventArgs e) - { - if (args.Length > 0) - { - //Debug.Print(args[0]); - Handling_File_Drop(args[0]); - } - FileDroper = new FileDropAdmin_cs.FileDropAdmin(this); - FileVersionInfo VerInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath); - J_VerInfo = VerInfo.FileVersion; - J_VerInfo = J_VerInfo.Replace(".0.0",""); - this.Text = "UAC白名单小工具 v" + J_VerInfo; - Task.Run(() => Check_Updates(false)); - NotKey(); - } - // 有文件拖放进来了 - private void Form1_DragEnter(object sender, DragEventArgs e) - { - e.Effect = DragDropEffects.Link; - } - // 处理拖放进来的文件 - private void Form1_DragDrop(object sender, DragEventArgs e) - { - Handling_File_Drop(((string[])e.Data.GetData(typeof(string[])))[0]); - } - // 处理拖放进来的文件 - private void Handling_File_Drop(string Drag_File_PATH) - { - Debug.Print(Drag_File_PATH); - if (Path.GetExtension(Drag_File_PATH).ToLower() == ".exe" || Path.GetExtension(Drag_File_PATH).ToLower() == ".bat") - { - if (System.IO.File.Exists(Drag_File_PATH)) - { - TextBox_程序位置.Text = Drag_File_PATH; - TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); - TextBox_启动参数.Text = ""; - TextBox_起始位置.Text = ""; - TextBox_启动参数.SendToBack(); - TextBox_起始位置.SendToBack(); - TextBox_程序位置.BringToFront(); - TextBox_程序名称.BringToFront(); - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else if (Path.GetExtension(Drag_File_PATH).ToLower() == ".lnk") - { - if (System.IO.File.Exists(Drag_File_PATH)) - { - WshShell shell = new WshShell(); - IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(Drag_File_PATH); - if (System.IO.File.Exists(Shortcut.TargetPath)) - { - TextBox_程序位置.Text = Shortcut.TargetPath; - TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); - TextBox_启动参数.Text = Shortcut.Arguments; - TextBox_起始位置.Text = Shortcut.WorkingDirectory; - TextBox_程序位置.BringToFront(); - TextBox_程序名称.BringToFront(); - if(TextBox_启动参数.Text != "") - { - TextBox_启动参数.BringToFront(); - } - else - { - TextBox_启动参数.SendToBack(); - } - if (TextBox_起始位置.Text != "") - { - TextBox_起始位置.BringToFront(); - } - else - { - TextBox_起始位置.SendToBack(); - } - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else - { - MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - // 监视输入框 - private void TextBox_程序名称_TextChanged(object sender, EventArgs e) - { - TextBox_程序名称.Text = Regex.Replace(TextBox_程序名称.Text, @"[^\u4e00-\u9fa5_a-zA-Z0-9\.]", ""); - //Debug.Print(TextBox_程序名称.Text); - if (TextBox_程序名称.Text != "") - { - if (TextBox_程序位置.Text != "") - { - Button_添加.Enabled = true; - } - } - else - { - Button_添加.Enabled = false; - } - } - // 监视输入框 - private void TextBox_程序位置_TextChanged(object sender, EventArgs e) - { - if (TextBox_程序位置.Text != "") - { - if (TextBox_程序名称.Text != "") - { - Button_添加.Enabled = true; - } - } - else - { - Button_添加.Enabled = false; - } - } - // 用对话框选择文件 - private void Button_浏览_Click(object sender, EventArgs e) - { - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - if (Path.GetExtension(openFileDialog1.FileName) == ".exe") - { - if (System.IO.File.Exists(openFileDialog1.FileName)) - { - TextBox_程序位置.Text = openFileDialog1.FileName; - TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); - TextBox_启动参数.Text = ""; - TextBox_起始位置.Text = ""; - TextBox_启动参数.SendToBack(); - TextBox_起始位置.SendToBack(); - TextBox_程序位置.BringToFront(); - TextBox_程序名称.BringToFront(); - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else if (Path.GetExtension(openFileDialog1.FileName) == ".lnk") - { - if (System.IO.File.Exists(openFileDialog1.FileName)) - { - WshShell shell = new WshShell(); - IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(openFileDialog1.FileName); - if (System.IO.File.Exists(Shortcut.TargetPath)) - { - TextBox_程序位置.Text = Shortcut.TargetPath; - TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); - TextBox_启动参数.Text = Shortcut.Arguments; - TextBox_起始位置.Text = Shortcut.WorkingDirectory; - TextBox_程序位置.BringToFront(); - TextBox_程序名称.BringToFront(); - if (TextBox_启动参数.Text != "") - { - TextBox_启动参数.BringToFront(); - } - else - { - TextBox_启动参数.SendToBack(); - } - if (TextBox_起始位置.Text != "") - { - TextBox_起始位置.BringToFront(); - } - else - { - TextBox_起始位置.SendToBack(); - } - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else - { - MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else - { - MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - // 添加、写入 - private void Button_添加_Click(object sender, EventArgs e) - { - // 先判断一下程序名称前缀是否有 noUAC. - if (TextBox_程序名称.Text.Length >= 6) - { - if (TextBox_程序名称.Text.Substring(0, 6) != "noUAC.") - { - TextBox_程序名称.Text = "noUAC." + TextBox_程序名称.Text; - } - } - else - { - TextBox_程序名称.Text = "noUAC." + TextBox_程序名称.Text; - } - string TempFileName = Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".xml"; - string XML_Text = Resources.XML_前 + Environment.NewLine + Resources.XML_程序位置_前 + TextBox_程序位置.Text + Resources.XML_程序位置_后; - if (TextBox_启动参数.Text != "") - { - XML_Text = XML_Text + Environment.NewLine + Resources.XML_启动参数_前 + TextBox_启动参数.Text + Resources.XML_启动参数_后; - } - if (TextBox_起始位置.Text != "") - { - XML_Text = XML_Text + Environment.NewLine + Resources.XML_起始位置_前 + TextBox_起始位置.Text + Resources.XML_起始位置_后; - } - XML_Text = XML_Text + Environment.NewLine + Resources.XML_后; - System.IO.File.WriteAllText(TempFileName, XML_Text, Encoding.Unicode); - ProcessStartInfo Schtasks = new ProcessStartInfo - { - FileName = "schtasks.exe", - WindowStyle = ProcessWindowStyle.Hidden, - Arguments = "/create " + "/tn " + '"' + TextBox_程序名称.Text + '"' + " /xml " + '"' + @TempFileName + '"' - }; - //Debug.Print("/create " + "/tn " + '"' + TextBox_程序名称.Text + '"' + " /xml " + '"' + @TempFileName + '"'); - //Schtasks.Verb = "runas"; - Process.Start(Schtasks); - Create_Shortcut(); - System.Threading.Thread.Sleep(200); - System.IO.File.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".xml"); - MessageBox.Show("UAC白名单添加成功!" + Environment.NewLine + Environment.NewLine + "快捷方式位于桌面:" + Environment.NewLine + System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + @"\" + TextBox_程序名称.Text + ".lnk" + Environment.NewLine + "注意:只有通过该快捷方式运行才不会提示 UAC,快捷方式可复制、移动、重命名。", "信息:",MessageBoxButtons.OK); - } - // 创建快捷方式 - public void Create_Shortcut() - { - WshShell shell = new WshShell(); - IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + @"\" + TextBox_程序名称.Text + ".lnk"); - //Debug.Print(Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".lnk"); - shortcut.TargetPath = "schtasks.exe"; - shortcut.Arguments = "/run " + "/tn " + '"' + TextBox_程序名称.Text + '"'; - shortcut.IconLocation = TextBox_程序位置.Text + ", 0"; - shortcut.WindowStyle = 7; - shortcut.Save(); - } - - private void Button_打开_Click(object sender, EventArgs e) - { - Process.Start("taskschd.msc", "/s"); - } - // 检查更新 - private void Check_Updates(bool Tipprompt) - { - string strHTML = WebClient_cs.GetHTTP.Get_HTTP("https://api.xiuer.pw/ver/uacbmdxgj.txt"); - Debug.Print(strHTML); - string[] Ver_Info = strHTML.Split('\n'); - if (Ver_Info.Length > 2) - { - if (Ver_Info[1] != "") - { - if (Ver_Info[1] != J_VerInfo) - { - if (MessageBox.Show("发现新版本 [v" + Ver_Info[1] + "]!是否前往更新?", "发现新版本!", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - Process.Start(Ver_Info[2]); - } - } - else - { - if (Tipprompt == true) - { - MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); - } - - } - } - else - { - if (Tipprompt == true) - { - MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); - } - } - } - else - { - if (Tipprompt == true) - { - MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); - } - } - } - - private void CheckBox_添加到右键菜单_CheckedChanged(object sender, EventArgs e) - { - //Debug.Print(checkBox_添加到右键菜单.Checked.ToString()); - if (checkBox_添加到右键菜单.Checked == true) - { - AddKey(); - } - else - { - DelKey(); - } - - } - private void AddKey() - { - if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) == null) - { - RegistryKey Key1 = Registry.ClassesRoot.CreateSubKey(@"exefile\shell\添加到 UAC 白名单"); - RegistryKey Key2 = Registry.ClassesRoot.CreateSubKey(@"exefile\shell\添加到 UAC 白名单\command"); - Key1.SetValue("Icon", '"' + Application.ExecutablePath + '"'); - Key2.SetValue("", '"'+ Application.ExecutablePath + '"' + " " + '"' + "%1" + '"'); - - } - } - private void DelKey() - { - if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) != null) - { - Registry.ClassesRoot.DeleteSubKeyTree(@"exefile\shell\添加到 UAC 白名单"); - } - } - private void NotKey() - { - //RegistryKey Key = Registry.ClassesRoot; - if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) == null) - { - checkBox_添加到右键菜单.Checked = false; - } - else - { - checkBox_添加到右键菜单.Checked = true; - } - //Debug.Print(Reg.GetValue("").ToString()); - - } - // 切换焦点为输入框 - private void Label_程序位置_MouseClick(object sender, MouseEventArgs e) - { - TextBox_程序位置.Focus(); - } - - private void Label_程序名称_MouseClick(object sender, MouseEventArgs e) - { - TextBox_程序名称.Focus(); - } - - private void Label_启动参数_MouseClick(object sender, MouseEventArgs e) - { - TextBox_启动参数.Focus(); - } - - private void Label_起始位置_MouseClick(object sender, MouseEventArgs e) - { - TextBox_起始位置.Focus(); - } - // 置顶输入框并修改背景颜色 - private void TextBox_程序位置_Enter(object sender, EventArgs e) - { - TextBox_程序位置.BringToFront(); - TextBox_程序位置.BackColor = Color.Gainsboro; - Label_程序位置.BackColor = Color.Gainsboro; - } - - private void TextBox_程序位置_Leave(object sender, EventArgs e) - { - if (TextBox_程序位置.Text == "") - TextBox_程序位置.SendToBack(); - TextBox_程序位置.BackColor = Color.WhiteSmoke; - Label_程序位置.BackColor = Color.WhiteSmoke; - } - - private void TextBox_程序名称_Enter(object sender, EventArgs e) - { - TextBox_程序名称.BringToFront(); - TextBox_程序名称.BackColor = Color.Gainsboro; - Label_程序名称.BackColor = Color.Gainsboro; - } - - private void TextBox_程序名称_Leave(object sender, EventArgs e) - { - if (TextBox_程序名称.Text == "") - TextBox_程序名称.SendToBack(); - TextBox_程序名称.BackColor = Color.WhiteSmoke; - Label_程序名称.BackColor = Color.WhiteSmoke; - } - - private void TextBox_启动参数_Enter(object sender, EventArgs e) - { - TextBox_启动参数.BringToFront(); - TextBox_启动参数.BackColor = Color.Gainsboro; - Label_启动参数.BackColor = Color.Gainsboro; - } - - private void TextBox_启动参数_Leave(object sender, EventArgs e) - { - if (TextBox_启动参数.Text == "") - TextBox_启动参数.SendToBack(); - TextBox_启动参数.BackColor = Color.WhiteSmoke; - Label_启动参数.BackColor = Color.WhiteSmoke; - } - - private void TextBox_起始位置_Enter(object sender, EventArgs e) - { - TextBox_起始位置.BringToFront(); - TextBox_起始位置.BackColor = Color.Gainsboro; - Label_起始位置.BackColor = Color.Gainsboro; - } - - private void TextBox_起始位置_Leave(object sender, EventArgs e) - { - if (TextBox_起始位置.Text == "") - TextBox_起始位置.SendToBack(); - TextBox_起始位置.BackColor = Color.WhiteSmoke; - Label_起始位置.BackColor = Color.WhiteSmoke; - } - - private void Button_添加_EnabledChanged(object sender, EventArgs e) - { - if (Button_添加.Enabled == true) - { - Button_添加.BackColor = Color.MediumSeaGreen; - } - else - { - Button_添加.BackColor = SystemColors.ButtonShadow; - } - } - } -} +using System; +using System.Diagnostics; +using System.Windows.Forms; +using System.IO; +using System.Text; +using IWshRuntimeLibrary; +using UAC白名单小工具.Properties; +using System.Threading.Tasks; +using System.Text.RegularExpressions; +using Microsoft.Win32; +using System.Drawing; + +namespace UAC白名单小工具 +{ + public partial class Form : System.Windows.Forms.Form + { + readonly string[] args; + + public FileDropAdmin_cs.FileDropAdmin FileDroper; + public Form(string[] args) + { + InitializeComponent(); + this.args = args; + } + string J_VerInfo;// 软件版本号 + // 程序创建前 + private void Form1_Load(object sender, EventArgs e) + { + if (args.Length > 0) + { + //Debug.Print(args[0]); + Handling_File_Drop(args[0]); + } + FileDroper = new FileDropAdmin_cs.FileDropAdmin(this); + FileVersionInfo VerInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath); + J_VerInfo = VerInfo.FileVersion; + J_VerInfo = J_VerInfo.Replace(".0",""); + this.Text = "UAC白名单小工具 v" + J_VerInfo; + //Task.Run(() => Check_Updates(false)); + NotKey(); + } + // 有文件拖放进来了 + private void Form1_DragEnter(object sender, DragEventArgs e) + { + e.Effect = DragDropEffects.Link; + } + // 处理拖放进来的文件 + private void Form1_DragDrop(object sender, DragEventArgs e) + { + Handling_File_Drop(((string[])e.Data.GetData(typeof(string[])))[0]); + } + // 处理拖放进来的文件 + private void Handling_File_Drop(string Drag_File_PATH) + { + Debug.Print(Drag_File_PATH); + if (Path.GetExtension(Drag_File_PATH).ToLower() == ".exe" || Path.GetExtension(Drag_File_PATH).ToLower() == ".bat") + { + if (System.IO.File.Exists(Drag_File_PATH)) + { + TextBox_程序位置.Text = Drag_File_PATH; + TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); + TextBox_启动参数.Text = ""; + TextBox_起始位置.Text = ""; + TextBox_启动参数.SendToBack(); + TextBox_起始位置.SendToBack(); + TextBox_程序位置.BringToFront(); + TextBox_程序名称.BringToFront(); + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else if (Path.GetExtension(Drag_File_PATH).ToLower() == ".lnk") + { + if (System.IO.File.Exists(Drag_File_PATH)) + { + WshShell shell = new WshShell(); + IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(Drag_File_PATH); + if (System.IO.File.Exists(Shortcut.TargetPath)) + { + TextBox_程序位置.Text = Shortcut.TargetPath; + TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); + TextBox_启动参数.Text = Shortcut.Arguments; + TextBox_起始位置.Text = Shortcut.WorkingDirectory; + TextBox_程序位置.BringToFront(); + TextBox_程序名称.BringToFront(); + if(TextBox_启动参数.Text != "") + { + TextBox_启动参数.BringToFront(); + } + else + { + TextBox_启动参数.SendToBack(); + } + if (TextBox_起始位置.Text != "") + { + TextBox_起始位置.BringToFront(); + } + else + { + TextBox_起始位置.SendToBack(); + } + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + // 监视输入框 + private void TextBox_程序名称_TextChanged(object sender, EventArgs e) + { + TextBox_程序名称.Text = Regex.Replace(TextBox_程序名称.Text, @"[^\u4e00-\u9fa5_a-zA-Z0-9\.]", ""); + //Debug.Print(TextBox_程序名称.Text); + if (TextBox_程序名称.Text != "") + { + if (TextBox_程序位置.Text != "") + { + Button_添加.Enabled = true; + } + } + else + { + Button_添加.Enabled = false; + } + } + // 监视输入框 + private void TextBox_程序位置_TextChanged(object sender, EventArgs e) + { + if (TextBox_程序位置.Text != "") + { + if (TextBox_程序名称.Text != "") + { + Button_添加.Enabled = true; + } + } + else + { + Button_添加.Enabled = false; + } + } + // 用对话框选择文件 + private void Button_浏览_Click(object sender, EventArgs e) + { + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + if (Path.GetExtension(openFileDialog1.FileName) == ".exe") + { + if (System.IO.File.Exists(openFileDialog1.FileName)) + { + TextBox_程序位置.Text = openFileDialog1.FileName; + TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); + TextBox_启动参数.Text = ""; + TextBox_起始位置.Text = ""; + TextBox_启动参数.SendToBack(); + TextBox_起始位置.SendToBack(); + TextBox_程序位置.BringToFront(); + TextBox_程序名称.BringToFront(); + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else if (Path.GetExtension(openFileDialog1.FileName) == ".lnk") + { + if (System.IO.File.Exists(openFileDialog1.FileName)) + { + WshShell shell = new WshShell(); + IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(openFileDialog1.FileName); + if (System.IO.File.Exists(Shortcut.TargetPath)) + { + TextBox_程序位置.Text = Shortcut.TargetPath; + TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text); + TextBox_启动参数.Text = Shortcut.Arguments; + TextBox_起始位置.Text = Shortcut.WorkingDirectory; + TextBox_程序位置.BringToFront(); + TextBox_程序名称.BringToFront(); + if (TextBox_启动参数.Text != "") + { + TextBox_启动参数.BringToFront(); + } + else + { + TextBox_启动参数.SendToBack(); + } + if (TextBox_起始位置.Text != "") + { + TextBox_起始位置.BringToFront(); + } + else + { + TextBox_起始位置.SendToBack(); + } + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + // 添加、写入 + private void Button_添加_Click(object sender, EventArgs e) + { + // 先判断一下程序名称前缀是否有 noUAC. + if (TextBox_程序名称.Text.Length >= 6) + { + if (TextBox_程序名称.Text.Substring(0, 6) != "noUAC.") + { + TextBox_程序名称.Text = "noUAC." + TextBox_程序名称.Text; + } + } + else + { + TextBox_程序名称.Text = "noUAC." + TextBox_程序名称.Text; + } + string TempFileName = Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".xml"; + string XML_Text = Resources.XML_前 + Environment.NewLine + Resources.XML_程序位置_前 + TextBox_程序位置.Text + Resources.XML_程序位置_后; + if (TextBox_启动参数.Text != "") + { + XML_Text = XML_Text + Environment.NewLine + Resources.XML_启动参数_前 + TextBox_启动参数.Text + Resources.XML_启动参数_后; + } + if (TextBox_起始位置.Text != "") + { + XML_Text = XML_Text + Environment.NewLine + Resources.XML_起始位置_前 + TextBox_起始位置.Text + Resources.XML_起始位置_后; + } + XML_Text = XML_Text + Environment.NewLine + Resources.XML_后; + System.IO.File.WriteAllText(TempFileName, XML_Text, Encoding.Unicode); + ProcessStartInfo Schtasks = new ProcessStartInfo + { + FileName = "schtasks.exe", + WindowStyle = ProcessWindowStyle.Hidden, + Arguments = "/create " + "/tn " + '"' + TextBox_程序名称.Text + '"' + " /xml " + '"' + @TempFileName + '"' + }; + //Debug.Print("/create " + "/tn " + '"' + TextBox_程序名称.Text + '"' + " /xml " + '"' + @TempFileName + '"'); + //Schtasks.Verb = "runas"; + Process.Start(Schtasks); + Create_Shortcut(); + System.Threading.Thread.Sleep(200); + System.IO.File.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".xml"); + MessageBox.Show("UAC白名单添加成功!" + Environment.NewLine + Environment.NewLine + "快捷方式位于桌面:" + Environment.NewLine + System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + @"\" + TextBox_程序名称.Text + ".lnk" + Environment.NewLine + "注意:只有通过该快捷方式运行才不会提示 UAC,快捷方式可复制、移动、重命名。", "信息:",MessageBoxButtons.OK); + } + // 创建快捷方式 + public void Create_Shortcut() + { + WshShell shell = new WshShell(); + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + @"\" + TextBox_程序名称.Text + ".lnk"); + //Debug.Print(Path.GetDirectoryName(Application.ExecutablePath) + @"\" + TextBox_程序名称.Text + ".lnk"); + shortcut.TargetPath = "schtasks.exe"; + shortcut.Arguments = "/run " + "/tn " + '"' + TextBox_程序名称.Text + '"'; + shortcut.IconLocation = TextBox_程序位置.Text + ", 0"; + shortcut.WindowStyle = 7; + shortcut.Save(); + } + + private void Button_打开_Click(object sender, EventArgs e) + { + Process.Start("taskschd.msc", "/s"); + } + // 检查更新 + private void Check_Updates(bool Tipprompt) + { + string strHTML = WebClient_cs.GetHTTP.Get_HTTP("https://api.xiu2.xyz/ver/uacbmdxgj.txt"); + Debug.Print(strHTML); + string[] Ver_Info = strHTML.Split('\n'); + if (Ver_Info.Length > 2) + { + if (Ver_Info[1] != "") + { + if (Ver_Info[1] != J_VerInfo) + { + if (MessageBox.Show("发现新版本 [v" + Ver_Info[1] + "]!是否前往更新?", "发现新版本!", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + Process.Start(Ver_Info[2]); + } + } + else + { + if (Tipprompt == true) + { + MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); + } + + } + } + else + { + if (Tipprompt == true) + { + MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); + } + } + } + else + { + if (Tipprompt == true) + { + MessageBox.Show("当前已是最新版本 " + J_VerInfo + " !", "信息:", MessageBoxButtons.OK); + } + } + } + + private void CheckBox_添加到右键菜单_CheckedChanged(object sender, EventArgs e) + { + //Debug.Print(checkBox_添加到右键菜单.Checked.ToString()); + if (checkBox_添加到右键菜单.Checked == true) + { + AddKey(); + } + else + { + DelKey(); + } + + } + private void AddKey() + { + if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) == null) + { + RegistryKey Key1 = Registry.ClassesRoot.CreateSubKey(@"exefile\shell\添加到 UAC 白名单"); + RegistryKey Key2 = Registry.ClassesRoot.CreateSubKey(@"exefile\shell\添加到 UAC 白名单\command"); + Key1.SetValue("Icon", '"' + Application.ExecutablePath + '"'); + Key2.SetValue("", '"'+ Application.ExecutablePath + '"' + " " + '"' + "%1" + '"'); + + } + } + private void DelKey() + { + if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) != null) + { + Registry.ClassesRoot.DeleteSubKeyTree(@"exefile\shell\添加到 UAC 白名单"); + } + } + private void NotKey() + { + //RegistryKey Key = Registry.ClassesRoot; + if (Registry.GetValue(@"HKEY_CLASSES_ROOT\exefile\shell\添加到 UAC 白名单\command\", "", null) == null) + { + checkBox_添加到右键菜单.Checked = false; + } + else + { + checkBox_添加到右键菜单.Checked = true; + } + //Debug.Print(Reg.GetValue("").ToString()); + + } + // 切换焦点为输入框 + private void Label_程序位置_MouseClick(object sender, MouseEventArgs e) + { + TextBox_程序位置.Focus(); + } + + private void Label_程序名称_MouseClick(object sender, MouseEventArgs e) + { + TextBox_程序名称.Focus(); + } + + private void Label_启动参数_MouseClick(object sender, MouseEventArgs e) + { + TextBox_启动参数.Focus(); + } + + private void Label_起始位置_MouseClick(object sender, MouseEventArgs e) + { + TextBox_起始位置.Focus(); + } + // 置顶输入框并修改背景颜色 + private void TextBox_程序位置_Enter(object sender, EventArgs e) + { + TextBox_程序位置.BringToFront(); + TextBox_程序位置.BackColor = Color.Gainsboro; + Label_程序位置.BackColor = Color.Gainsboro; + } + + private void TextBox_程序位置_Leave(object sender, EventArgs e) + { + if (TextBox_程序位置.Text == "") + TextBox_程序位置.SendToBack(); + TextBox_程序位置.BackColor = Color.WhiteSmoke; + Label_程序位置.BackColor = Color.WhiteSmoke; + } + + private void TextBox_程序名称_Enter(object sender, EventArgs e) + { + TextBox_程序名称.BringToFront(); + TextBox_程序名称.BackColor = Color.Gainsboro; + Label_程序名称.BackColor = Color.Gainsboro; + } + + private void TextBox_程序名称_Leave(object sender, EventArgs e) + { + if (TextBox_程序名称.Text == "") + TextBox_程序名称.SendToBack(); + TextBox_程序名称.BackColor = Color.WhiteSmoke; + Label_程序名称.BackColor = Color.WhiteSmoke; + } + + private void TextBox_启动参数_Enter(object sender, EventArgs e) + { + TextBox_启动参数.BringToFront(); + TextBox_启动参数.BackColor = Color.Gainsboro; + Label_启动参数.BackColor = Color.Gainsboro; + } + + private void TextBox_启动参数_Leave(object sender, EventArgs e) + { + if (TextBox_启动参数.Text == "") + TextBox_启动参数.SendToBack(); + TextBox_启动参数.BackColor = Color.WhiteSmoke; + Label_启动参数.BackColor = Color.WhiteSmoke; + } + + private void TextBox_起始位置_Enter(object sender, EventArgs e) + { + TextBox_起始位置.BringToFront(); + TextBox_起始位置.BackColor = Color.Gainsboro; + Label_起始位置.BackColor = Color.Gainsboro; + } + + private void TextBox_起始位置_Leave(object sender, EventArgs e) + { + if (TextBox_起始位置.Text == "") + TextBox_起始位置.SendToBack(); + TextBox_起始位置.BackColor = Color.WhiteSmoke; + Label_起始位置.BackColor = Color.WhiteSmoke; + } + + private void Button_添加_EnabledChanged(object sender, EventArgs e) + { + if (Button_添加.Enabled == true) + { + Button_添加.BackColor = Color.MediumSeaGreen; + } + else + { + Button_添加.BackColor = SystemColors.ButtonShadow; + } + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 3b6a717..669bf37 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 有关程序集的一般信息由以下 -// 控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("UAC白名单小工具")] -[assembly: AssemblyDescription("UAC白名单小工具")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("X.I.U")] -[assembly: AssemblyProduct("UAC白名单小工具")] -[assembly: AssemblyCopyright("Copyright © 2020 X.I.U. All Rights Reserved.")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 会使此程序集中的类型 -//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 -//请将此类型的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("cace89b6-1927-4695-b915-fa14d349c66c")] - -// 程序集的版本信息由下列四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 -//通过使用 "*",如下所示: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("UAC白名单小工具")] +[assembly: AssemblyDescription("UAC白名单小工具")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("X.I.U")] +[assembly: AssemblyProduct("UAC白名单小工具")] +[assembly: AssemblyCopyright("Copyright © 2020 X.I.U. All Rights Reserved.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("cace89b6-1927-4695-b915-fa14d349c66c")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.8.1.0")] +[assembly: AssemblyFileVersion("1.8.1.0")] diff --git a/README.md b/README.md index 486bbb4..ee6e260 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ ## 软件界面 -![软件界面](https://raw.githubusercontent.com/XIU2/UACWhitelistTool/master/img/02.png) -![右键菜单](https://raw.githubusercontent.com/XIU2/UACWhitelistTool/master/img/01.png) +![软件界面](https://cdn.staticaly.com/gh/XIU2/UACWhitelistTool/master/img/02.png) +![右键菜单](https://cdn.staticaly.com/gh/XIU2/UACWhitelistTool/master/img/01.png) **** ## 下载地址 -* 蓝奏云 :[https://pan.lanzouq.com/b073m0dne](https://pan.lanzouq.com/b073m0dne) +* 蓝奏云 :[https://pan.lanzouf.com/b073m0dne](https://pan.lanzouf.com/b073m0dne) * Github:[https://github.com/XIU2/UACWhitelistTool/releases](https://github.com/XIU2/UACWhitelistTool/releases) **** @@ -68,6 +68,10 @@ ## 更新日志 +### 2023年03月13日,版本 v1.8.1 + +1. **移除** 检查更新。 + ### 2020年08月07日,版本 v1.8 1. **美化** 软件界面。 diff --git "a/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj" "b/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj" index 42d8c77..3a149eb 100644 --- "a/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj" +++ "b/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj" @@ -1,119 +1,141 @@ - - - - - Debug - AnyCPU - {CACE89B6-1927-4695-B915-FA14D349C66C} - WinExe - UAC白名单小工具 - UAC白名单小工具 - v4.5 - 512 - true - true - - - - AnyCPU - true - full - false - ..\..\Program\UAC白名单小工具\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - ..\..\Program\UAC白名单小工具\Release\ - TRACE - prompt - 4 - - - - UAC白名单小工具.Program - - - LocalIntranet - - - false - - - - Icon.ico - - - Properties\app.manifest - - - - - - - - - - - - - - - - - - Form - - - Form.cs - - - - - - Form.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} - 1 - 0 - 0 - tlbimp - False - True - - - - - - + + + + + Debug + AnyCPU + {CACE89B6-1927-4695-B915-FA14D349C66C} + WinExe + UAC白名单小工具 + UAC白名单小工具 + v4.5 + 512 + true + true + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + ..\..\Program\UAC白名单小工具\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\Program\UAC白名单小工具\Release\ + TRACE + prompt + 4 + + + + UAC白名单小工具.Program + + + LocalIntranet + + + false + + + + Icon.ico + + + Properties\app.manifest + + + + + + + + + + + + + + + + + + Form + + + Form.cs + + + + + + Form.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + + + + + + + + False + .NET Framework 3.5 SP1 + false + + + \ No newline at end of file diff --git "a/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj.user" "b/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj.user" index 29671f6..9301745 100644 --- "a/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj.user" +++ "b/UAC\347\231\275\345\220\215\345\215\225\345\260\217\345\267\245\345\205\267.csproj.user" @@ -1,7 +1,17 @@ - - - - - - + + + + + + + + + + + + + + zh-CN + false + \ No newline at end of file