如何批量添加过滤器到文件选择器?

时间:2016-07-14 08:52:28

标签: javascript powershell batch-file cmd hta

我正在使用此代码创建批处理File / folder chooser dialog from a Windows batch script

的文件选择器
@echo off
set dialog="about:<input type=file id=FILE><script>FILE.click();new ActiveXObject
set dialog=%dialog%('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);
set dialog=%dialog%close();resizeTo(0,0);</script>"
for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "file=%%p"
echo selected  file is : "%file%"
pause

所以我的问题是:如何批量添加过滤器到文件选择器?

例如,我想只添加.rar来选择winrar文件

3 个答案:

答案 0 :(得分:2)

我在vbscript中发现了另一个解决方案:

<强> 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:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);eval(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0).Read("&Len(sIniDir)+Len(sFilter)+Len(sTitle)+41&"));function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg(iniDir,null,filter,title)));close();}</script><hta:application showintaskbar=no />""") 
 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

编辑:2016年7月15日@ 02:04

并使用这样的批处理文件生成它:

@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:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);eval(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0).Read("^&Len(sIniDir^)^+Len(sFilter^)^+Len(sTitle^)+41^&"));function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg(iniDir,null,filter,title)));close();}</script><hta:application showintaskbar=no />"""^) 
    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

漏洞代码:

@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:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);eval(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0).Read("^&Len(sIniDir^)^+Len(sFilter^)^+Len(sTitle^)+41^&"));function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg(iniDir,null,filter,title)));close();}</script><hta:application showintaskbar=no />"""^) 
    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

答案 1 :(得分:1)

如何使用PowerShell?

@echo off

set "full="
set "file=" 
set "mypath=%~dp0"

call:fileSelection "%file%", "%mypath%", "Choose a file", file, mypath

set "full=%mypath%\%file%"

echo(
echo( File is: %file%
echo( Path is: %mypath%
echo(
echo( Full filename: %full%

exit/B

:fileSelection
SetLocal & set "file=%~1" & set "folder=%~2"  & rem if selection is canceled restore previous data
set "dialog=powershell -sta "Add-Type -AssemblyName System.windows.forms^|Out-Null;$f=New-Object System.Windows.Forms.OpenFileDialog;$f.filename='%~1';$f.InitialDirectory='%~2';$f.title='%~3';$f.showHelp=$false;$f.Filter='RAR files (*.rar)^|*.rar^|ZIP files (*.zip)^|*.zip^|All files (*.*)^|*.*';$f.ShowDialog()^|Out-Null;$f.FileName""
for /f "delims=" %%I in ('%dialog%') do set "res=%%I"
echo "%res%" | find "\" >NUL && call:stripPath "%res%", file, folder  & rem selection, otherwise cancel. Avoid this if you want full path and filename
EndLocal & set "%4=%file%" & set "%5=%folder%"
exit/B 0

:: --------------------- Split path and filename ---------------------
:stripPath
SetLocal & set "file=%~nx1" & set "folder=%~dp1"
EndLocal & set "%2=%file%" & set "%3=%folder:~0,-1%"
exit/B

BTW,用于文件夹选择

call:folderSelection "%mypath%", mypath, "Choose a folder"

:folderSelection
SetLocal & set "folder=%~1"
set "dialog=powershell -sta "Add-Type -AssemblyName System.windows.forms^|Out-Null;$f=New-Object System.Windows.Forms.FolderBrowserDialog;$f.SelectedPath='%~1';$f.Description='%~3';$f.ShowNewFolderButton=$true;$f.ShowDialog();$f.SelectedPath""
for /F "delims=" %%I in ('%dialog%') do set "res=%%I"
EndLocal & (if "%res%" EQU "" (set "%2=%folder%") else (set "%2=%res%"))
exit/B 0

答案 2 :(得分:0)

是的,我想根据 elzooilogico

的解决方案分享我的脚本

只需试一下2或3或4位数字即可破解 4位数字可在5分钟或更长时间内完成。

如果你想破解超过4位数字的密码,当然需要更多的时间。 因此,要测试它,只需创建一个新的存档,其中winrar受密码保护,例如:

  

密码= 123

enter image description here

enter image description here

@echo off
mode con cols=70 lines=15 & color 0B
:Rar
Title WinRar Password Cracker by Hackoo (Only Digits numbers)
rem set dialog="about:<input type=file id=FILE><script>FILE.click();new ActiveXObject
rem set dialog=%dialog%('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);
rem set dialog=%dialog%close();resizeTo(0,0);</script>"
rem for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "file=%%p"
set "full="
set "file=" 
set "mypath=%~dp0"
call:fileSelection "%file%", "%mypath%", "Choose a file", file, mypath
set "full=%mypath%\%file%"
rem echo(
rem echo( File is: %file%
rem echo( Path is: %mypath%
rem echo(
rem echo( Full filename: %full%
rem pause
cls
echo           ----------------------------------------------
echo                          GET DETAIL
echo           ----------------------------------------------
echo.
set "Rarext=.rar"
echo selected  file is : "%full%"
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 Unrar="%ProgramFiles%\WinRAR\UnRar.exe"
SET PSWD=0
SET DEST=%TEMP%\Hackoo\%RANDOM%
MD %DEST%

:START
cls
color 0A
rem echo %UNRAR% E -inul -y -P%PSWD% "%full%" "%DEST%"
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% "%full%" "%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  = "%full%"
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
exit /b

:fileSelection
SetLocal & set "file=%~1" & set "folder=%~2"  & rem if selection is canceled restore previous data
set "dialog=powershell -sta "Add-Type -AssemblyName System.windows.forms^|Out-Null;$f=New-Object System.Windows.Forms.OpenFileDialog;$f.filename='%~1';$f.InitialDirectory='%~2';$f.title='%~3';$f.showHelp=$false;$f.Filter='RAR files (*.rar)^|*.rar';$f.ShowDialog()^|Out-Null;$f.FileName""
for /f "delims=" %%I in ('%dialog%') do set "res=%%I"
echo "%res%" | find "\" >NUL && call:stripPath "%res%", file, folder  & rem selection, otherwise cancel. Avoid this if you want full path and filename
EndLocal & set "%4=%file%" & set "%5=%folder%"
exit/B 0

:: --------------------- Split path and filename ---------------------
:stripPath
SetLocal & set "file=%~nx1" & set "folder=%~dp1"
EndLocal & set "%2=%file%" & set "%3=%folder:~0,-1%"