Pregunta

Estoy tratando de iniciar un programa basado en un acceso directo del menú de inicio. En particular, estoy tratando de PowerPoint lanzamiento basado en el acceso directo del menú de inicio. Para lograr esto, estoy usando el IWshRuntimeLibrary.

static void Main(string[] args)
{
    string searchTerm = "powerpoint";

    string startMenu = Environment
        .GetFolderPath(Environment.SpecialFolder.CommonStartMenu);

    string shortcutPath = Directory
        .GetFiles(startMenu, "*.lnk", SearchOption.AllDirectories)
        .OrderBy(p => p.Length)
        .First(p => p.ToLower().Contains(searchTerm));

    WshShell shell = new WshShell();

    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);

    Console.WriteLine(shortcut.TargetPath); //prints: C:\Windows\Installer\{90140000-0011-0000-0000-0000000FF1CE}\pptico.exe

    Process.Start(shortcut.TargetPath, shortcut.Arguments);
}

Soy capaz de encontrar con éxito el acceso directo, así como crear un objeto IWshShortcut. Sin embargo, una vez que intento para ejecutar la aplicación respaldo del acceso directo (a través de Process.Start (shortcut.TargetPath, shortcut.Arguments)), un Win32Exception se produce:

System.ComponentModel.Win32Exception was unhandled
  Message=The specified executable is not a valid application for this OS platform.
  Source=System
  ErrorCode=-2147467259
  NativeErrorCode=193
  StackTrace:
       at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
       at System.Diagnostics.Process.Start()
       at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
       at System.Diagnostics.Process.Start(String fileName, String arguments)
       at Scratch.Program.Main(String[] args) in C:\Users\jhampton\Documents\Visual Studio 2010\Projects\Scratch\Scratch\Program.cs:line 26
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

La respuesta sólo relacionada que pude encontrar fue en este discusión . Mi proyecto ya se estaba construyendo como una aplicación X 86

Ya que parece relevante, aquí hay algunos antecedentes en mi sistema. Estoy corriendo Windows 7 Professional de 64 bits, y ha instalado Microsoft Office 2010. Esto es parte de una aplicación de consola escrita en Visual Studio 2010, dirigido a .NET Framework 4 Client Profile.

Estoy en el proceso de investigación de las siguientes soluciones alternativas:

La API Código Pack de Windows: http://code.msdn.microsoft.com/WindowsAPICodePack
Los accesos directos sin IWshRuntimeLibrary: de cómo resolver un .lnk en C #

Lo siento por la falta de enlaces sensibles. Es mi primer post y, aparentemente, no puede insertar más de uno con una etiquetas.

¿Fue útil?

Solución

Esto debería simplemente trabajo:

Process.Start(shortcutPath);

no es necesario abrir el LNK, sólo hay que preguntar ventanas para ejecutarlo. Detrás de la escena, Process.Start hará un ShellExecute que sabe cómo procesar un .lnk.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top