rinodrops

Get shortcut path of the C# application

Nov 19th, 2018
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.InteropServices; // added for DllImport
  7.  
  8.  
  9. namespace ConsoleApp1
  10. {
  11.     // definition of STARTUPINFO structure
  12.     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  13.     public struct STARTUPINFO
  14.     {
  15.         public uint cb;
  16.         public string lpReserved;
  17.         public string lpDesktop;
  18.         public string lpTitle;
  19.         public uint dwX;
  20.         public uint dwY;
  21.         public uint dwXSize;
  22.         public uint dwYSize;
  23.         public uint dwXCountChars;
  24.         public uint dwYCountChars;
  25.         public uint dwFillAttribute;
  26.         public uint dwFlags;
  27.         public ushort wShowWindow;
  28.         public ushort cbReserved2;
  29.         public IntPtr lpReserved2;
  30.         public IntPtr hStdInput;
  31.         public IntPtr hStdOutput;
  32.         public IntPtr hStdError;
  33.     }
  34.  
  35.     class Program
  36.     {
  37.         // Import
  38.         [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "GetStartupInfoA")]
  39.         public static extern void GetStartupInfo(out STARTUPINFO lpStartupInfo);
  40.  
  41.         static void Main(string[] args)
  42.         {
  43.             STARTUPINFO sui;
  44.             sui.dwFlags = 0x00000800; // STARTF_TITLEISLINKNAME
  45.             GetStartupInfo(out sui);
  46.             System.Console.Write(sui.lpTitle);
  47.             System.Console.ReadLine();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment