From 006a24f850cd7b8872fa441e64b3a7685985a047 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 13 Oct 2022 18:00:50 +0800 Subject: [PATCH] 1 --- BPASmart.MenuLoad/App.xaml.cs | 1 + BeDesignerSCADA/Helper/SystemHelper.cs | 34 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/BPASmart.MenuLoad/App.xaml.cs b/BPASmart.MenuLoad/App.xaml.cs index e18500ba..27f00a03 100644 --- a/BPASmart.MenuLoad/App.xaml.cs +++ b/BPASmart.MenuLoad/App.xaml.cs @@ -47,6 +47,7 @@ namespace BPASmart.MenuLoad this.Dispatcher.Invoke(() => { if (File.Exists(_path)) { + SystemHelperNew.GetInstance.CreateDesktopShortcut("BeDesignerSCADA.exe"); SystemHelperNew.GetInstance.CreateDesktopShortcut(); run.LoadingData(_path); run.Show(); diff --git a/BeDesignerSCADA/Helper/SystemHelper.cs b/BeDesignerSCADA/Helper/SystemHelper.cs index 2a957edf..f643c342 100644 --- a/BeDesignerSCADA/Helper/SystemHelper.cs +++ b/BeDesignerSCADA/Helper/SystemHelper.cs @@ -44,7 +44,6 @@ namespace BeDesignerSCADA.Helper if (System.IO.File.Exists(deskTop + GetApplicationName + ".lnk")) // { return true; - //System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式 } WshShell shell = new WshShell(); //快捷键方式创建的位置、名称 @@ -66,6 +65,39 @@ namespace BeDesignerSCADA.Helper } } + public bool CreateDesktopShortcut(string Name) + { + //1、在COM对象中找到 Windows Script Host Object Model + //2、添加引用 using IWshRuntimeLibrary; + string deskTop = string.Empty; + try + { + deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\"; + if (System.IO.File.Exists(deskTop + Name + ".lnk")) // + { + return true; + } + WshShell shell = new WshShell(); + //快捷键方式创建的位置、名称 + IWshShortcut shortcut = shell.CreateShortcut(deskTop + Name + ".lnk") as IWshShortcut; + shortcut.TargetPath = GetApplicationPath; //目标文件 + //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 + shortcut.WorkingDirectory = System.Environment.CurrentDirectory; + shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】 + shortcut.Description = Name; //描述 + //shortcut.IconLocation = exePath + "\\logo.ico"; //快捷方式图标 + shortcut.Arguments = ""; + //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键 + shortcut.Save(); //必须调用保存快捷才成创建成功 + return true; + } + catch (Exception ex) + { + return false; + } + } + + /// /// 设置开机自启动 ///