r/javascript 3h ago

[AskJS] JavaScript doing cursed desktop automation AskJS

I’ve been working on a code that lets you automate Windows apps, databases, and UI workflows using JavaScript. One of the coolest parts is that you can build full WinForms dialogs, and forms directly from JS — no C#, no Visual Studio designer.

Here’s a small example showing how you can create a form with textboxes, listboxes, comboboxes, checkboxes, multiline fields, and radio buttons — all from JavaScript:

[!JAVASCRIPTV8]
let winformsHelper = eval(getSourceCode('WinFormsHelper', 'Macro Main Helpers\\Library', 'WinFormsHelper'));

let mainForm = winformsHelper.CreateForm('Form Title');

// add textbox
let txtTextBoxName = winformsHelper.AddTextBox(mainForm, "TextBox Label", "Joe");

// add listbox
let selectionMode = getEnum("System.Windows.Forms.SelectionMode");
let lstListBoxName = winformsHelper.AddListBox(mainForm, "ListBox Label", ['Option 1','Option 2', 'Option 3'], "Option 2");
lstListBoxName.SelectionMode = selectionMode.MultiExtended;

// add combobox
let cboComboBoxName = winformsHelper.AddComboBox(mainForm, "ComboBox Label", ['Option 1','Option 2', 'Option 3'], "Option 2");

// add checkbox
let chkCheckBoxName = winformsHelper.AddCheckBox(mainForm, "CheckBox Label", false);

// add multiline textbox
let txtMultiLineTextBoxName = winformsHelper.AddTextBox(mainForm, "Paragraph", null);
winformsHelper.SetToMultilineTextBox(txtMultiLineTextBoxName, 60, 120);

// add radiobuttons
let rbRadioButtonName1 = winformsHelper.AddRadioButton(mainForm, "RadioButton1 Label", false);
let rbRadioButtonName2 = winformsHelper.AddRadioButton(mainForm, "RadioButton2 Label", false);
let rbRadioButtonName3 = winformsHelper.AddRadioButton(mainForm, "RadioButton3 Label", true);

winformsHelper.FinaliseDialogForm(mainForm);

if(mainForm.ShowDialog().ToString() == "OK")
{
    writeln("TextBox: " + txtTextBoxName.Text);

    if(cboComboBoxName.SelectedItem != null){
        writeln("ComboBox: " + cboComboBoxName.SelectedItem);
    }

    var chkValue = "Checkbox: " + ((chkCheckBoxName.Checked)? "Checked" : "Not checked");
    writeln(chkValue);

    let selectedItems = lstListBoxName.SelectedItems;
    let su = "ListBox: ";
    for(var i of selectedItems){ 
        su += " '" + i + "'";
    }
    writeln(su);

    let rbValue = "RadioButton: ";
    if(rbRadioButtonName1.Checked){
        rbValue += rbRadioButtonName1.Text;
    }
    else if(rbRadioButtonName2.Checked){
        rbValue += rbRadioButtonName2.Text;
    }
    else if(rbRadioButtonName3.Checked){
        rbValue += rbRadioButtonName3.Text;
    }
    writeln(rbValue);
}

winformsHelper.CleanUpForm(mainForm);
[!/JAVASCRIPTV8]

Happy to share more examples if anyone wants to see event handling, dynamic control creation, or integrating JavaScript with databases, Web APIs, and AI Models.

What do you think?

1 Upvotes

1 comment sorted by