3

시작 메뉴 바로 가기를 기반으로 프로그램을 시작하려고합니다. 특히 시작 메뉴 바로 가기를 기반으로 파워 포인트를 시작하려고합니다. 이를 위해 IWshRuntimeLibrary를 사용하고 있습니다.C에서 시작 메뉴 바로 가기에서 파워 포인트를 시작할 수 없습니다.

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); 
} 

바로 가기를 찾고 IWshShortcut 개체를 만들 수 있습니다. 내가 바로 가기의 백업 응용 프로그램 실행 (Process.Start를 통해을 (shortcut.TargetPath, shortcut.Arguments))를 시도하지만 일단하는 Win32Exception가 발생합니다 내가 찾을 수

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: 

유일한 관련 대답이 discussion했다. 내 프로젝트는 이미 x86 응용 프로그램으로 구축 중이었습니다.

내 시스템에 대한 배경 정보가 나와 있습니다. Windows 7 Professional 64-Bit를 실행하고 Microsoft Office 2010을 설치했습니다. 이것은 .NET Framework 4 Client Profile을 대상으로 Visual Studio 2010으로 작성된 콘솔 응용 프로그램의 일부입니다.

나는 다음과 같은 대체 솔루션을 조사하는 과정에있어 : ​​

윈도우 API 코드 팩 : http://code.msdn.microsoft.com/WindowsAPICodePack
바로 가기 IWshRuntimeLibrary없는 : 합리적인 링크의 부족에 대한 How to resolve a .lnk in c#

죄송합니다. 그것은 내 첫 게시물이고 분명히 하나 이상의 태그를 사용하여 삽입 할 수 없습니다.

+0

'shortcut.TargetPath'의 내용을 출력 해 보았습니까? – mookid8000

+0

@ mookid8000 : 예제 코드에 포함시키는 것을 잊어 버렸습니다. 편집하겠습니다. 그 동안 내가 갖고있는 것은 다음과 같습니다. "C : \ Windows \ Installer \ {90140000-0011-0000-0000-0000000FF1CE} \ pptico.exe "를 입력하십시오. 나는 파워 포인트가 실제로 설치되고, 라이센스되고, 작동한다는 것을 알아야한다. – Josh

답변

2

이것은 단순히 작동합니다 :

당신은 LNK를 열 필요가 없습니다
Process.Start(shortcutPath); 

, 단지 그것을 실행 창을 부탁드립니다. 장면 뒤에서 Process.Start는 .lnk를 처리하는 방법을 알고있는 ShellExecute을 수행합니다.

+0

이것은 완벽하게 작동합니다. 평소와 같이 나는 일을 지나치게 복잡하게 만들었습니다. 감사. – Josh