Reputation: 11
I am launching msEdge via kernal32.CreateProcess, the process launches but when I try to interact with the initial process it has exited and a new process is running. I have coded to deal with this but I have code in the wild that is affected by this new behavior and fails to interact with the process as it looks like its exited...
This behaviour first appeared in msEdge update 89.0.774.57 but a colleague has seen it happening after downgrading to 86.0.622.56
Looking for help in how to stop msEdge from starting in this way, I assume its some config option I'm missing...
Sample code (appologies for the VB!):
Sub Main()
Dim processInfo As PROCESS_INFORMATION
Dim creationFlags As Integer = CreationFlagsLocal.NORMAL_PRIORITY_CLASS Or CreationFlagsLocal.DETACHED_PROCESS
Dim startupInfo As STARTUPINFO = New STARTUPINFO
startupInfo.cb = Marshal.SizeOf(startupInfo)
Dim path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
CreateProcess(Nothing, path, Nothing, Nothing, False, creationFlags, IntPtr.Zero, Nothing, startupInfo, processInfo)
Console.WriteLine("The processID from CreateProcess was: " & processInfo.dwProcessId)
Thread.Sleep(2000)
Console.WriteLine("GetRunningEdgeProcessID() returns " & GetRunningEdgeProcessID())
Dim originalPidExists = Process.GetProcesses().Any(Function(x) x.Id = processInfo.dwProcessId)
Console.WriteLine($"PID {processInfo.dwProcessId} still exists? {originalPidExists}")
End Sub
Code that gets the running process after the initial process exits:
Function GetRunningEdgeProcessID() As Integer
Dim edgeProcesses = Process.GetProcessesByName("msedge")
Dim mainProcess = edgeProcesses.FirstOrDefault(Function(x) Not String.IsNullOrEmpty(x.MainWindowTitle))
If mainProcess IsNot Nothing Then Return mainProcess.Id
Return -1
End Function
Import of CreateProcess:
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)>
Function CreateProcess(ByVal lpApplicationName As String,
ByVal lpCommandLine As String, ByRef lpProcessAttributes As SECURITY_ATTRIBUTES,
ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Boolean,
ByVal dwCreationFlags As Integer, ByVal lpEnvironment As IntPtr, ByVal lpCurrentDirectory As String,
<[In]()> ByRef lpStartupInfo As STARTUPINFO,
<[Out]()> ByRef lpProcessInformation As PROCESS_INFORMATION) As Boolean
End Function
Upvotes: 1
Views: 629
Reputation: 11
It turns out that the process that was launching msEdge was elevated and edge does not want to run elevated, so it relaunches itself in the normal user context. There is a flag that allows edge to run in elevated mode that resolves the original issue.
Also, the issue can be caused by use of the Start-Up Boost feature that MS has recently remote disabled as it was causing issues like this edge://flags#edge-de-elevate-on-launch
Further reading: https://winaero.com/microsoft-edge-now-de-elevates-itself-automatically/
Upvotes: 0