1

I am using Visual Studio Clickones and try to execute (.appref-ms) application and using RedirectStandardOutput...

I have to use the option "Prefer 32-bit" because I am using Access DB with connection string as Provider=Microsoft.Jet.OLEDB.4.0.

This is my execution code :

    var p = new Process();
    p.StartInfo = new ProcessStartInfo(@"C:\Users\hed-b\Desktop\PulserTester.appref-ms")
    {
        RedirectStandardOutput = true,
        UseShellExecute = false
    };
    p.Start();
    reportNumber = p.StandardOutput.ReadToEnd();
    p.WaitForExit();

This is the error I have got

System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'

Editing

By look here, I see that I can run it by cmd

.Net Core 2.0 Process.Start throws "The specified executable is not a valid application for this OS platform"

as

var proc = Process.Start(@"cmd.exe ",@"/c C:\Users\hed-b\Desktop\PulserTester.appref-ms")

But How can I use RedirectStandardOutput this way?

Sahil Sharma
  • 1,813
  • 1
  • 16
  • 37
  • I think you can try this, ' ProcessStartInfo info = new ProcessStartInfo("cmd.exe"); info.Arguments = @"/c C:\Users\hed-b\Desktop\PulserTester.appref-ms"; set the info you need with your RedirectStandardOutput and then 'Process process = Process.Start(info) – S.Fragkos Jul 03 '18 at 11:27
  • You can't, redirecting I/O requires using ProcessStartInfo.UseShellExecute = false; And that prevents starting an appref-ms file. As long as you commit to the horror of hard-coding path names, you might as well go whole-hog and hardcode C:\Windows\System32\rundll32.exe C:\Windows\System32\dfshim.dll,ShOpenVerbShortcut,"yourpath.appref-ms". Not that this likely to work, rundll32.exe is not a console mode app so has nothing to redirect. ClickOnce is not your favorite deployment technique, unless you use it to deploy both executables. – Hans Passant Jul 03 '18 at 11:34

1 Answers1

3

Looks like you're intending to start CMD and run a command, but your code just tries to run that command as an application.

Try something like this.

    var p = new Process();
    p.StartInfo = new ProcessStartInfo(@"cmd.exe")
    {
        RedirectStandardOutput = true,
        UseShellExecute = false,
        Arguments = "/c C:\Users\hed-b\Desktop\PulserTester.appref-ms"
    };
    p.Start();
    reportNumber = p.StandardOutput.ReadToEnd();
    p.WaitForExit();

Using the blocking ReadToEnd will pause your thread while that code runs and makes it harder to capture error output also - Have a look at this answer for a demonstration of a non blocking solution that captures both standard data and standard err : ProcessInfo and RedirectStandardOutput

Sam
  • 1,208
  • 1
  • 9
  • 16
  • Thanks for answer.. I tried it the problem it this (.appref-ms) file its just the runner of my program (something of visual studio) and my real program does not wait on WaitForExit(); –  Jul 03 '18 at 11:30