Hi, the following steps work for my project even if I restart the Revit app and open in different files,
Firstly, import these functionalities:
[DllImport("user32.dll")]
private static extern IntPtr GetWindow(IntPtr hwndParent, uint uCmd);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);
then check the structures of handles from the Revit App - current File to the Finish Button as jlpgy mentioned:

for example in the ui of Revit 2024:
1. get the main app handle via FindWindow() or simply using the function RevitAPI provided
2. get the control bar handle via FindWindowEX()
3. get the first dialog handle via FindWindowEX() or GetWindow()
4. repeatedly get the dialog handle via GetWindow() until there's a child handle matches the target button
finally use SendMessage() to send BM_CLICK message
according to the document of GetWindow() method
type 5 == GW_CHILD type 2 == GW_HWNDNEXT
pinvoke.net: GetWindow (user32)