This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/Installer/Shortcut.cs

124 lines
3.4 KiB
C#
Raw Normal View History

2019-11-11 15:48:49 +01:00
using System;
using System.Reflection;
2020-02-28 12:59:59 +01:00
using System.Runtime.InteropServices;
2019-11-11 15:48:49 +01:00
2020-03-16 15:53:14 +01:00
namespace Installer
2019-11-11 15:48:49 +01:00
{
2020-02-28 12:59:59 +01:00
internal static class Shortcut
2019-11-11 15:48:49 +01:00
{
2020-02-28 14:26:16 +01:00
private static readonly Type MType = Type.GetTypeFromProgID("WScript.Shell");
private static readonly object MShell = Activator.CreateInstance(MType);
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
public static void Make(string target, string fileName)
{
2020-02-28 14:26:16 +01:00
IWshShortcut shortcut = (IWshShortcut) MType.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod,
null, MShell, new object[] {fileName});
2019-11-11 15:48:49 +01:00
shortcut.TargetPath = target;
shortcut.Save();
}
2020-02-28 14:26:16 +01:00
[ComImport]
[TypeLibType(0x1040)]
[Guid("F935DC23-1CF0-11D0-ADB9-00C04FD58A0B")]
2019-11-11 15:48:49 +01:00
private interface IWshShortcut
{
[DispId(0)]
2020-02-28 14:26:16 +01:00
string FullName
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0)]
get;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3e8)]
2020-02-28 14:26:16 +01:00
string Arguments
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3e8)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3e8)]
set;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3e9)]
2020-02-28 14:26:16 +01:00
string Description
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3e9)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3e9)]
set;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3ea)]
2020-02-28 14:26:16 +01:00
string Hotkey
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ea)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ea)]
set;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3eb)]
2020-02-28 14:26:16 +01:00
string IconLocation
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3eb)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3eb)]
set;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3ec)]
2020-02-28 14:26:16 +01:00
string RelativePath
{
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ec)]
set;
}
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3ed)]
2020-02-28 14:26:16 +01:00
string TargetPath
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ed)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ed)]
set;
}
2020-02-28 12:59:59 +01:00
2020-02-28 14:26:16 +01:00
[DispId(0x3ee)] int WindowStyle { [DispId(0x3ee)] get; [param: In] [DispId(0x3ee)] set; }
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x3ef)]
2020-02-28 14:26:16 +01:00
string WorkingDirectory
{
[return: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ef)]
get;
[param: In]
[param: MarshalAs(UnmanagedType.BStr)]
[DispId(0x3ef)]
set;
}
2020-02-28 12:59:59 +01:00
2020-02-28 14:26:16 +01:00
[TypeLibFunc(0x40)]
[DispId(0x7d0)]
void Load([In] [MarshalAs(UnmanagedType.BStr)] string pathLink);
2020-02-28 12:59:59 +01:00
2019-11-11 15:48:49 +01:00
[DispId(0x7d1)]
void Save();
}
}
2020-02-28 12:59:59 +01:00
}