How to add filter to a file chooser in batch?

前端 未结 3 1275
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 12:34

I\'m using this code to create a file chooser with batch File / folder chooser dialog from a Windows batch script

@echo off
set dialog=\"about:

        
3条回答
  •  渐次进展
    2021-01-16 13:14

    I found another solution in vbscript posted here :

    The absolute ultimate Browse for file dialog (w95 to w8) with start folder and filters

    Function GetFileDlgEx(sIniDir,sFilter,sTitle) 
     Set oDlg = CreateObject("WScript.Shell").Exec("mshta.exe ""about:""") 
     oDlg.StdIn.Write "var iniDir='" & sIniDir & "';var filter='" & sFilter & "';var title='" & sTitle & "';" 
     GetFileDlgEx = oDlg.StdOut.ReadAll 
    End Function
    'sample test
    sIniDir = "C:\MyFile.rar" 
    sFilter = "RAR files (*.rar)|*.rar|" 
    sTitle = "WinRar Password Cracker by Hackoo (Only Digits numbers)" 
    MyFile = GetFileDlgEx(Replace(sIniDir,"\","\\"),sFilter,sTitle) 
    wscript.echo MyFile
    

    Edit : On 15/07/2016 @02:04

    And to genrate it with a batch file like this :

    @echo off
    Title The absolute ultimate Browse for file dialog (w95 to w8) with start folder and filters
    (
        echo Function GetFileDlgEx(sIniDir,sFilter,sTitle^) 
        echo Set oDlg = CreateObject("WScript.Shell"^).Exec("mshta.exe ""about:"""^) 
        echo oDlg.StdIn.Write "var iniDir='" ^& sIniDir ^& "';var filter='" ^& sFilter ^& "';var title='" ^& sTitle ^& "';" 
        echo GetFileDlgEx = oDlg.StdOut.ReadAll 
        echo End Function
        echo sIniDir = "C:\MyFile.rar" 
        echo sFilter = "RAR files (*.rar)|*.rar|" 
        echo sTitle = "WinRar Password Cracker by Hackoo (Only Digits numbers)" 
        echo MyFile = GetFileDlgEx(Replace(sIniDir,"\","\\"^),sFilter,sTitle^) 
        echo wscript.echo MyFile
    )>"%tmp%\%~n0.vbs"
    for /f "tokens=* delims=" %%p in ('Cscript /NoLogo "%tmp%\%~n0.vbs"') do set "file=%%p"
    echo %file%
    pause
    

    The hole code :

    @echo off
    mode con cols=70 lines=20 & color 0B
    Title WinRar Password Cracker by Hackoo (Only Digits numbers)
    :Rar
    (
        echo Function GetFileDlgEx(sIniDir,sFilter,sTitle^) 
        echo Set oDlg = CreateObject("WScript.Shell"^).Exec("mshta.exe ""about:"""^) 
        echo oDlg.StdIn.Write "var iniDir='" ^& sIniDir ^& "';var filter='" ^& sFilter ^& "';var title='" ^& sTitle ^& "';" 
        echo GetFileDlgEx = oDlg.StdOut.ReadAll 
        echo End Function
        echo sIniDir = "C:\MyFile.rar" 
        echo sFilter = "RAR files (*.rar)|*.rar|" 
        echo sTitle = "WinRar Password Cracker by Hackoo (Only Digits numbers)" 
        echo MyFile = GetFileDlgEx(Replace(sIniDir,"\","\\"^),sFilter,sTitle^) 
        echo wscript.echo MyFile
    )>"%tmp%\%~n0.vbs"
    for /f "tokens=* delims=" %%p in ('Cscript /NoLogo "%tmp%\%~n0.vbs"') do set "file=%%p"
    cls
    echo           ----------------------------------------------
    echo                          GET DETAIL
    echo           ----------------------------------------------
    echo.
    set "Rarext=.rar"
    echo selected  file is : "%file%"
    setlocal enabledelayedexpansion
    for %%i in ("%file%") do (
    set ext=%%~xi
    IF /I Not "!Rarext!"=="!ext!" Color 0C && echo This file is not a winrar file the extension must be ".rar" & pause & cls & goto Rar
    )
    echo.
    echo Hit any key to continue ....
    pause>nul
    :Main
    cls
    rem ******************  MAIN CODE SECTION
    set STARTTIME=!TIME!
    mode con cols=60 lines=15
    set strProgramFiles=%ProgramFiles%
    if exist "%ProgramFiles(x86)%" set strProgramFiles=%ProgramFiles(x86)%
    Set Unrar="%strProgramFiles%\WinRAR\UnRar.exe"
    SET PSWD=0
    SET DEST=%TEMP%\Hackoo\%RANDOM%
    MD %DEST%
    
    :START
    cls
    color 0A
    SET /A PSWD=%PSWD%+1
    echo.
    echo     0 1 0 %random% 1 1 0 0 1 0 0 1 %random% 1 0 1 0 0 1%random%
    echo     1%random% 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 %random%
    echo     1 1 1 1 1 0 1 1 0 0 %random% 1 1 0 1 0 1 0 0 0 1 1 %random%
    echo     0 %random% 0 1 1 1 1 1 0 1 0 1 0 1 %random% 0 0 0 0 0 %random%  
    echo.
    echo  **********************************************************
    echo    Please wait a while... Trying to crack the password... 
    echo              current tested password = %PSWD%
    echo  **********************************************************
    echo.  
    echo     0 1 0 %random% 1 1 0 0 1 0 0 1 %random% 1 0 1 0 0 1 %random%
    echo     1%random% 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 %random%
    echo     1 1 1 1 1 0 1 1 0 0 %random% 1 1 0 1 0 1 0 0 0 1 1 %random%
    echo     0 %random% 0 1 1 1 1 1 0 1 0 1 0 1 %random% 0 0 0 0 0 %random%
    %UNRAR% E -inul -y -P%PSWD% "%file%" "%DEST%">nul 2>&1
    IF "%ERRORLEVEL%" EQU "0" GOTO :FINISH
    GOTO START
    :FINISH
    mode con cols=60 lines=15
    RD %DEST% /Q /S
    cls
    echo        ----------------------------------------------
    echo                           CRACKED
    echo        ----------------------------------------------
    echo.
    echo PASSWORD FOUND
    echo FILE  = "%file%"
    echo CRACKED PASSWORD = %PSWD%
    set ENDTIME=!TIME!
    call :GetDuration !STARTTIME! !ENDTIME!
    exit /b
    rem ******************  END MAIN CODE SECTION
    
    :GetDuration
    set function_starttime=%1
    set function_endtime=%2
    
    rem Change formatting for the start and end times
    for /F "tokens=1-4 delims=:.," %%a in ("%function_starttime%") do (
       set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
    )
    
    for /F "tokens=1-4 delims=:.," %%a in ("%function_endtime%") do (
       set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
    )
    
    rem Calculate the elapsed time by subtracting values
    set /A elapsed=end-start
    
    rem Format the results for output
    set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
    if %hh% lss 10 set hh=0%hh%
    if %mm% lss 10 set mm=0%mm%
    if %ss% lss 10 set ss=0%ss%
    if %cc% lss 10 set cc=0%cc%
    
    set DURATION=%hh%:%mm%:%ss%.%cc%
    
    echo Start Time   : %function_starttime%
    echo Finish Time  : %function_endtime%
    echo          ---------------
    echo Duration : %DURATION%
    echo.
    pause>nul
    

提交回复
热议问题