Domanda

I’m recreating a Windows-Android Apk Installer (for my own use & educational purposes) This is a windows forms application and the functionality will be to: install, flash and control some things on my Android device.

The application contains several checkboxes that represent files "populated from a folder with filtered extention". These items (batch files) should run Command Prompt and the CMD output should be retrieved into the application textbox.

When several items are checked in CheckedListBox (or All Checked); I need the application to run all the selected batches with CMD.

Or for Installing Applications: i.e: "adb install ~\path to my apk folder\ checkedliastbox1.filename.apk"

These are the Codes i am trying to use; not working properly, ofcourse. What happens in both codes, is that it will open several cmd windows at the same time and it's not getting the checkedListbox1.selectedItems into the command prompt. In other words only show adb help.

Code #1

            private void btn_Install_Click(object sender, EventArgs e)
    {
        foreach (object itemChecked in checkedListBox1.CheckedItems)
        {
            Process.Start(@"C:\myfolder\programfiles\program.exe", "run " + checkedListBox1.SelectedItems);
        }
    }

Code #2

        private void btn_install_Click(object sender, EventArgs e)
    {
        foreach (object itemChecked in checkedListBox1.CheckedItems)
        {
            p.StartInfo.FileName = @"C:\RGDnamics\Android\adb\adb.exe";
            p.StartInfo.UseShellExecute = true;
            p.StartInfo.CreateNoWindow = false;
            p.StartInfo.Arguments = "install C:\\myFolder\\Android\\Backups\\Apk\\myapks\\" + itemChecked.ToString();
            p.Start();
            p.WaitForExit();
        }

Any idea what i might be doing wrong? Thanks in advance.

È stato utile?

Soluzione

You are passing the SelectedItems collection for each CheckedItem, instead of passing each of the current checked item.

Instead of:

Process.Start(@"C:\RGDnamics\programfiles\program.exe", "run "+checkedListBox1.SelectedItems);

use:

Process.Start(@"C:\RGDnamics\programfiles\program.exe", "run "+itemChecked.toString());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top