Opening a pop up window for multiple choices?
<# :^ Starting bat script and PowerShell comment
@echo off && cd /d "%~dp0" & color 0a
echo & setlocal EnableDelayedExpansion
title Batch files and Powershell hybrids
%__AppDir__%mode.com con:cols=080lines=009
echo. & echo. hybrid .cmd/.bat ^& ps1
echo\=====================================
for /f usebackq^tokens^=*delims^= %%i in (`
set "_=0" ^& type "%~f0"^|powershell.exe -nOp -c -
`)do 2>&1 (if "%%~i" == "[ Error 1 ]" (goto %:^|
)else if "%%~i" == "[ Error 2 ]" (goto %:^O
)else if "%%~i" == "[ Error 3 ]" (goto %:^V
)else if "%%~i" == "[ Error 4 ]" (goto %:^?
)else set/a "_+=1" && call %:^) !_! "%%~i")
if !_! equ 0 goto %:^?
endlocal & %__AppDir__%timeout.exe 01 | (
echo/- The job is done!) & goto :eof
%:^|
endlocal & %__AppDir__%timeout.exe 01 | (
echo/- Canceled by user!) & goto :eof
%:^?
endlocal & %__AppDir__%timeout.exe 01 | (
echo/- Timeout reached!) & goto :eof
%:^)
rem. :: & %__AppDir__%timeout.exe 01 | (
echo\Clicked Itens #%~1: "%~2") & exit /b
%:^O
endlocal & %__AppDir__%timeout.exe 01 | (
echo\Nothing selected by user) & goto :eof
%:^V
endlocal & %__AppDir__%timeout.exe 01 | (
echo\#Error: no \subfolders) & goto :eof
:: End Bat Session and Starting PowerShell Script >" ::
#>
function SourceDirectory ([string]$Message,
[string]$work_dir, [switch]$NoNewFolderButton )
{
$browseForFolderOptions = 0
$browseForFolderOptions += 512
$app = New-Object -ComObject Shell.Application
$folder = $app.BrowseForFolder(0, $Message, $browseForFolderOptions, $work_dir)
if ($folder) { $selectedDirectory = $folder.Self.Path } else { $selectedDirectory = '' }
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($app) > $null
return $selectedDirectory
}
$work_dir = Push-Location $PSScriptRoot
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Select Folders use Control'
$form.Size = New-Object System.Drawing.Size(330,200)
$form.StartPosition = 'CenterScreen'
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(560,20)
$label.Text = 'Please make a selection from the list below:'
$form.Controls.Add($label)
$Global:timer = New-Object System.Windows.Forms.Timer
$Global:EndDate = ((Get-Date).AddSeconds(+10)).ToString("mmss")
$Global:timer.Add_Tick({ if ($EndDate -lt (Get-Date).ToString("mmss")) {
$timer.Stop(); $form.Close(); Write-Host '[ Error 4 ]'}})
$listBox = New-Object System.Windows.Forms.Listbox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.SelectionMode = 'MultiExtended'
[void] $listBox.Items.Remove('Item *')
if ((ls -ad $work_dir).count -eq 0){'[ Error 3 ]'; break
} else { ls -ad $work_dir | ? {[void] $listBox.Items.Add($_) } }
$listBox.Height = 70
$form.Controls.Add($listBox)
$form.Topmost = $true;
$timer.Start(); $result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::Cancel) {'[ Error 1 ]' ; break}
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
if ($listBox.SelectedItems.Count -gt 0) { (resolve-path($listBox.SelectedItems) |
select -ExpandProperty Path )| % { $_ } } else {'[ Error 2 ]'; break} }
Pop-Location ; exit
You can use hybrid bat with powershell, and with some searching on the examples available on the internet.
You can quickly adapt it so that it best suits your goal, a lot and take advantage of the resulting learning and consider migrating to powershell.
Below is an example using a script I made a few months ago to get a folder listing by multiple selection/click and which I adapted by adding output to following actions by the user:
- Selected items
- Unselected item
- Cancel click/close
- Timeout 10 seconds // if no actions
- Start-CountDownTimer.ps1
- Multiple selection list boxes
- Cancel button in a powershell script
- An A-Z Index of Windows PowerShell commands
- How to add a timer in ps1 to quit the form after certain amount of time
Although there might be no "direct way", there are several work arounds e.g. doing a time out
of the main script while a second script is doing the user query. The second script can for example write it's result into a file (or not, if it is ignored). After the time out the first script continues with evaluating the result (or cancelling the second script if it was ignored).
That all depends on the type of command terminal you want to use for the batch file e.g. powershell, cmd, or some other. Here are a few examples:
Here is how to add a time out in cmd
Here is how to add a time out in a powershell