c# how can you open a exe file and auto check a checkbox inside a installer.

mion shion 241 Reputation points
2022-11-13T11:59:09.357+00:00

good morning all,

i have a question that i have no idea how to do,

i want to start a exe in c# and attach to the process of the exe and auto check a certin box so for example

load up python install

and attach to the proccess and auto select

259830-screenshot-2022-11-13-115642.png

so for example load this up with process.start(file.exe)
then when it loads up to auto check the checkbox in question

is that possible to do in c# ?

any help would be much apprieated
kind regards,
elfenliedtopfan5

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2022-11-13T12:40:29.017+00:00

    You can use a WH_CBT hook to detect the window or FindWindow, then check the control
    For example with FindWindow, test on a button click (change the location of python-3.11.0-amd64.exe) :

    (remove space at S leep (editor bug))

        public partial class Form1 : Form  
        {  
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]  
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  
      
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]  
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);  
      
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]  
            public static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);  
      
            public const int BM_GETCHECK = 0x00F0;  
            public const int BM_SETCHECK = 0x00F1;  
      
            public const int BST_UNCHECKED = 0x0000;  
            public const int BST_CHECKED = 0x0001;  
      
            public Form1()  
            {  
                InitializeComponent();  
            }  
      
            private Thread workerThread = null;  
            private readonly AutoResetEvent isCanceled = new AutoResetEvent(false);  
      
            private void WorkerThread()  
            {  
                for (; !isCanceled.WaitOne(0);)  
                {  
                    IntPtr hWnd = FindWindow("PythonBA", null);  
                    if (hWnd != IntPtr.Zero)  
                    {  
                        IntPtr hWndCheckBox = FindWindowEx(hWnd, IntPtr.Zero, "Button", "Add &python.exe to PATH");  
                        if (hWndCheckBox != IntPtr.Zero)  
                        {  
                            // To not send the message too early...  
                            Thread.S leep(200);  
                            SendMessage(hWndCheckBox, BM_SETCHECK, BST_CHECKED, IntPtr.Zero);  
                            isCanceled.Set();  
                        }  
                    }    
                    Thread.S leep(10);  
                }  
            }  
      
            private void button1_Click(object sender, EventArgs e)  
            {  
                workerThread = new Thread(new ThreadStart(this.WorkerThread));  
                workerThread.Start();  
                using (Process p = new Process())  
                {  
                    p.StartInfo.FileName = "E:\\temp\\python-3.11.0-amd64.exe";                 
                    p.Start();  
                }  
            }  
        }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.