title: How can I launch programmatically (C++) an application from a Windows shortcut (.lnk file)?
body: <p>how can I launch programmatically an application from a Windows shortcut (.lnk file)?</p>
  
  <p>I tried to use the API ShellExecute and it seems to work. Any caveat?</p>
  
  <p>Thank you.</p>
  
  <p>Here it is a snippet of my current code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  #include &lt;map&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  int main( int, char** )
  {
     std::map&lt; int, std::wstring &gt; errors;
     errors[0]                      = L"The operating system is out of memory or resources.";
     errors[ERROR_FILE_NOT_FOUND]   = L"The specified file was not found."; 
     errors[ERROR_PATH_NOT_FOUND]   = L"The specified path was not found."; 
     errors[ERROR_BAD_FORMAT]       = L"The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image).";
     errors[SE_ERR_ACCESSDENIED]    = L"The operating system denied access to the specified file.";
     errors[SE_ERR_ASSOCINCOMPLETE] = L"The file name association is incomplete or invalid.";
     errors[SE_ERR_DDEBUSY]         = L"The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.";
     errors[SE_ERR_DDEFAIL]         = L"The DDE transaction failed.";
     errors[SE_ERR_DDETIMEOUT]      = L"The DDE transaction could not be completed because the request timed out.";
     errors[SE_ERR_DLLNOTFOUND]     = L"The specified DLL was not found.";
     errors[SE_ERR_FNF]             = L"The specified file was not found.";
     errors[SE_ERR_NOASSOC]         = L"There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.";
     errors[SE_ERR_OOM]             = L"There was not enough memory to complete the operation.";
     errors[SE_ERR_PNF]             = L"The specified path was not found.";
     errors[SE_ERR_SHARE]           = L"A sharing violation occurred.";
  
     int ret = reinterpret_cast&lt; int &gt;( ::ShellExecute(0,L"open",L"\"C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Accessories\\Calculator.lnk\"",0,0,SW_SHOW) );
     const int minimumRetOK = 33;
     if ( ret &lt; minimumRetOK ) {
        if ( errors.count( ret ) ) {
           std::wcout &lt;&lt; L"Error " &lt;&lt; ret &lt;&lt; L" " &lt;&lt; errors[ ret ];
        } else {
           std::wcout &lt;&lt; L"Error " &lt;&lt; ret &lt;&lt; L" undocumented error";
        }
     }
  
      return 0;
  }
  </code></pre>