打开一个弹出窗口进行多项选择?

打开一个弹出窗口进行多项选择?

我正在编写一个batch脚本,该脚本运行视频播放列表,逐个打开它们,并要求在视频之间执行操作。有没有办法打开一个弹出窗口以供多个选择?如果不采取任何操作,此弹出窗口应在几秒钟内关闭,以便播放列表可以继续。没有原生的 Microsoft 命令行工具可以做到这一点,正在寻找解决方法。

答案1

在此处输入图片描述

<# :^ 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

在此处输入图片描述


您可以使用混合球棒,并在互联网上搜索了一些可用的例子。

你可以快速调整它,以便它最适合你的目标,并利用由此产生的学习,并考虑迁移到

下面是一个示例,使用我几个月前编写的脚本,通过多次选择/单击获取文件夹列表,并通过在用户执行以下操作时添加输出对其进行了调整:

  • 已选商品
  • 未選擇項目
  • 取消点击/关闭
  • 如果没有操作,则超时 10 秒

在此处输入图片描述


答案2

尽管可能没有“直接方法”,但有几种解决方法,例如,time out在第二个脚本执行用户查询的同时执行主脚本。例如,第二个脚本可以将其结果写入文件(如果被忽略,则不写入)。超时后,第一个脚本继续评估结果(如果被忽略,则取消第二个脚本)。

这完全取决于您要用于批处理文件的命令终端的类型,例如 powershell、cmd 或其他。以下是几个示例:

  • 这是如何在 cmd 中添加超时

  • 这是如何在 powershell 中添加超时

相关内容