Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find process with id #606

Open
BlueprismWorld opened this issue Dec 23, 2023 · 4 comments
Open

Could not find process with id #606

BlueprismWorld opened this issue Dec 23, 2023 · 4 comments

Comments

@BlueprismWorld
Copy link

BlueprismWorld commented Dec 23, 2023

Always throwing an exception GetMainWindow Could not find process with id

 string procName = @"C:\\Windows\\System32\\notepad.exe";
 var app = FlaUI.Core.Application.Launch(procName);
 using (var automation = new UIA3Automation())
 {
     var window = Retry.WhileNull(() =>
         app.GetMainWindow(automation),
         TimeSpan.FromSeconds(10)
     ).Result;     
     MessageBox.Show(window.Title);
 }
@SilverSockSound
Copy link

I was having the same issue. I found a workaround that is not pretty but it works. For some reason when you Launch notepad, because it is a windows store app, it gets the wrong process ID. I tried using .LaunchStoreApp() using the AUMID but that didn't work either.

So the solution I found was:

FlaUI.Core.Application.Launch("notepad.exe");
Thread.Sleep(500);
var application = FlaUI.Core.Application.Attach("notepad.exe");
var automation = new UIA3Automation();
var mainWindow = application.GetMainWindow(automation);

Could probably reduce the sleep.

This probably won't work if you have multiple instances of the application running.

@Roemer
Copy link
Member

Roemer commented Mar 8, 2024

Which Windows Version are you on? On Win10 your code should work, on Win 11 the problem is indeed that it is a Windows Store APP which you need to handle differently.

@SilverSockSound
Copy link

I am indeed on Windows 11.

How would it be best handled in Win 11? I tried using .LaunchStoreApp() but ran into the same error as using .Launch().

@warrenkc
Copy link

warrenkc commented May 22, 2024

I can launch notepad in Windows 11 using this code:
var app = FlaUI.Core.Application.LaunchStoreApp("Microsoft.WindowsNotepad_8wekyb3d8bbwe!App");

I found the app id using PowerShell. But I can't seem to proceed to control notepad.
Using PowerShell
Open PowerShell: Press Win + X and select Windows PowerShell (Admin).

Get-StartApps | Format-Table -Property Name, AppID

This command lists all installed apps along with their AppID, which is the appUserModelId.

So this code should work but it doesn't. It seems to work with other windows store apps.

var app = FlaUI.Core.Application.LaunchStoreApp("Microsoft.WindowsNotepad_8wekyb3d8bbwe!App");

 using (var automation = new UIA3Automation())
 {
     var window = Retry.WhileNull(() =>
         app.GetMainWindow(automation),
         TimeSpan.FromSeconds(10)
     ).Result;
     Console.WriteLine(window.Title);
 }

For example this works:

string appId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";
var app = FlaUI.Core.Application.LaunchStoreApp(appId);

using (var automation = new UIA3Automation())
{
    var window = Retry.WhileNull(() =>
        app.GetMainWindow(automation),
        TimeSpan.FromSeconds(10)
    ).Result;
    Console.WriteLine(window.Title);
}

return;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants