We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

kerenor
Posts: 13
Joined: Mon Mar 20, 2023 3:32 pm

Error starting a new process from the main app

Hi,

This is most likely an MSIX question and not an Advanced Installer question, but regardless I'd appreciate your help.


I have a c# app that needs to start a new process that runs a .bat file. This fails with the error

Code: Select all

Unable to start C:\Program Files\WindowsApps\App.E_1.0.0.67_x64__5c1j8dm4w74ew\utils\runtime_analyzer.bat. Exception received: System.ComponentModel.Win32Exception (1726): The remote procedure call failed.
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Worker.ExecuteAsync(CancellationToken stoppingToken)


I opened PowerShell in that MSIX app using Hover (many thanks!) to see if I can run the batch file from there and saw that directly running the batch file works:

Code: Select all

PS C:\Program Files\WindowsApps\App.E_1.0.0.67_x64__5c1j8dm4w74ew> .\utils\runtime_analyzer.bat
 [... does whatever it needs to do, but in this process]

But indeed starting a new process doesn't:

Code: Select all

PS C:\Program Files\WindowsApps\App.E_1.0.0.67_x64__5c1j8dm4w74ew> Start-Process .\utils\runtime_analyzer.bat
Start-Process : This command cannot be run due to the error: The remote procedure call failed.
At line:1 char:1
+ Start-Process  .\utils\runtime_analyzer.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Needless to say, outside of MSIX context starting a new process does work.

Would appreciate any ideas on what am I doing wrong and how to start a new process from a batch file inside MSIX (Starting new exe processes is possible, from other tests done)

Many thanks!
Keren
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Error starting a new process from the main app

Hello Keren,

That might be a MSIX limitation, as you do not have access from your MSIX app outside of the container - due to security reasons.

If possible, please allow me some more time to discuss this with our colleagues and I will followup on this thread as soon as I will have more information.

Thank you for your patience!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Error starting a new process from the main app

Hello Keren,

So I've been testing this and it looks like this works just fine.

Here would be the C# code that launches the batch file:

Code: Select all

    class Program
    {
        static void Main(string[] args)
        {
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = @"C:\Users\Catalin\Desktop\hello.bat";
            psi.CreateNoWindow = false;
            psi.WindowStyle = ProcessWindowStyle.Normal;

            Process p = Process.Start(psi);
            p.WaitForExit();
        }
    }
After I install the MSIX and the application is launched (launchbat.exe), the BAT file is executed as expected.
Screenshot_104.png
Screenshot_104.png (95.87 KiB) Viewed 12072 times

Could you please make sure your MSIX has the "FullTrust" capability? You can check this in "Capabilities" page.
Screenshot_105.png
Screenshot_105.png (56.46 KiB) Viewed 12072 times


Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kerenor
Posts: 13
Joined: Mon Mar 20, 2023 3:32 pm

Re: Error starting a new process from the main app

This is interesting, thanks Catalin for your response!
My package indeed has fullTrust capability, and in fact we have very similar c# code, but in our case it also sets the ProcessStartInfo to use shell execution, like so

Code: Select all

            psi.UseShellExecute = true;

Perhaps that is the cause of this behavior. If I have time I will try it without that and tell you if it works.
Do you know if perhaps that is some limitation with MSIX apps? (this flag differentiates between starting a process with ShellExecute vs CreateProcess)

Thanks

Keren
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Error starting a new process from the main app

You are always welcome, Keren!
Perhaps that is the cause of this behavior. If I have time I will try it without that and tell you if it works.

Do you know if perhaps that is some limitation with MSIX apps? (this flag differentiates between starting a process with ShellExecute vs CreateProcess)
To be fully honest with you, I am not quite familiar with that so I can not say for sure whether it is the cause of this or not.

Please keep me updated if this works without that line added.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kerenor
Posts: 13
Joined: Mon Mar 20, 2023 3:32 pm

Re: Error starting a new process from the main app

Thanks for your support

just updating that it indeed runs without ShellExecute. Interesting!
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Error starting a new process from the main app

Thank you for your followup on this!

That is quite interesting, indeed.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”