2016-07-14 26 views
0

Ich verwende diesen Code ein Dateiauswahl mit Batch File/folder chooser dialog from a Windows batch scriptWie fügt man einen Filter zu einer Dateiauswahl im Batch hinzu?

@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 

Also meine Frage ist zu schaffen: auf eine Dateiauswahl im Batch So fügen Sie Filter?

Zum Beispiel würde Ich mag .rar hinzufügen nur gerade Winrar Dateien auswählen

Antwort

1

Wie wäre es mit 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, für Ordnerauswahl

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 
+0

Vielen Dank für Ihre Hilfe, Ihre Antwort der Trick! – Hackoo

+1

Dies funktioniert sehr gut, außer für den Overhead des Ladens von Powershell. Aber ich würde dir besser eine Antwort geben, die die Verwendung von MHT-Dateien beinhaltet, aber das war für mich nicht möglich. – elzooilogico

0

Just, ich will mein Skript teilen, basierend auf der Lösung von elzooilogico

nur einen Versuch für nur 2 oder 3 oder 4 Ziffern zu knacken 4 Ziffern können in 5 Minuten oder mehr erfolgen.

Wenn Sie das Passwort mehr als 4 Ziffern knacken wollen, dauert es natürlich länger. so, um es zu testen, erstellen Sie einfach ein neues Archiv mit WinRAR mit einem Passwort zum Beispiel geschützt:

Passwort = 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%" 
1

I fand eine andere Lösung in vbscript hier gepostet:

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 

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

Und es mit einer Batch-Datei wie folgt genrate:

@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 

Der Lochcode:

@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

kommentieren Sie einfach ein Problem. Wenn _Dateiname_ oder _Pfad_ das Zeichen ** & ** enthalten, muss die Datei 'echo% file: & =^&%' mit Escapezeichen versehen werden – elzooilogico