In c# can I write code to run a Windows 11 shortcut link programmatically?

Paddy Patterson 21 Reputation points
2022-01-22T11:07:09.983+00:00

For a Windows 10 shortcut lnk, I could use Shell32.ShellLinkObject.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,239 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,163 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 81,721 Reputation points
    2022-01-22T12:14:38.14+00:00

    I don't have Windows 11, but it would be weird if a simple Process.Start did not work anymore.
    A test on Windows 10 with a TestNotepadLink.lnk to Notepad on Desktop

                string sDestPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string sLink = "TestNotepadLink.lnk";
                string sShortcut = sDestPath + "\\" + sLink;
                using (Process p = new Process())
                {
                    p.StartInfo.FileName = sShortcut;
                    p.Start();
                }
    

  2. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2022-01-25T08:28:21.787+00:00

    @Paddy Patterson , based on my research, I find a new method to run a shortcut link in windows 11.

    Here is a code example you could refer to.

     internal class Program  
        {  
            public enum ShowWindowCommands : int  
            {  
      
                SW_HIDE = 0,  
                SW_SHOWNORMAL = 1,      
                SW_NORMAL = 1,  
                SW_SHOWMINIMIZED = 2,  
                SW_SHOWMAXIMIZED = 3,  
                SW_MAXIMIZE = 3,  
                SW_SHOWNOACTIVATE = 4,  
                SW_SHOW = 5,  
                SW_MINIMIZE = 6,  
                SW_SHOWMINNOACTIVE = 7,  
                SW_SHOWNA = 8,  
                SW_RESTORE = 9,  
                SW_SHOWDEFAULT = 10,  
                SW_MAX = 10  
            }  
            [DllImport("shell32.dll")]  
            public static extern IntPtr ShellExecute(  
                IntPtr hwnd,  
                string lpszOp,  
                string lpszFile,  
                string lpszParams,  
                string lpszDir,  
                ShowWindowCommands FsShowCmd  
            );  
            static void Main(string[] args)  
            {  
                  
                string sLink = "1 - Shortcut";  
                ShellExecute(IntPtr.Zero, "open", sLink, null, null, ShowWindowCommands.SW_SHOWMAXIMIZED);  
            }  
        }  
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments