Pregunta

I have a 32 bit application that I want to register opening "explorer.exe" as a jump task. It works fine on 32 bit Windows 7, but in 64 bit Windows, it gives an error "C:\Windows\system32\explorer.exe Unspecified error".

Since Explorer's full path is "C:\Windows\SysWOW64\explorer.exe", I assume this is a result of Windows seeing the 32 bit emulated path at at run time, but the jump list needs the full 64 bit path. Is there a simple way to build this jumplist that will work on a 64 bit OS?

I guess I could do a check of Environment.Is64BitOperatingSystem and hardcode the location to "C:\Windows\SysWow64" if it's set, but I it's bad to be using hardcoded paths.

string exe = System.Reflection.Assembly.GetExecutingAssembly().Location;
string current = System.IO.Path.GetDirectoryName(exe);
var jl = new System.Windows.Shell.JumpList();
jl.ShowFrequentCategory = false;
jl.ShowRecentCategory = false;
jl.BeginInit();
jl.JumpItems.AddRange(new[]
    {
        new System.Windows.Shell.JumpTask
        {
            Title = "Explore",
            ApplicationPath = "explorer.exe",
            IconResourcePath = "explorer.exe",
            Arguments = "/select,\"" + exe,
            WorkingDirectory = current,
        },
        // other jump tasks here
    });
jl.EndInit();
jl.Apply();
¿Fue útil?

Solución

I found the answer here How to start a 64-bit process from a 32-bit process

The "sysnative" thing doesn't work in this scenario, but disabling filesystem redirection temporarily works:

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

    if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
        Wow64DisableWow64FsRedirection(ref ptr);
    try
    {
        // Add jump list code
    }
    finally
    {
        if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
            Wow64RevertWow64FsRedirection(ptr);
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top