-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsShortcuts.cs
42 lines (36 loc) · 1.44 KB
/
WindowsShortcuts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using IWshRuntimeLibrary;
using System;
using System.IO;
using System.Text;
using File = System.IO.File;
namespace CalMedUpdater
{
public static class WindowsShortcuts
{
private static string GetAllUsersDesktopDirectory()
{
var path = new StringBuilder(260);
Utility.SHGetSpecialFolderPath(IntPtr.Zero, path, 0x19, false);
return path.ToString();
}
public static void DeleteDesktopShortcut(DesktopShortcut desktopShortcut)
{
var shortcutPath = Path.Combine(GetAllUsersDesktopDirectory(), $"{desktopShortcut.Name}.lnk");
File.Delete(shortcutPath);
}
public static void CreateDesktopShortcut(string installPath, string fileName, DesktopShortcut desktopShortcut)
{
DeleteDesktopShortcut(desktopShortcut);
var shortcutPath = Path.Combine(GetAllUsersDesktopDirectory(), $"{desktopShortcut.Name}.lnk");
var mainFilePath = Path.Combine(installPath, fileName);
WshShell shell = new WshShell();
IWshShortcut shortcut = shell.CreateShortcut(shortcutPath) as IWshShortcut;
shortcut.Description = desktopShortcut.Name;
shortcut.WorkingDirectory = installPath;
shortcut.TargetPath = mainFilePath;
shortcut.Arguments = desktopShortcut.Arguments;
shortcut.IconLocation = mainFilePath;
shortcut.Save();
}
}
}