A fork of Eusth's IPA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Shortcut.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace IPA
  4. {
  5. public class Shortcut
  6. {
  7. private static Type m_type = Type.GetTypeFromProgID("WScript.Shell");
  8. private static object m_shell = Activator.CreateInstance(m_type);
  9. [ComImport, TypeLibType((short)0x1040), Guid("F935DC23-1CF0-11D0-ADB9-00C04FD58A0B")]
  10. private interface IWshShortcut
  11. {
  12. [DispId(0)]
  13. string FullName { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0)] get; }
  14. [DispId(0x3e8)]
  15. string Arguments { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3e8)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3e8)] set; }
  16. [DispId(0x3e9)]
  17. string Description { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3e9)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3e9)] set; }
  18. [DispId(0x3ea)]
  19. string Hotkey { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ea)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ea)] set; }
  20. [DispId(0x3eb)]
  21. string IconLocation { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3eb)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3eb)] set; }
  22. [DispId(0x3ec)]
  23. string RelativePath { [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ec)] set; }
  24. [DispId(0x3ed)]
  25. string TargetPath { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ed)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ed)] set; }
  26. [DispId(0x3ee)]
  27. int WindowStyle { [DispId(0x3ee)] get; [param: In] [DispId(0x3ee)] set; }
  28. [DispId(0x3ef)]
  29. string WorkingDirectory { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ef)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ef)] set; }
  30. [TypeLibFunc((short)0x40), DispId(0x7d0)]
  31. void Load([In, MarshalAs(UnmanagedType.BStr)] string PathLink);
  32. [DispId(0x7d1)]
  33. void Save();
  34. }
  35. public static void Create(string fileName, string targetPath, string arguments, string workingDirectory, string description, string hotkey, string iconPath)
  36. {
  37. IWshShortcut shortcut = (IWshShortcut)m_type.InvokeMember("CreateShortcut", System.Reflection.BindingFlags.InvokeMethod, null, m_shell, new object[] { fileName });
  38. shortcut.Description = description;
  39. shortcut.Hotkey = hotkey;
  40. shortcut.TargetPath = targetPath;
  41. shortcut.WorkingDirectory = workingDirectory;
  42. shortcut.Arguments = arguments;
  43. if (!string.IsNullOrEmpty(iconPath))
  44. shortcut.IconLocation = iconPath;
  45. shortcut.Save();
  46. }
  47. }
  48. }