Custom box values

Hello,

I want to know please how can i make a “start-process” button receive values that entered in a separate custom box.

i have this short script:

#add text box
$textBox_IP = New-Object System.Windows.Forms.TextBox
$textBox_ip.Location = New-Object System.Drawing.Point(75,10)
$textBox_ip.Size = New-Object System.Drawing.Size(189,20)
$form_RemoteControl.Controls.Add($textBox_ip)

# add Start button
$button_start = New-Object System.Windows.Forms.Button
$button_start.Location = New-Object System.Drawing.Size(25,70)
$button_start.Size = New-Object System.Drawing.Size(240,32)
$button_start.TextAlign = "MiddleCenter"
$button_start.Text = "Start"
$button_start.Add_Click({
$button_start.Text = "Start"
Start-Process -FilePath "C:\Users\userbame\Desktop\software\software.exe" -verb RunAs
})
$Form_remoteControl.Controls.Add($button_start)

the output of that .exe is:

software.exe <address> [\site server name]

 

so i want that the IP that i will enter in the custom box will be the <address>

TNX

Pass the -ArgumentList parameter to Start-Process to supply command line arguments. You may need to explicitly scope your variables to ensure the delegate the handles the click event has access to the variable, as they commonly run in other scopes, e.g., $script:Arguments

sorry, i don’t think i understood.

the change should br in this line:?

Start-Process -FilePath “C:\Users\userbame\Desktop\software\software.exe” -verb RunAs

Start-Process -FilePath "C:\Users\userbame\Desktop\software\software.exe" -verb RunAs -ArgumentList "$Arg1","$Arg2", etc...

Be sure to read the help files to fully understand the cmdlet use case, params, and switches.

# get function / cmdlet details
(Get-Command -Name Start-Process).Parameters.Keys
Get-help -Name Start-Process -Full
Get-help -Name Start-Process -Online
Get-help -Name Start-Process -Examples

<#
 Get-help -Name Start-Process -Full
...
    

PARAMETERS
    -ArgumentList <String[]>
        Specifies parameters or parameter values to use when this cmdlet starts the process.
        
        Required?                    false
        Position?                    1
        Default value                None
        Accept pipeline input?       False
        Accept wildcard characters?  false
        
...
#>

i have this until now:

#add text box
$textBox_IP = New-Object System.Windows.Forms.TextBox
$textBox_ip.Location = New-Object System.Drawing.Point(75,10)
$textBox_ip.Size = New-Object System.Drawing.Size(189,20)
$form_RemoteControl.Controls.Add($textBox_ip)

# add Start button
$button_start = New-Object System.Windows.Forms.Button
$button_start.Location = New-Object System.Drawing.Size(25,70)
$button_start.Size = New-Object System.Drawing.Size(240,32)
$button_start.TextAlign = "MiddleCenter"
$button_start.Text = "Start"
$button_start.Add_Click({
$button_start.Text = "Start"
Start-Process -FilePath "C:\Users\username\Desktop\SCCM_RC\CmRcViewer.exe" -verb RunAs -ArgumentList # ??????????
})
$Form_remoteControl.Controls.Add($button_start)

i need that every IP address i will enter in the textBox_ip will be the address to remote on.

$textBox_ip.text

Always read the documentation wh=en playing with something for the first time.

btwn, please read the guide on how to format the code when posting in this forum, it’ll be at the top of text box additionally you can refer below gif.