├── DateAndTime ├── DateParts.bat ├── W32DOW.bat ├── W32tmSleep.bat ├── getTime.bat └── sleeptp.bat ├── Java ├── getJavaVersion.bat ├── javaDetect.bat ├── javaExtInstaller.bat └── javaHybrid.bat ├── LICENSE ├── ProcessesUtils ├── StartPID.bat └── startHidden.bat ├── README.md ├── dataStructures └── binaryTree.bat ├── discovers_and_bugs ├── bugs │ ├── EOFbreaker.bat │ ├── FORbreaker.bat │ ├── ParamExpansionAndDriveVars │ ├── callCrasher.bat │ ├── callForCallIf.txt │ ├── callbrackets.bat │ ├── forCrasher.bat │ ├── forEmptyTokens │ ├── ifCrasher.bat │ ├── ifDefined.bat │ ├── pipeIf.bat │ └── remCrasher.bat └── discovers │ ├── DPATH │ ├── FirmwareType.bat │ ├── anonymous.bat │ ├── boolKeys.bat │ ├── callArgs.bat │ ├── callcolons.bat │ ├── certutil.txt │ ├── defaultJumpDir.bat │ ├── emptyTokens.bat │ ├── fileRedirection.bat │ ├── findEscapeQuote.bat │ ├── firmware_type.txt │ ├── forL.bat │ ├── internal_commands.txt │ ├── keys │ ├── msg.txt │ ├── multiLineComments.txt │ ├── negativeGOTO.bat │ ├── plainfor │ ├── promptFeatures.txt │ ├── splitCommand.bat │ ├── tasklist │ └── typeList.bat ├── fileUtils ├── SHA512.bat ├── dirTimes.bat ├── encodingDetect.bat ├── extInstaller ├── file2hex.bat ├── fileModifiedTime.bat ├── fileTimes.bat ├── fileassembler.bat ├── firstLines.bat ├── firstLinesP.bat ├── folderOwner.bat ├── listFS.bat ├── md2.bat ├── md4.bat ├── md5.bat ├── progressCopy.bat ├── sha1.bat ├── sha256.bat ├── sha384.bat ├── splitBin.bat ├── tailHead.bat └── wmicVersion.bat ├── hybrids ├── .net │ ├── FileTimeFilerJS.bat │ ├── ProcessStartJS.bat │ ├── SystemTrayNotification.bat │ ├── WebClientDownload.bat │ ├── bat2exe.bat │ ├── c │ │ ├── getPixelColor.bat │ │ ├── listWindows.bat │ │ ├── mouse.bat │ │ ├── mouseSniffer.bat │ │ ├── quickEdit.bat │ │ ├── screenCapture.bat │ │ ├── taskbarHidder.bat │ │ └── windowMode.bat │ ├── checkPortJS.bat │ ├── colorInput.bat │ ├── coloroutput.bat │ ├── dirTimesNET.bat │ ├── fileTimesNET.bat │ ├── getCmdPID.bat │ ├── gzipJS.bat │ ├── keyStates.bat │ ├── keyreader.bat │ ├── listEncodings.bat │ ├── msbuild │ │ └── checkPort.bat │ ├── passHidder.bat │ ├── powershell │ │ ├── checkRemotePort.bat │ │ └── enterNumber.bat │ ├── selectFolder.bat │ ├── setPrio.bat │ ├── split.net.bat │ ├── systemSounds.bat │ └── waitMS.bat ├── iexpress │ ├── OKPopup.bat │ ├── bat2exeIEXP.bat │ ├── hidder.bat │ ├── iexpYNButton.bat │ ├── licenseAgreement.bat │ └── read.me ├── jscript │ ├── FileTimeFilterJS.bat │ ├── ShellRunJS.bat │ ├── UIautoLogin.bat │ ├── WinHTTPDownloadJS.bat │ ├── XMLHTTPDownloadJS.bat │ ├── base64.bat │ ├── calcjs.bat │ ├── deleteJS.bat │ ├── dirTimesJS.bat │ ├── drivesInfoJS.bat │ ├── edit.json.bat │ ├── ejectjs.bat │ ├── enterNumberJS.bat │ ├── fileTImesJS.bat │ ├── focusOn.bat │ ├── freememjs.bat │ ├── getInnerText.bat │ ├── guid.bat │ ├── imageProcessing │ │ ├── convImg.bat │ │ ├── crop.bat │ │ ├── rotateFlip.bat │ │ ├── scale.bat │ │ ├── shRotate.bat │ │ ├── stamp.bat │ │ └── tiff.bat │ ├── imgInfo.bat │ ├── jsonextractor.bat │ ├── jspopup.bat │ ├── julian.bat │ ├── listVerbs.bat │ ├── mediarunner.bat │ ├── oneDriveSync.bat │ ├── pdfPageCounter.bat │ ├── phisycalDrives.bat │ ├── pinnerJS.bat │ ├── ppt2pdf.bat │ ├── printJS.bat │ ├── replacer.bat │ ├── sendKeys.bat │ ├── shellCopy.bat │ ├── shortcutJS.bat │ ├── slowTypeJS.bat │ ├── splitjs.bat │ ├── spplayer.bat │ ├── toHexJS.bat │ ├── toHtmlEnt.bat │ ├── tooltipInfo.bat │ ├── unHexJS.bat │ ├── uuid.bat │ ├── winhttpjs.bat │ ├── write.bat │ ├── xpath.bat │ ├── xpath0.1.bat │ ├── yesnopopup.bat │ └── zipjs.bat ├── makecab │ ├── cabSplitter.bat │ ├── cabdir.bat │ └── fileinf.bat ├── mshta │ ├── OpticalDrivesCount.bat │ ├── atob.bat │ ├── btoa.bat │ ├── freeMem.bat │ ├── printClip.bat │ ├── say.bat │ ├── soundPlayer.bat │ ├── start.bckgrnd.bat │ ├── ui.extensions │ │ ├── buttons.bat │ │ ├── choose.button.bat │ │ ├── countdown.bat │ │ ├── passwordSubmiter.bat │ │ ├── radioButtons.bat │ │ └── userInput.bat │ └── weekNumber.bat └── wsh │ ├── EjectCD.bat │ ├── vbexecutor.bat │ └── win32process.bat ├── math ├── isInteger.bat └── removeLeadingZeroes.bat ├── network ├── bitsDownloader.bat └── checkNet.bat ├── other ├── ArrayListPOC.bat ├── beeper.bat ├── continueEnter.bat ├── listBrosers.bat ├── listBrowsers.bat ├── officeVersion.bat ├── pushdCounter.bat ├── pushdCounterTmpF.bat └── setlocalLevelCounter.bat ├── printing └── printCHM.bat ├── stringutils ├── countOfSubstrings.bat ├── endsWith.bat ├── indexOf.bat ├── lastIndexOf.bat ├── reverse.bat ├── split.bat ├── startsWith.bat ├── stringToHex.bat ├── strlen0.3 ├── strlen2.5 ├── strlen2.9 ├── toLowerCase.bat └── toUpperCase.bat └── system ├── checkPermissions.bat ├── chkPermissions.bat ├── monitorInfo.bat ├── netVersions.bat └── screenres.bat /DateAndTime/DateParts.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem gets Date Parts 3 | rem by Vasil "npocmaka" Arnaudov 4 | rem 21.01.15 - improvement was proposed by Ildar Shaimordanov - a.k.a siberia-man 5 | rem - to use empty folder to increase performance 6 | for /f "skip=10 tokens=2,3,4,5,6,7,8 delims=: " %%D in (' 7 | robocopy /l * "%windir%\System32\wbem\MOF\bad" "%windir%\System32\wbem\MOF\bad" /ns /nc /ndl /nfl /np /njh /XF * /XD * 8 | ') do ( 9 | set "dow=%%D" 10 | set "month=%%E" 11 | set "day=%%F" 12 | set "HH=%%G" 13 | set "MM=%%H" 14 | set "SS=%%I" 15 | set "year=%%J" 16 | ) 17 | 18 | echo Day of the week: %dow% 19 | echo Day of the month : %day% 20 | echo Month : %month% 21 | echo hour : %HH% 22 | echo minutes : %MM% 23 | echo seconds : %SS% 24 | echo year : %year% 25 | -------------------------------------------------------------------------------- /DateAndTime/W32DOW.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | rem :: prints the day of the week 4 | rem :: works on Vista and above 5 | rem :: by Vasil "npocmaka" Arnaudov 6 | 7 | rem :: getting ansi date ( days passed from 1st jan 1601 ) , timer server hour and current hour 8 | FOR /F "skip=16 tokens=4,5 delims=:( " %%D in ('w32tm /stripchart /computer:localhost /samples:1 /period:1 /dataonly /packetinfo') do ( 9 | set "ANSI_DATE=%%D" 10 | set "TIMESERVER_HOURS=%%E" 11 | goto :end_for ) 12 | :end_for 13 | set "LOCAL_HOURS=%TIME:~0,2%" 14 | if "%TIMESERVER_HOURS:~0,1%0" EQU "00" set TIMESERVER_HOURS=%TIMESERVER_HOURS:~1,1% 15 | if "%LOCAL_HOURS:~0,1%0" EQU "00" set LOCAL_HOURS=%LOCAL_HOURS:~1,1% 16 | set /a OFFSET=TIMESERVER_HOURS-LOCAL_HOURS 17 | 18 | rem :: day of the week will be the modulus of 7 of local ansi date +1 19 | rem :: we need need +1 because Monday will be calculated as 0 20 | rem :: 1st jan 1601 was Monday 21 | 22 | rem :: if abs(offset)>12 we are in different days with the time server 23 | 24 | IF %OFFSET%0 GTR 120 set /a DOW=(ANSI_DATE+1)%%7+1 25 | IF %OFFSET%0 LSS -120 set /a DOW=(ANSI_DATE-1)%%7+1 26 | IF %OFFSET%0 LEQ 120 IF %OFFSET%0 GEQ -120 set /a DOW=ANSI_DATE%%7+1 27 | 28 | 29 | echo Day of the week: %DOW% 30 | exit /b 2147483648 31 | endlocal 32 | -------------------------------------------------------------------------------- /DateAndTime/W32tmSleep.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: yet another sleep emulator working on everything from NT and above 3 | if "%~1"=="" goto :help 4 | ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL || goto :help 5 | IF %~1 LSS 0 goto :help 6 | 7 | setLocal 8 | set /a adj=%~1/2+1 9 | w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:%adj% >nul 2>&1 10 | endLocal 11 | 12 | goto :eof 13 | :help 14 | echo. 15 | echo %~n0 16 | echo Sleep emulator 17 | echo Wait for a specified number of seconds. 18 | echo. 19 | echo Usage: CALL %~n0 seconds 20 | echo. 21 | echo seconds - seconds to wait 22 | echo. 23 | echo. 24 | echo by Vasil "npocmaka" Arnaudov 25 | -------------------------------------------------------------------------------- /DateAndTime/getTime.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: gets time using typePerf command 4 | :: with put some effort to be made fast and maximum compatible 5 | 6 | setlocal 7 | ::check if windows is XP and use XP valid counter for UDP performance 8 | if defined USERDOMAIN_roamingprofile (set "v=v4") else (set "v=") 9 | set "mon=" 10 | for /f "skip=2 delims=," %%# in ('typeperf "\UDP%v%\*" -si 0 -sc 1') do ( 11 | if not defined mon ( 12 | for /f "tokens=1-7 delims=.:/ " %%a in (%%#) do ( 13 | set mon=%%a 14 | set date=%%b 15 | set year=%%c 16 | set hour=%%d 17 | set minute=%%e 18 | set sec=%%f 19 | set ms=%%g 20 | ) 21 | ) 22 | ) 23 | echo %year%.%mon%.%date% 24 | echo %hour%:%minute%:%sec%.%ms% 25 | endlocal 26 | -------------------------------------------------------------------------------- /DateAndTime/sleeptp.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: yet another sleep emulator working on everything from NT and above 3 | if "%~1"=="" goto :help 4 | ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL 2>NUL || goto :help 5 | IF %~1 LSS 0 goto :help 6 | 7 | typeperf "\System\Processor Queue Length" -si %~1 -sc 1 >nul 8 | 9 | goto :eof 10 | :help 11 | echo. 12 | echo %~n0 13 | echo Sleep emulator 14 | echo Wait for a specified number of seconds. 15 | echo. 16 | echo Usage: CALL %~n0 seconds 17 | echo. 18 | echo seconds - seconds to wait 19 | -------------------------------------------------------------------------------- /Java/getJavaVersion.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem : ------------------------------ 3 | rem : 4 | rem : sets java version as a number to jver 5 | rem : variable in one line. 6 | rem : by Vasil "npocmaka" Arnaudov 7 | rem : 8 | rem : ------------------------------ 9 | 10 | for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%%l%%m" 11 | 12 | rem : ------------------------------ 13 | rem : for execution directly to the command prompt use the line bellow 14 | rem : for /f tokens^=2-5^ delims^=.-_^" %j in ('java -fullversion 2^>^&1') do @set "jver=%j%k%l%m" 15 | rem : ------------------------------ 16 | -------------------------------------------------------------------------------- /Java/javaDetect.bat: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | @ECHO OFF 3 | set __COMPAT_LAYER=RunAsInvoker 4 | :: Export java settings from registry to a temporary file 5 | START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft" 6 | 7 | 8 | if not exist "%Temp%\java.reg" ( 9 | START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft" 10 | ) 11 | 12 | 13 | 14 | if not exist "%Temp%\java.reg" ( 15 | echo java not installed 16 | exit /b 1 17 | ) 18 | 19 | 20 | 21 | :: Find java location 22 | FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "INSTALLDIR"') DO SET JAVA_HOME=%%B 23 | SET JAVA_HOME=%JAVA_HOME:"=% 24 | SET JAVA_HOME=%JAVA_HOME:\\=\% 25 | SET JAVA_HOME 26 | 27 | :: Get java version 28 | ::FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "CurrentVersion"') DO SET JAVA_VERSION=%%B 29 | ::SET JAVA_VERSION=%JAVA_VERSION:"=% 30 | ::SET JAVA_VERSION 31 | ::SET JAVA_VERSION=%JAVA_VERSION:.=% 32 | ::SET JAVA_VERSION=%JAVA_VERSION:_=% 33 | ::SET /A JAVA_VERSION=%JAVA_VERSION% 34 | 35 | for /f tokens^=2-5^ delims^=.-_^" %%j in ('%JAVA_HOME%\bin\java.exe -fullversion 2^>^&1') do set "JAVA_VERSION=%%j%%k%%l%%m" 36 | 37 | :: Delete temp file 38 | rem @DEL %Temp%\java.reg /S /Q > NUL 2>&1 39 | set JAVA_VERSION 40 | :: Check java version compatibility 41 | IF %JAVA_VERSION% LSS 16020 ( 42 | ECHO. 43 | ECHO YOU NEED AT LEAST JAVA WITH VERSION 1.6.0_20 -- this is just an example echo. 44 | GOTO :EOF 45 | ) 46 | 47 | PAUSE 48 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 49 | -------------------------------------------------------------------------------- /Java/javaExtInstaller.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: requires Admin permissions 3 | :: allows a files with .JAVA (in this case ) extension to act like .bat/.cmd files. 4 | :: Will create a 'caller.bat' asociated with the extension 5 | :: which will create a temp .bat file on each call (you can consider this as cheating) 6 | :: and will call it. 7 | :: Have on mind that the %0 argument will be lost. 8 | 9 | 10 | rem :: "installing" a caller. 11 | if not exist "c:\javaCaller.bat" ( 12 | echo @echo off 13 | echo copy "%%~nx1" "%%temp%%\%%~nx1.bat" /Y ^>nul 14 | echo "%%temp%%\%%~nx1.bat" %%* 15 | ) > c:\javaCaller.bat 16 | 17 | rem :: associating file extension 18 | assoc .java=javafile 19 | ftype javafile=c:\javaCaller "%%1" %%* 20 | -------------------------------------------------------------------------------- /Java/javaHybrid.bat: -------------------------------------------------------------------------------- 1 | @Deprecated /* >nul 2>&1 2 | 3 | :: self compiled java/.bat hybrid 4 | :: 5 | :: deprecated is the only one annotation that can be used outside the class definition 6 | :: and is needed for 'mute' start of multi-line java comment 7 | :: that will be not printed by the batch file. 8 | :: though it still creates two files - the .class and the .java 9 | :: it still allows you to embed both batch and java code into one file 10 | 11 | @echo off 12 | setlocal 13 | java -version >nul 2>&1 || ( 14 | echo java not found 15 | exit /b 1 16 | ) 17 | 18 | ::find class name 19 | ::can be different than the script name 20 | for /f "usebackq tokens=3 delims=} " %%c in (`type %~f0 ^|find /i "public class"^|findstr /v "for /f"`) do ( 21 | set "javaFile=%%c" 22 | goto :skip 23 | ) 24 | :skip 25 | 26 | copy "%~f0" "%javaFile%.java" >nul 2>&1 27 | 28 | javac "%javaFile%.java" 29 | java "%javaFile%" 30 | 31 | ::optional 32 | ::del %javaFile%.* >nul 2>&1 33 | endlocal 34 | exit /b 0 35 | 36 | *******/ 37 | 38 | 39 | 40 | public class TestClass 41 | { 42 | public static void main(String args[]) 43 | { 44 | System.out.println("selfcompiled .bat/.java hybrid"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Vasil Arnaudov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | batch.scripts 2 | ============= 3 | -------------------------------------------------------------------------------- /dataStructures/binaryTree.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | 4 | :: Binary tree implementation with pure batch 5 | :: only insert and find methods are implmented so far 6 | :: 7 | :: it uses the binary tree name as the variable that holds 8 | :: the root element and adds revursively to namer right elements 9 | :: and namel the left elements. 10 | 11 | :::--- some tests ----- 12 | call ::insert test_tree6 1 13 | call ::insert test_tree6 5 14 | call ::insert test_tree6 8 15 | call ::insert test_tree6 9999 16 | 17 | color 18 | echo searching for value 8 19 | call ::find test_tree6 8 20 | echo %errorlevel% - if 0 element is found 21 | echo searching for value 123 22 | call ::find test_tree6 123 23 | echo %errorlevel% - if 1 element is not found 24 | set test_tree6 25 | :::::::::::::::::::::::::::::: 26 | 27 | exit /b 0 28 | 29 | 30 | :find three_name value 31 | setlocal enableDelayedExpansion 32 | set /a value=%~2 33 | set node=%1 34 | 35 | if %value% equ !%1! ( 36 | endlocal & ( 37 | echo %1 38 | exit /b 0 39 | ) 40 | ) 41 | 42 | 43 | if %value% GTR !%1! ( 44 | if defined %1r ( 45 | endlocal & ( 46 | call ::find %1r %value% 47 | ) 48 | ) else ( 49 | endlocal & exit /b 1 50 | ) 51 | ) 52 | 53 | if %value% LSS !%1! ( 54 | if defined %1l ( 55 | endlocal & ( 56 | call ::find %1l %value% 57 | ) 58 | ) else ( 59 | endlocal & exit /b 1 60 | ) 61 | ) 62 | 63 | 64 | exit /b 65 | 66 | 67 | 68 | :insert three_name value 69 | setlocal 70 | ::set "three_name=%~1" 71 | set /a value=%~2 72 | 73 | if not defined %~1 ( 74 | endlocal & ( 75 | set "%~1=%value%" 76 | exit /b 0 77 | ) 78 | ) 79 | 80 | if %value% GEQ %~1r ( 81 | if not defined %~1r ( 82 | endlocal & ( 83 | set %~1r=%value% 84 | exit /b 0 85 | ) 86 | ) else ( 87 | endlocal & ( 88 | call ::insert %~1r %value% 89 | rem exit /b 0 90 | ) 91 | ) 92 | ) 93 | 94 | if %value% LSS %~1l ( 95 | if not defined %~1l ( 96 | endlocal & ( 97 | set %~1l=%value% 98 | exit /b 0 99 | ) 100 | ) else ( 101 | endlocal & ( 102 | call ::insert %~1r %value% 103 | rem exit /b 0 104 | ) 105 | ) 106 | ) 107 | 108 | exit /b 0 109 | 110 | :delete 111 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/EOFbreaker.bat: -------------------------------------------------------------------------------- 1 | :: http://ss64.org/viewtopic.php?id=1554 2 | :: redirecting to/from escaped EOF crashes the command prompt 3 | :: as explained in dbenham in the above link 4 | :: this was also featured here 5 | :: http://stackoverflow.com/questions/23284131/cmd-exe-parsing-bug-leads-to-other-exploits 6 | 7 | @echo off 8 | rem do not set new lines at the end or you'll break the breaker 9 | echo combobreaker |( goto :eof >^ 10 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/FORbreaker.bat: -------------------------------------------------------------------------------- 1 | ::http://ss64.org/viewtopic.php?id=1554 2 | 3 | @echo on 4 | :: this prints for %%A in ((nul)) do echo %%A 5 | :: before command prompt crash 6 | break | for %%A in () do echo %%A 7 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/ParamExpansionAndDriveVars: -------------------------------------------------------------------------------- 1 | C:\>for %I in (a: b: c: ">:" "&:") do @echo %~fI 2 | C:\>pushd c: 3 | C:\>set " 4 | 5 | the output is: 6 | 7 | =&:=&:\ 8 | 9 | =>:=>:\ 10 | 11 | =A:=A:\ 12 | 13 | =B:=B:\ 14 | 15 | =C:=C:\ 16 | 17 | .... 18 | 19 | 20 | 21 | Will not work if there's path attached to the mimic drives in the for set or if the "push ." (cd . also can be used) is skipped. 22 | Looks like the parameter expansion splits the paths in two parts - drive and the rest of the path and later concattanes them. 23 | And used drives are stored somewhere - and if there's no path part they are not deleted. CD and PUSHD resets drive variables. 24 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/callCrasher.bat: -------------------------------------------------------------------------------- 1 | :: Do not set any symbols after the closing bracket 2 | (call :: & :: ) 3 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/callForCallIf.txt: -------------------------------------------------------------------------------- 1 | :: http://stackoverflow.com/questions/19445153/why-i-cant-call-if-and-for-neither-in-batch-nor-in-the-cmd 2 | 3 | :: Call command cannot execute IF and FOR commands , despite syntax errors are detected 4 | :: Examples bellow (should be executed in command prompt but not from batch file) 5 | 6 | 7 | C:\Windows\system32>call @if a==a echo called 8 | ',' is not recognized as an internal or external command, 9 | operable program or batch file. 10 | 11 | C:\Windows\system32>call (@if a==a echo called) 12 | ';' is not recognized as an internal or external command, 13 | operable program or batch file. 14 | 15 | C:\Windows\system32>call if a==a echo called 16 | 'if' is not recognized as an internal or external command, 17 | operable program or batch file. 18 | 19 | C:\Windows\system32>call for %a in (1) do @echo called 20 | 'for' is not recognized as an internal or external command, 21 | operable program or batch file. 22 | 23 | C:\Windows\system32>call @for %a in (1) do @echo called 24 | '+' is not recognized as an internal or external command, 25 | operable program or batch file. 26 | 27 | C:\Windows\system32>call (@for %a in (1) do @echo called) 28 | ';' is not recognized as an internal or external command, 29 | operable program or batch file. 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/callbrackets.bat: -------------------------------------------------------------------------------- 1 | ::http://stackoverflow.com/questions/24418084/why-call-command-cannot-execute-a-command-enclosed-with-brackets 2 | :: 3 | :: Call command is unable to execute expression enclosed in brackets 4 | :: Examples bellow 5 | :: 6 | :: 7 | 8 | @echo off 9 | 10 | :: the echo that will never be 11 | call(echo echo echo) 12 | 13 | :: its the same with non-cmd internal commands 14 | call ( notepad.exe ) 15 | 16 | :: and even with a code that should fail 17 | call(gibberish) 18 | 19 | :: moreover the execution is successful 20 | call (gibberish)&&echo %errorlevel% 21 | 22 | :: though there's some parsing done 23 | call(this will print call help because contains "/?"-/?) 24 | 25 | :: and will detect a wrong syntax of some parsed-before-execution commands 26 | call ( if a==) 27 | 28 | :: and this too 29 | call (%~) 30 | 31 | :: same with labels 32 | call(:label) 33 | call(:no_label) 34 | :label 35 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/forCrasher.bat: -------------------------------------------------------------------------------- 1 | set "h=/?" && call if %%h%% 2 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/forEmptyTokens: -------------------------------------------------------------------------------- 1 | @@echo off 2 | :::this prints - 1:[i] 2:[] 3:[] 4:[] 5:[] 6:[] 7:[] 3 | for /f "tokens=1,1,1,1,1,1,1" %%a in ("i ii iii iv v vi vii") do ( 4 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 5 | ) 6 | 7 | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[iv] 5:[] 6:[] 7:[%g] 8 | for /f "tokens=2,3,1-4" %%a in ("i ii iii iv v vi vii") do ( 9 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 10 | ) 11 | 12 | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[] 5:[] 6:[] 7:[%g] 13 | for /f "tokens=1-3,1-3," %%a in ("i ii iii iv v vi vii") do ( 14 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 15 | ) 16 | 17 | exit /b 0 18 | http://stackoverflow.com/questions/25950181/why-for-f-sets-empty-values-for-repeated-numbers-in-the-rest-of-tokens 19 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/ifCrasher.bat: -------------------------------------------------------------------------------- 1 | set "h=/?"&& call for %%h%% 2 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/ifDefined.bat: -------------------------------------------------------------------------------- 1 | :: Checking if variable that name contains spaces (or default delimiters - pointed by Liviu) 2 | :: is not so easy 3 | :: Escaping delimiters with ^ does not work and even its buggy 4 | :: 5 | :: To perform proper checking you need delayed expansion 6 | :: or FOR /F wrapping (proposed by penpen) 7 | :: 8 | :: http://www.dostips.com/forum/viewtopic.php?f=3&t=6148 9 | :: 10 | :: using delayed expansion 11 | 12 | :: some explantations here : http://stackoverflow.com/questions/28000194/why-if-checking-ignores-delimtersome-word-after-the-check-expression 13 | 14 | @echo off 15 | 16 | setlocal enableDelayedExpansion 17 | 18 | set sim salabim=magic 19 | set sim=simulation 20 | 21 | set "checker=sim salabim" 22 | 23 | if defined !checker! echo # 24 | 25 | rem the commented lines produce errors 26 | rem if defined sim salabim echo $ 27 | rem if defined %checker% echo @ 28 | rem if defined "sim salabim" echo * 29 | 30 | 31 | endlocal 32 | 33 | 34 | :: using FOR /F (penpen) 35 | 36 | @echo off 37 | setlocal disableDelayedExpansion 38 | set sim salabim=magic 39 | 40 | for %%a in ("sim salabim") do if defined %%~a echo --- 41 | endlocal 42 | goto :eof 43 | 44 | 45 | :: If defined parser bug demonstration 46 | 47 | @echo off 48 | 49 | setlocal 50 | 51 | set "undefined1=" 52 | set "undefined2=" 53 | set "undefined3=" 54 | 55 | set "var1=1" 56 | 57 | if defined var1^ undefined1^ undefined2^ undefined3 echo ### 58 | 59 | endlocal 60 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/pipeIf.bat: -------------------------------------------------------------------------------- 1 | :: http://www.dostips.com/forum/viewtopic.php?f=3&t=5539 2 | :: 3 | :: when something is piped to IF command the spaces before first operand are eaten (check the link above) 4 | :: While I've only found the problem - the root cause and the solution were found by jeb 5 | 6 | @echo off 7 | rem prints 1 is geq than 1 8 | echo.|if defined 1 geq 1 echo 1 is geq than 1 9 | rem prints 2 is gtr than 100 10 | echo.|if defined 2 gtr 100 echo 2 is gtr than 100 11 | 12 | rem prints 1 is gteater than 100 13 | echo.|if 1 gtr gtr 100 echo 1 is gteater than 100 14 | rem prints 100 is gteater and the same time less than 100 15 | echo.|if 100 lss gtr 100 echo 100 is gteater and the same time less than 100 16 | 17 | :: the root cause is visible by executing the following line in command prompt (found by jeb): 18 | ::C:\>echo pipe | if defined X lss Y echo %^cmdcmdline% 19 | :: In both cases - befora and after swalowing of the spaces syntax errors are detected (that's why the examples above works 20 | :: - a second comparison operator is added) 21 | 22 | 23 | :: the solution (proposed by jeb): 24 | 25 | 26 | @echo off 27 | set "myLine=if 1 lss 2 more" 28 | echo pipe | ( %%myLine%%) 29 | 30 | :: If command dows now swallow the pipe and passed string can be used both in IF and ELSE commands. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /discovers_and_bugs/bugs/remCrasher.bat: -------------------------------------------------------------------------------- 1 | set "h=/?"&call rem %%h%% 2 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/DPATH: -------------------------------------------------------------------------------- 1 | @echo off 2 | dpath /? 3 | dpath 4 | type cmd.exe 5 | set /p=&1 >nul 20 | if "%0" == ":%anonymous%" ( 21 | echo Anonymous called 22 | exit /b 0 23 | )>&3 24 | 25 | 26 | rem example with code block ecnlosed with brackets 27 | echo Before anonymous call: 28 | echo %%1=%1 %%2=%2 %%3=%3 29 | 30 | for /l %%N in (1 1 5) do ( 31 | set /a N=%%N*2 32 | call :%%anonymous%% a b c 3>&1 >nul 33 | echo --- 34 | ) 35 | if "%0" == ":%anonymous%" ( 36 | echo( 37 | echo Anonymous call: 38 | echo %%1=%1 %%2=%2 %%3=%3 N=%N% 39 | exit /b 0 40 | )>&3 41 | 42 | echo( 43 | echo After anonymous call: 44 | echo %%1=%1 %%2=%2 %%3=%3 45 | 46 | 47 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/boolKeys.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | goto :endComment 3 | Nothing useful , just observation over KEYS internal state and how it differs from ECHO. 4 | KEYS changes its state even if it's called within brackets or in conditional execution statements and to child threads/processes spawned with pipes or FOR (unlike ECHO): 5 | https://www.dostips.com/forum/viewtopic.php?t=6914#p45037 6 | :endComment 7 | setlocal disableDelayedExpansion 8 | 9 | set "if_on=for /f "tokens=3" %%# in ('keys') do if %%#==on. " 10 | set "if_off=for /f "tokens=3" %%# in ('keys') do if %%#==off. " 11 | 12 | rem :: echo state cannot be examined so easy 13 | ::for /f "tokens=3" %%# in ('echo') do echo %%# 14 | ::echo|for /f "tokens=3" %%# in ('more') do echo %%# 15 | ::echo|find "on." 16 | ( 17 | 18 | keys on 19 | %if_on% echo Should be displayed 20 | %if_off% echo Should be not 21 | keys off 22 | %if_off% echo Should be displayed 23 | %if_on% echo Should be not 24 | ( 25 | keys on 26 | ) 27 | %if_on% echo Should be displayed 28 | %if_off% echo Should be not 29 | 30 | ) 31 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/callArgs.bat: -------------------------------------------------------------------------------- 1 | :: using SHIFT and accessing arguments within same brackets context 2 | :: might cause troubles 3 | :: 4 | :: following code with this arg. line ich ni san shi go roku 5 | :: 6 | :: @echo off 7 | :: for /l %%c in (1=1=5) do ( 8 | :: echo --%1-- 9 | :: shift 10 | :: ) 11 | :: echo --%1-- 12 | :: 13 | :: gives following output 14 | :: 15 | :: --ich-- 16 | :: --ni-- 17 | :: --san-- 18 | :: --shi-- 19 | :: --go-- 20 | :: --roku-- 21 | :: 22 | :: the only way to access arguments in this case is using CALL 23 | :: http://ss64.org/viewtopic.php?id=1708 24 | 25 | @echo off 26 | for /l %%c in (1 ; 1 ; 5) do ( 27 | call echo --%%1-- 28 | shift 29 | ) 30 | echo --%1-- 31 | 32 | :: 33 | :: with delayed expansion 34 | :: 35 | 36 | setlocal enableDelayedExpansion 37 | set /a counter=0 38 | for /l %%x in (1 ; 1 ; 5) do ( 39 | set /a counter=!counter!+1 40 | call echo %%!counter! 41 | ) 42 | endlocal 43 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/callcolons.bat: -------------------------------------------------------------------------------- 1 | :: calling lables can be used like 2 | :: call ::label arguments 3 | 4 | @echo off 5 | 6 | call ::label 7 | echo -after- 8 | exit /b o 9 | :label 10 | echo printed 11 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/defaultJumpDir.bat: -------------------------------------------------------------------------------- 1 | :: For every drive there's dynamic environment variable 2 | :: that points to the last accessed directory e.g. : 3 | :: 4 | :: =D:=D:\someFolder 5 | :: 6 | :: defining same variable in-advance will 7 | :: allow direct jump to some directory by entering the drive 8 | :: (if directory does not exist it will print it as a message) 9 | :: This will not harm the command prompt. 10 | :: If different folder is entered the value of the variable will be changed durring the 11 | :: command prompt session. 12 | :: 13 | ::http://ss64.org/viewtopic.php?id=1559 14 | :: 15 | 16 | 17 | reg add HKCU\Environment /v "=D:" /d "Get out of here stalker" /f 18 | 19 | :: SETX won't allow defining variable starting with equal sign on every machine.So it's better to use REG 20 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/emptyTokens.bat: -------------------------------------------------------------------------------- 1 | :: http://stackoverflow.com/questions/25950181/why-for-f-sets-empty-values-for-repeated-numbers-in-the-rest-of-tokens 2 | 3 | :: For /f command set empty value for each requested token in options section 4 | :: Examples bellow 5 | 6 | :::this prints - 1:[i] 2:[] 3:[] 4:[] 5:[] 6:[] 7:[] 7 | for /f "tokens=1,1,1,1,1,1,1" %%a in ("i ii iii iv v vi vii") do ( 8 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 9 | ) 10 | 11 | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[iv] 5:[] 6:[] 7:[%g] 12 | for /f "tokens=2,3,1-4" %%a in ("i ii iii iv v vi vii") do ( 13 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 14 | ) 15 | 16 | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[] 5:[] 6:[] 7:[%g] 17 | for /f "tokens=1-3,1-3," %%a in ("i ii iii iv v vi vii") do ( 18 | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] 19 | ) 20 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/fileRedirection.bat: -------------------------------------------------------------------------------- 1 | ::Only the last file in the sequence will be affected.Not existing files will be not created 2 | echo #>a>b>c>d>e>f 3 | ::Info will be red only from the last file in the row.Not existing files will be ignored 4 | set /p="a"b"""c""" 7 | type abc 8 | set /p= can be used as number separators in for /L 6 | echo\ 7 | for /L %%A in (1;1=5) do echo %%A 8 | 9 | :: everyting except first three numbers will be igonred 10 | :: 1000 will be ignored 11 | 12 | for /L %%A in (1;1=5,1000) do echo %%A 13 | 14 | :: every string not containing numbers in the first three items will be taken as 0 15 | 16 | for /l %%a in (null ; 1 ; 5) do echo %%a 17 | 18 | :: if a string starts with figits only the starting number will be taken into accoung 19 | 20 | set BottleRum=13DeadMen 21 | 22 | for /l %%P in (%BottleRum% 1;%BottleRum%) do set DevilDozen=%%P 23 | 24 | echo %DevilDozen% 25 | echo Yo-Ho-Ho! 26 | 27 | :: http://ss64.org/viewtopic.php?id=1667 28 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/internal_commands.txt: -------------------------------------------------------------------------------- 1 | Two internal commands were re-"discovered" here: 2 | 3 | http://ss64.org/viewtopic.php?id=1558 4 | 5 | 6 | KEYS and DPATH 7 | 8 | 9 | DPATH help message points to APPEND command and is not useful at all. 10 | It's syntax is the same as PATH command.Later Carlos Mortinez discovered that 11 | TYPE command uses %DPATH% variable set by DPATH command and can print files in DPATH 12 | directories like there in the same directory.The same with input redirection: 13 | http://ss64.org/viewtopic.php?id=1876 14 | http://ss64.org/viewtopic.php?id=1875 15 | 16 | 17 | KEYS command message also is missleading - it claims that has no effect but sets a %KEYS% vaiable (ON or OFF) 18 | despite the command itself does not rely on the environment variable to check its status. 19 | 20 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/keys: -------------------------------------------------------------------------------- 1 | @echo off 2 | keys /? 3 | set "keys=" 4 | keys off 5 | echo %keys% 6 | set "keys=" 7 | keys 8 | 9 | exit /b 0 10 | 11 | ::==== 12 | demonstrates the effects of keys command. 13 | I've mentioned the command here http://ss64.org/viewtopic.php?id=1558 14 | and later in the thread Dave Benham discovered that the command sets an environemnt 15 | variable , which means that the help message is wrong - it affects the current console. 16 | Keys does not relly on %keys% variable to display its state correctly 17 | ::===== 18 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/msg.txt: -------------------------------------------------------------------------------- 1 | http://ss64.org/viewtopic.php?id=2075 2 | Some tests I've made over MSG command (aware that you need installed terminal services to make this command available) showed that there are some special characters that cannot be set at the beginning of the message ( / and - ): 3 | msg "%username%" "--#" 4 | msg "%username%" "//#" 5 | both lines will print the help message . 6 | 7 | They can be esacped with \ (only the first appearance need to be escaped): 8 | msg "%username%" "\--#" 9 | msg "%username%" "\//#" 10 | 11 | it can be used also to put as message with quotes in : 12 | msg "%username%" "\"message with quotes\"" 13 | I havent found other special sequences that can be used with \ 14 | 15 | 16 | Max length of the symbols in the message is 255 17 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/negativeGOTO.bat: -------------------------------------------------------------------------------- 1 | :: Goto to not existing label exits the script and put in commpand prompt context 2 | :: so commands with negative conditional execution will be executed 3 | :: First I proposed using negative conditiontional execution here: 4 | :: http://stackoverflow.com/questions/23318951/how-to-treat-user-input-as-two-words-instead-of-one-in-batch 5 | :: later the user that I've answered to discovered that only the conditions on the same line will be executed: 6 | :: http://stackoverflow.com/questions/23327304/my-goto-redirect-is-not-working-but-works-with-echo 7 | :: Where jeb's found that the script goes to command prompt context 8 | :: And here I've found that the brackets and FOR contexts are not broken : 9 | :: http://www.dostips.com/forum/viewtopic.php?f=3&t=5928 10 | 11 | 12 | @echo off 13 | setlocal enableDelayedExpansion 14 | 15 | for /f "tokens=1,2,3" %%a in ("1 2 3 ") do ( 16 | set /a n=1+1 17 | goto :no_label_ >nul 2>&1 || break just fills the end of line 18 | echo brackets context is not broken 19 | echo( 20 | echo and so variables cannot be accessed 21 | set "n2=something else" 22 | echo -%n%- and -%n2%- 23 | echo but more delayed expansioon does not work --^> !n! :-( 24 | echo( 25 | echo and for context is not broken!!!! 26 | echo %%a--%%b--%%c 27 | echo pass a command line parameter to check the output of this: 28 | echo ~"%~1"~ 29 | 30 | ) 31 | echo never printed 32 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/plainfor: -------------------------------------------------------------------------------- 1 | @ 2 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/promptFeatures.txt: -------------------------------------------------------------------------------- 1 | Some undocumented prompt command features: 2 | (http://ss64.org/viewtopic.php?pid=7706#p7706) 3 | 4 | 5 | PROMPT - (Here I'll list some things ) 6 | 1.By default %PROMPT% variable is not defined (then prompt displays it's default value $P$G) 7 | 8 | 2.If %PROMPT% variable is defined or pre-set via registry deleting it will set again prompt to its default value. 9 | 10 | 3.PROMPT command is highly dependable on %PROMPT% variable and editing the variable will lead to the same results (e.g. SET "PROMPT=$P$G") 11 | 12 | 4. Everything after a dollar sign sequence that is not in the supported list ( $A $B $C $D $E $F $G $H $L $M $N $P $Q $S $T $V $_ $$ $+ ) will be ignored 13 | 14 | 5. Limitations for prompt length are 400 symbols in Windows XP and 511 from Vista and above . Hitting the limit also produces 15 | different results in XP/Vista and the fresher versions: 16 | 5.1.On XP it produces error message 17 | 5.2.On 7 and above it just only takes the first 511 symbols. 18 | 19 | On XP limitation can be worked-around by setting longer than 400 symbols value directly to PROMPT variable (For these I need clarification by more people so I'll start a separate thread) 20 | Special $-sequneces will be taken as a single symbol. 21 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/splitCommand.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: https://stackoverflow.com/a/64752041/388389 4 | :: Splits a long command into a few lines. 5 | :: Limitations are that some special symbols should be escaped (carets, closing brackets and etc.) 6 | 7 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 8 | set "{{=setlocal enableDelayedExpansion&for %%a in (" & set "}}="::end::" ) do if "%%~a" neq "::end::" (set command=!command! %%a) else (call !command! & endlocal)" 9 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 | 11 | :: Example: 12 | 13 | %{{% 14 | echo 15 | "command" 16 | written 17 | on a 18 | few lines 19 | %}}% 20 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/tasklist: -------------------------------------------------------------------------------- 1 | tasklist filters support wildcard (*) if it is put at the end -> 2 | http://stackoverflow.com/questions/36602024/regular-expression-or-wild-card-in-tasklist/36602530#36602530 3 | tasklist /FI "IMAGENAME eq cm*" 4 | 5 | 6 | And a double quotes can be escaped with \" unless they are not at the end. 7 | title "aa" 8 | tasklist /FI "WINDOWTITLE eq \"aa*" 9 | and backslash can be escaped with double backslash 10 | -------------------------------------------------------------------------------- /discovers_and_bugs/discovers/typeList.bat: -------------------------------------------------------------------------------- 1 | :: Type command accepts wildcards and file lists 2 | :: Every time when a wildcard or a list of more than one 3 | :: file is used it will print file names in StdErr 4 | :: even if a single file applies to the wildcard expression 5 | :: or the file list 6 | :: http://ss64.org/viewtopic.php?id=1794 7 | 8 | @echo off 9 | echo hello>lang.en 10 | echo holla>lang.es 11 | echo hallo>lang.de 12 | 13 | echo -- 14 | echo -- testing type lang.?? 15 | echo -- 16 | type lang.?? 17 | 18 | echo -- 19 | echo -- testing type lang* 2^>nul 20 | echo -- 21 | type lang* 2>nul 22 | 23 | echo -- 24 | echo -- testing type lang* ^>nul 25 | echo -- 26 | type lang?* >nul 27 | 28 | echo -- 29 | echo -- testimg more lang* 30 | echo -- 31 | more lang* 32 | 33 | exit /b 0 34 | 35 | 36 | :: the output is 37 | 38 | -- 39 | -- testing type lang.?? 40 | -- 41 | 42 | lang.de 43 | 44 | 45 | hallo 46 | 47 | lang.en 48 | 49 | 50 | hello 51 | 52 | lang.es 53 | 54 | 55 | holla 56 | -- 57 | -- testing type lang* 2>nul 58 | -- 59 | hallo 60 | hello 61 | holla 62 | -- 63 | -- testing type lang* >nul 64 | -- 65 | 66 | lang.de 67 | 68 | 69 | 70 | lang.en 71 | 72 | 73 | 74 | lang.es 75 | 76 | 77 | -- 78 | -- testimg more lang* 79 | -- 80 | hallo 81 | hello 82 | holla 83 | 84 | -------------------------------------------------------------------------------- /fileUtils/SHA512.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates SHA512 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "SHA512=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" SHA512') do ( 45 | if not defined SHA512 ( 46 | for %%Z in (%%#) do set "SHA512=!SHA512!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%SHA512%" 53 | ) 54 | ) else ( 55 | echo %SHA512% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/dirTimes.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | for %%# in (/h /help -h -help) do ( 4 | if "%~1" equ "%%#" ( 5 | (echo() 6 | echo %~nx0 - Displays LastModified,LastAccessed and DateCreated times of a given directory 7 | echo in format YYYYMMDDhhmmss 8 | (echo() 9 | echo example: 10 | echo call %~nx0 "C:\directory\" 11 | ) 12 | ) 13 | 14 | if "%~1" equ "" ( 15 | echo no directory passed 16 | exit /b 1 17 | ) 18 | 19 | if not exist "%~f1" ( 20 | echo directory "%~f1" does not exist 21 | exit /b 2 22 | ) 23 | 24 | if exist "%~f1\" if not exist "%~f1" ( 25 | echo "%~f1" is a file but not a directory 26 | exit /b 3 27 | ) 28 | 29 | set "dirname=%~f1" 30 | set dirname=%dirname:\=\\% 31 | echo directory timestamps for %~f1 : 32 | (echo() 33 | for /f "useback delims=." %%t in (`"WMIC path Win32_Directory WHERE name="%dirname%" get LastModified,CreationDate,LastAccessed /format:value"`) do ( 34 | for /f %%$ in ("%%t") do if "%%$" neq "" echo %%$ 35 | ) 36 | endlocal && ( 37 | exit /b %errorlevel% 38 | ) 39 | -------------------------------------------------------------------------------- /fileUtils/encodingDetect.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :detect_encoding 3 | setLocal 4 | if "%1" EQU "-?" ( 5 | endlocal 6 | call :help 7 | exit /b 0 8 | ) 9 | if "%1" EQU "-h" ( 10 | endlocal 11 | call :help 12 | exit /b 0 13 | ) 14 | if "%1" EQU "" ( 15 | endlocal 16 | call :help 17 | exit /b 0 18 | ) 19 | 20 | 21 | if not exist "%1" ( 22 | echo file does not exists 23 | endlocal 24 | exit /b 54 25 | ) 26 | 27 | if exist "%1\" ( 28 | echo this cannot be used against directories 29 | endlocal 30 | exit /b 53 31 | ) 32 | 33 | if "%~z1" EQU "0" ( 34 | echo empty files are not accepted 35 | endlocal 36 | exit /b 52 37 | ) 38 | 39 | 40 | 41 | set "file=%~snx1" 42 | del /Q /F "%file%.hex" >nul 2>&1 43 | 44 | certutil -f -encodehex %file% %file%.hex>nul 45 | 46 | rem -- find the first line of hex file -- 47 | 48 | for /f "usebackq delims=" %%E in ("%file%.hex") do ( 49 | set "f_line=%%E" > nul 50 | goto :enfdor 51 | ) 52 | :enfdor 53 | del /Q /F "%file%.hex" >nul 2>&1 54 | 55 | rem -- check the BOMs -- 56 | echo %f_line% | find "ef bb bf" >nul && echo utf-8 &&endlocal && exit /b 1 57 | echo %f_line% | find "ff fe 00 00" >nul && echo utf-32 LE &&endlocal && exit /b 5 58 | echo %f_line% | find "ff fe" >nul && echo utf-16 &&endlocal && exit /b 2 59 | echo %f_line% | find "fe ff 00" >nul && echo utf-16 BE &&endlocal && exit /b 3 60 | echo %f_line% | find "00 00 fe ff" >nul && echo utf-32 BE &&endlocal && exit /b 4 61 | 62 | echo ASCII & endlocal & exit /b 6 63 | 64 | 65 | 66 | endLocal 67 | goto :eof 68 | 69 | :help 70 | echo. 71 | echo %~n0 file - Detects encoding of a text file 72 | echo. 73 | echo for each encoding you will recive a text responce with a name and a errorlevel codes as follows: 74 | 75 | echo 1 - UTF-8 76 | echo 2 - UTF-16 BE 77 | echo 3 - UTF-16 LE 78 | echo 4 - UTF-32 BE 79 | echo 5 - UTF-32 LE 80 | echo 6 - ASCII 81 | 82 | echo for empty files you will receive error code 52 83 | echo for directories you will receive error code 53 84 | echo for not existing file you will receive error code 54 85 | goto :eof 86 | -------------------------------------------------------------------------------- /fileUtils/extInstaller: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: requires Admin permissions 3 | :: allows a files with .TEST (in this case ) extension to act like .bat/.cmd files. 4 | :: Will create a 'caller.bat' asociated with the extension 5 | :: which will create a temp .bat file on each call (you can consider this as cheating) 6 | :: and will call it. 7 | :: Have on mind that the %0 argument will be lost. 8 | 9 | 10 | rem :: "installing" a caller. 11 | if not exist "c:\caller.bat" ( 12 | echo @echo off 13 | echo copy "%%~nx1" "%%temp%%\%%~nx1.bat" /Y ^>nul 14 | echo "%%temp%%\%%~nx1.bat" %%* 15 | ) > c:\caller.bat 16 | 17 | rem :: associating file extension 18 | assoc .test=batps 19 | ftype batps=c:\caller "%1" %* 20 | -------------------------------------------------------------------------------- /fileUtils/file2hex.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :stringToHex 3 | del tmp.hex >nul 2>nul 4 | 5 | if "%~2" equ "" ( 6 | echo destination not given 7 | exit /b 10 8 | ) 9 | 10 | set "source=%~f1" 11 | set "destination=%~2" 12 | del "%destination%" >nul 2>&1 13 | 14 | if not exist "%source%" ( 15 | echo source file "%source%" does not exist 16 | exit /b 11 17 | ) 18 | 19 | certutil -encodehex "%source%" tmp.hex >nul 20 | setlocal enableDelayedExpansion 21 | set "hex_str=" 22 | for /f "usebackq tokens=2 delims= " %%A in ("tmp.hex") do ( 23 | set "line=%%A" 24 | set line=!line:~0,48! 25 | )>>"%destination%" 26 | del tmp.hex >nul 2>nul 27 | -------------------------------------------------------------------------------- /fileUtils/fileModifiedTime.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | for %%# in (/h /help -h -help) do ( 4 | if "%~1" equ "%%#" ( 5 | (echo() 6 | echo %~nx0 [rtnVar] - gets last modified time of a file in YYYY/MM/DD HH:mm:SS format 7 | echo rtnVar - optional variable name where the result will be stored 8 | (echo() 9 | echo example: 10 | echo call %~nx0 C:\file.ext lastModified 11 | ) 12 | ) 13 | 14 | if "%~1" equ "" ( 15 | echo no file passed 16 | exit /b 1 17 | ) 18 | 19 | if not exist "%~f1" ( 20 | echo file "%~f1" does not exist 21 | exit /b 2 22 | ) 23 | 24 | if exist "%~f1\" ( 25 | echo "%~f1" is a directory but not a file 26 | exit /b 3 27 | ) 28 | set "file_loc=%~f1" 29 | for %%# in ("%file_loc%") do set file_dir=%%~dp# 30 | for %%# in ("%file_loc%") do set file_name=%%~nx# 31 | pushd %file_dir% 32 | 33 | for /f "skip=2 tokens=1,2" %%a in ('robocopy "." "%temp%" /l /fat /ts /LEV:1 /NP /NC /NS /NJS /NJH /IF "%file_name%"') do ( 34 | echo last modified date of "%~f1" : 35 | echo %%a %%b 36 | set "fdate_time=%%a %%b" 37 | ) 38 | popd 39 | 40 | endlocal && ( 41 | if "%~2" neq "" set "%2=%fdate_time%" 42 | exit /b %errorlevel% 43 | ) 44 | -------------------------------------------------------------------------------- /fileUtils/fileTimes.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | for %%# in (/h /help -h -help) do ( 4 | if "%~1" equ "%%#" ( 5 | (echo() 6 | echo %~nx0 - Displays LastModified,LastAccessed and DateCreated times of a given file 7 | echo in format YYYYMMDDhhmmss 8 | (echo() 9 | echo example: 10 | echo call %~nx0 C:\file.ext 11 | ) 12 | ) 13 | 14 | if "%~1" equ "" ( 15 | echo no file passed 16 | exit /b 1 17 | ) 18 | 19 | if not exist "%~f1" ( 20 | echo file "%~f1" does not exist 21 | exit /b 2 22 | ) 23 | 24 | if exist "%~f1\" ( 25 | echo "%~f1" is a directory but not a file 26 | exit /b 3 27 | ) 28 | 29 | set "file_loc=%~f1" 30 | set file_loc=%file_loc:\=\\% 31 | echo file timestamps for %~f1 : 32 | (echo() 33 | for /f "useback delims=." %%t in (`"WMIC DATAFILE WHERE name="%file_loc%" get LastModified,CreationDate,LastAccessed /format:value"`) do ( 34 | for /f %%$ in ("%%t") do if "%%$" neq "" echo %%$ 35 | ) 36 | endlocal && ( 37 | exit /b %errorlevel% 38 | ) 39 | -------------------------------------------------------------------------------- /fileUtils/fileassembler.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if "%~1" EQU "" echo parameter not entered & exit /b 1 3 | set "parts=%~1.part" 4 | 5 | setlocal enableDelayedExpansion 6 | set numb=0 7 | for /f "delims=." %%P in ('dir /b %parts%*') do ( 8 | set /a numb=numb+1 9 | ) 10 | rem echo !numb! 11 | 12 | 13 | setlocal enableDelayedExpansion 14 | set "string=%~1.part.1" 15 | for /l %%n in (2;1;!numb!) do ( 16 | set "string=!string!+!parts!.%%n" 17 | ) 18 | rem echo !string! 19 | copy /y /b !string! %~1%~x1 20 | endlocal 21 | -------------------------------------------------------------------------------- /fileUtils/firstLines.bat: -------------------------------------------------------------------------------- 1 | 2 | 3 | break>"%temp%\empty"&&fc "%temp%\empty" "%file_to_process%" /lb X /t |more +4 | findstr /B /E /V "*****" 4 | 5 | rem comperatively brief way to show first N lines of a file 6 | rem will fail the file contains ***** and MORE command will replace tab characters (if any) with space 7 | rem http://stackoverflow.com/questions/27509846/batch-script-to-overwrite-a-file-with-first-5-lines 8 | -------------------------------------------------------------------------------- /fileUtils/firstLinesP.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableExtensions 3 | 4 | rem ------ validate parameters ------ 5 | :: parametrized version of batch.scripts/fileUtils/firstLiles.bat 6 | for %%H in ("/h" "-h" "-help" "/help") do if /I "%~1" EQU "%%~H" goto :help 7 | if "%~2" EQU "" goto :help 8 | if not exist "%~1" echo file does not exist && exit /b 3 9 | set /a "lines=%~2" 10 | if not defined lines echo pass a number bigger than 0 for the lines to be shown&&exit /b 1 11 | if defined lines if %lines%0 equ 0 echo pass a number bigger than 0 for the lines to be shown&&exit /b 2 12 | rem --------------------------------- 13 | 14 | ;break>"%temp%\empty" 15 | @@fc "%temp%\empty" "%~1" /lb %lines% /t |more +4 | findstr /B /E /V "*****" 16 | ;del /q /f "%temp%\empty" 17 | 18 | goto :eof 19 | endlocal 20 | 21 | :help 22 | echo Displays first lines of a given file 23 | echo. 24 | echo %~n0 file lines 25 | echo. 26 | echo. 27 | echo lines Number of lines to display.Must be bigger than 0. 28 | echo file Specifies the file. 29 | :: 30 | :: by Vasil "npocmaka" Arnaudov 31 | :: 32 | -------------------------------------------------------------------------------- /fileUtils/folderOwner.bat: -------------------------------------------------------------------------------- 1 | :folderOwner 2 | @echo off 3 | 4 | set "folder=%%~1" 5 | 6 | for /f "tokens=* delims=" %%a in ("%folder%") do ( 7 | set "fpath=%%~pa" 8 | set "fname=%%~na" 9 | set "fdrive=%%~da" 10 | ) 11 | 12 | set "fpath=%fpath:\=\\%" 13 | 14 | for /f "usebackq tokens=* delims=" %%a in (`wmic path Win32_Directory where "path='%fpath%' and drive='%fdrive%' and filename='%fname%'" get CSName /format:value`) do ( 15 | for /f "tokens=* delims=" %%z in ("%%a") do ( 16 | 17 | if "%%z" neq "" ( 18 | set "%%z" 19 | ) 20 | ) 21 | ) 22 | 23 | echo %CSName% 24 | exit /b 0 25 | -------------------------------------------------------------------------------- /fileUtils/listFS.bat: -------------------------------------------------------------------------------- 1 | fltmc volumes | find ":" 2 | rem :: lists file system types (NTFS,FAT32,CDFS ..) on all drivres 3 | rem as fltmc utility is not listed in technet A-Z reference it's rather an example how can it be used 4 | rem requires less code than fsutil 5 | rem http://stackoverflow.com/questions/6995813/how-can-i-use-batch-to-determine-if-a-computer-is-using-fat32-or-ntfs 6 | -------------------------------------------------------------------------------- /fileUtils/md2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates MD2 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "MD2=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" MD2') do ( 45 | if not defined MD2 ( 46 | for %%Z in (%%#) do set "MD2=!MD2!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%MD2%" 53 | ) 54 | ) else ( 55 | echo %MD2% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/md4.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates MD4 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "MD4=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" MD4') do ( 45 | if not defined MD4 ( 46 | for %%Z in (%%#) do set "MD4=!MD4!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%MD4%" 53 | ) 54 | ) else ( 55 | echo %MD4% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/md5.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates MD5 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "md5=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" MD5') do ( 45 | if not defined md5 ( 46 | for %%Z in (%%#) do set "md5=!md5!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%md5%" 53 | ) 54 | ) else ( 55 | echo %md5% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/progressCopy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: Copies a single file with progress bar 4 | :: requires at least windows vista 5 | :: uses esentutl command 6 | :: http://ss64.org/viewtopic.php?id=1727 7 | 8 | rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 9 | 10 | rem Esentutl is a command that performs some operations over a special windows database files (e.g. restore point files) 11 | rem From Windows Vista and above it supports copy operation which has a progress bar and can be used on ordinary files: 12 | 13 | rem esentutl /y "FILE.EXT" /d"DEST.EXT" /o 14 | rem May be it is not completely reliable: 15 | 16 | rem If performed on arbitrary files, this operation may fail 17 | rem at the end of the file if its size is not sector-aligned. 18 | 19 | rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 | 21 | :progressCopy 22 | setlocal 23 | echo. 24 | for /f "skip=2 tokens=2,3 delims=. " %%V in ('esentutl /d#') do ( 25 | echo esentutl version %%V.%%W 26 | set /a "version=%%V%%W" 27 | goto :break 28 | ) 29 | :break 30 | color 31 | if defined version if %version%0 LSS 600 ( 32 | echo UNSUPORTED VERSION 33 | echo Lower than 6.0 34 | exit /b 3 35 | ) 36 | 37 | 38 | for %%H in ("/h" "-h" "-help" "/help") do ( 39 | if /I "%~1" EQU "%%~H" goto :help 40 | ) 41 | 42 | if "%~1" EQU "" ( 43 | goto :help 44 | ) 45 | set "source=%~1" 46 | 47 | if not exist "%source%" ( 48 | (echo() 49 | echo source file does not exist 50 | exit /b 2 51 | ) 52 | 53 | for %%F in ("/f" "/force") do ( 54 | if /I "%~3" EQU "%%~F" set "force=1" 55 | if /I "%~2" EQU "%%~F" set "force=1" && set "dest=%~nx1" 56 | ) 57 | 58 | if "%~2" NEQ "" ( 59 | if not defined dest set "dest=%~2" 60 | ) else ( 61 | if not defined dest set "dest=%~nx1" 62 | ) 63 | 64 | if exist "%dest%" if not defined force ( 65 | (echo() 66 | echo file already exist and force option is not set 67 | echo exit /b 1 68 | ) 69 | 70 | if exist "%dest%" if defined force ( 71 | (echo() 72 | echo file already exist and will be overwritten 73 | del /Q /F "%dest%" 74 | ) 75 | 76 | esentutl /y "%source%" /d"%dest%" /o 77 | endlocal 78 | goto :eof 79 | 80 | :help 81 | echo. 82 | echo Copying a file with a progress bar 83 | echo. 84 | echo. 85 | echo %~nx0 source [destination] [/force^|/f] 86 | echo. 87 | echo. 88 | echo source - path to the source file 89 | echo. 90 | echo destination - path to the destination file.If not 91 | echo defined it will be set to the current directory. 92 | echo. 93 | echo /force - overwrite the source file if exists 94 | echo. 95 | -------------------------------------------------------------------------------- /fileUtils/sha1.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates SHA1 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "SHA1=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" SHA1') do ( 45 | if not defined SHA1 ( 46 | for %%Z in (%%#) do set "SHA1=!SHA1!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%SHA1%" 53 | ) 54 | ) else ( 55 | echo %SHA1% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/sha256.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates SHA256 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "SHA256=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" SHA256') do ( 45 | if not defined SHA256 ( 46 | for %%Z in (%%#) do set "SHA256=!SHA256!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%SHA256%" 53 | ) 54 | ) else ( 55 | echo %SHA256% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/sha384.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | if "%~1" equ "" ( 4 | echo no file passed 5 | echo pass -help to see the help message 6 | exit /b 1 7 | ) 8 | 9 | for %%# in (-h -help /h /help) do ( 10 | if "%~1" equ "%%~#" ( 11 | echo generates SHA384 checksum for a given file 12 | (echo() 13 | echo USAGE: 14 | (echo() 15 | echo %~nx0 file [variable] 16 | (echo() 17 | echo variable string in which the generated checksum will be stored 18 | (echo() 19 | exit /b 0 20 | ) 21 | ) 22 | 23 | if not exist "%~1" ( 24 | echo file %~1 does not exist 25 | exit /b 2 26 | ) 27 | 28 | if exist "%~1\" ( 29 | echo %~1 is a directory 30 | exit /b 3 31 | ) 32 | 33 | for %%# in (certutil.exe) do ( 34 | if not exist "%%~f$PATH:#" ( 35 | echo no certutil installed 36 | echo for Windows XP professional and Windows 2003 37 | echo you need Windows Server 2003 Administration Tools Pack 38 | echo https://www.microsoft.com/en-us/download/details.aspx?id=3725 39 | exit /b 4 40 | ) 41 | ) 42 | 43 | set "SHA384=" 44 | for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" SHA384') do ( 45 | if not defined SHA384 ( 46 | for %%Z in (%%#) do set "SHA384=!SHA384!%%Z" 47 | ) 48 | ) 49 | 50 | if "%~2" neq "" ( 51 | endlocal && ( 52 | set "%~2=%SHA384%" 53 | ) 54 | ) else ( 55 | echo %SHA384% 56 | ) 57 | endlocal 58 | -------------------------------------------------------------------------------- /fileUtils/wmicVersion.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :wmicVersion pathToBinary [variableToSaveTo] 3 | setlocal 4 | set "item=%~1" 5 | set "item=%item:\=\\%" 6 | 7 | 8 | for /f "usebackq delims=" %%a in (`"WMIC DATAFILE WHERE name='%item%' get Version /format:Textvaluelist"`) do ( 9 | for /f "delims=" %%# in ("%%a") do set "%%#" 10 | ) 11 | 12 | if "%~2" neq "" ( 13 | endlocal & ( 14 | echo %version% 15 | set %~2=%version% 16 | ) 17 | ) else ( 18 | echo %version% 19 | ) 20 | -------------------------------------------------------------------------------- /hybrids/.net/bat2exe.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal 4 | 5 | del %~n0.exe /q /s >nul 2>nul 6 | 7 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 8 | set "jsc=%%v" 9 | ) 10 | 11 | if not exist "%~n0.exe" ( 12 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 13 | ) 14 | 15 | %~n0.exe "%jsc%" %* 16 | del /q /f %~n0.exe 1>nul 2>nul 17 | endlocal & exit /b %errorlevel% 18 | */ 19 | 20 | //https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/bat2exe.bat 21 | import System; 22 | import System; 23 | import System.IO; 24 | import System.Diagnostics; 25 | 26 | 27 | var arguments:String[] = Environment.GetCommandLineArgs(); 28 | if (arguments.length<3){ 29 | Console.WriteLine("Path to cmd\bat file not given"); 30 | Environment.Exit(1); 31 | } 32 | 33 | var binName=Path.GetFileName(arguments[2])+".exe"; 34 | if(arguments.length>3){ 35 | binName=Path.GetFileName(arguments[3]); 36 | } 37 | var batchContent:byte[]= File.ReadAllBytes(arguments[2]); 38 | var compilerLoc=arguments[1]; 39 | 40 | var content="[" 41 | 42 | for (var i=0;inul||@goto :batch 2 | /* 3 | :batch 4 | @echo off 5 | setlocal 6 | 7 | :: find csc.exe 8 | set "csc=" 9 | for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do set "csc=%%#" 10 | 11 | if not exist "%csc%" ( 12 | echo no .net framework installed 13 | exit /b 10 14 | ) 15 | 16 | if not exist "%~n0.exe" ( 17 | call %csc% /nologo /warn:0 /out:"%~n0.exe" "%~dpsfnx0" || ( 18 | exit /b %errorlevel% 19 | ) 20 | ) 21 | %~n0.exe %* 22 | endlocal & exit /b %errorlevel% 23 | 24 | */ 25 | 26 | 27 | 28 | 29 | 30 | 31 | using System; 32 | using System.Drawing; 33 | using System.Runtime.InteropServices; 34 | 35 | public class Win32 36 | { 37 | [DllImport("user32.dll")] 38 | static extern IntPtr GetDC(IntPtr hwnd); 39 | 40 | [DllImport("user32.dll")] 41 | static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); 42 | 43 | [DllImport("gdi32.dll")] 44 | static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); 45 | 46 | static public System.Drawing.Color GetPixelColor(int x, int y) 47 | { 48 | IntPtr hdc = GetDC(IntPtr.Zero); 49 | uint pixel = GetPixel(hdc, x, y); 50 | ReleaseDC(IntPtr.Zero, hdc); 51 | Color color = Color.FromArgb((int)(pixel & 0x000000FF), 52 | (int)(pixel & 0x0000FF00) >> 8, 53 | (int)(pixel & 0x00FF0000) >> 16); 54 | return color; 55 | } 56 | 57 | public static void Main(string[] args) 58 | { 59 | int X= Int32.Parse(args[0]); 60 | int Y=Int32.Parse(args[1]); 61 | System.Console.WriteLine(GetPixelColor(X,Y)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /hybrids/.net/checkPortJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* 2 | @echo off 3 | setlocal 4 | del %~n0.exe /q /s >nul 2>nul 5 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 6 | set "jsc=%%v" 7 | ) 8 | if not exist "%~n0.exe" ( 9 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 10 | ) 11 | %~n0.exe %* 12 | ::del /q /f %~n0.exe 1>nul 2>nul 13 | endlocal & exit /b %errorlevel% 14 | */ 15 | 16 | import System; 17 | import System.Net.Sockets; 18 | 19 | var arguments:String[] = Environment.GetCommandLineArgs(); 20 | if (arguments.length<3){ 21 | Console.WriteLine("not enough arguments"); 22 | Environment.Exit(1); 23 | } 24 | 25 | var host=arguments[1]; 26 | try { 27 | var port=Int32.Parse(arguments[2]); 28 | } catch (err) { 29 | Console.WriteLine("Cannot convert " + arguments[1] + " to number"); 30 | Environment.Exit(2); 31 | } 32 | 33 | Console.WriteLine("Checking host {0} and port {1}",host,port); 34 | 35 | var client = new TcpClient(); 36 | 37 | try { 38 | client.Connect(host, port); 39 | } catch(err) { 40 | Console.WriteLine("Closed"); 41 | Environment.Exit(0); 42 | } 43 | client.Close(); 44 | Console.WriteLine("Open"); 45 | -------------------------------------------------------------------------------- /hybrids/.net/dirTimesNET.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /****** silent line that start jscript comment ****** 2 | 3 | @echo off 4 | :::::::::::::::::::::::::::::::::::: 5 | ::: compile the script :::: 6 | :::::::::::::::::::::::::::::::::::: 7 | setlocal 8 | if exist "%~n0.exe" goto :skip_compilation 9 | 10 | setlocal 11 | 12 | :: find csc.exe 13 | set "jsc=" 14 | for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*jsc.exe") do set "jsc=%%#" 15 | 16 | if not exist "%jsc%" ( 17 | echo no .net framework installed 18 | exit /b 10 19 | ) 20 | 21 | :break_loop 22 | 23 | 24 | call %jsc% /nologo /out:"%~n0.exe" "%~f0" 25 | :::::::::::::::::::::::::::::::::::: 26 | ::: end of compilation :::: 27 | :::::::::::::::::::::::::::::::::::: 28 | :skip_compilation 29 | 30 | 31 | 32 | for %%# in (/h /help -h -help) do ( 33 | if "%~1" equ "%%#" ( 34 | (echo() 35 | echo %~nx0 - Displays LastModified,LastAccessed and DateCreated times of a given directory 36 | echo in format YYYY-MM-DD hh:mm:ss , the thichs since 0:00:00 UTC on January 1, 0001 , day of the week 37 | (echo() 38 | echo example: 39 | echo call %~nx0 C:\file.ext 40 | ) 41 | ) 42 | 43 | if "%~1" equ "" ( 44 | echo no directory passed 45 | exit /b 1 46 | ) 47 | 48 | if not exist "%~f1" ( 49 | echo directory "%~f1" does not exist 50 | exit /b 2 51 | ) 52 | 53 | if exist "%~f1\" if not exist "%~f1" ( 54 | echo "%~f1" is a file but not a directory 55 | exit /b 3 56 | ) 57 | 58 | (echo() 59 | echo directory timestamps for %~f1 : 60 | (echo() 61 | 62 | 63 | "%~n0.exe" "%~f1" 64 | 65 | exit /b 0 66 | 67 | 68 | ****** end of jscript comment ******/ 69 | import System; 70 | import System.IO; 71 | 72 | var arguments:String[] = Environment.GetCommandLineArgs(); 73 | 74 | function printDateInfo(timeTag,dt){ 75 | Console.WriteLine( timeTag + " : " + dt.ToString("yyyy-MM-dd hh:mm:ss")); 76 | Console.WriteLine(timeTag + " thicks : " + dt.Ticks); 77 | Console.WriteLine( timeTag + " day of the week : " + dt.DayOfWeek); 78 | Console.WriteLine( timeTag + " day of the year : " + dt.DayOfYear); 79 | Console.WriteLine(); 80 | } 81 | 82 | var modified_date= Directory.GetLastWriteTime(Environment.GetCommandLineArgs()[1]); 83 | var creation_date= Directory.GetCreationTime(Environment.GetCommandLineArgs()[1]); 84 | var accessed_date= Directory.GetLastAccessTime(Environment.GetCommandLineArgs()[1]); 85 | 86 | printDateInfo("Modified",modified_date); 87 | printDateInfo("Created",creation_date); 88 | printDateInfo("Accessed",accessed_date); 89 | -------------------------------------------------------------------------------- /hybrids/.net/fileTimesNET.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /****** silent line that start jscript comment ****** 2 | 3 | @echo off 4 | :::::::::::::::::::::::::::::::::::: 5 | ::: compile the script :::: 6 | :::::::::::::::::::::::::::::::::::: 7 | setlocal 8 | if exist "%~n0.exe" goto :skip_compilation 9 | 10 | setlocal 11 | 12 | :: find csc.exe 13 | set "jsc=" 14 | for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*jsc.exe") do set "jsc=%%#" 15 | 16 | if not exist "%jsc%" ( 17 | echo no .net framework installed 18 | exit /b 10 19 | ) 20 | 21 | :break_loop 22 | 23 | 24 | call %jsc% /nologo /out:"%~n0.exe" "%~f0" 25 | :::::::::::::::::::::::::::::::::::: 26 | ::: end of compilation :::: 27 | :::::::::::::::::::::::::::::::::::: 28 | :skip_compilation 29 | 30 | 31 | 32 | for %%# in (/h /help -h -help) do ( 33 | if "%~1" equ "%%#" ( 34 | (echo() 35 | echo %~nx0 - Displays LastModified,LastAccessed and DateCreated times of a given file 36 | echo in format YYYY-MM-DD hh:mm:ss , the thichs since 0:00:00 UTC on January 1, 0001 , day of the week 37 | (echo() 38 | echo example: 39 | echo call %~nx0 C:\file.ext 40 | ) 41 | ) 42 | 43 | if "%~1" equ "" ( 44 | echo no file passed 45 | exit /b 1 46 | ) 47 | 48 | if not exist "%~f1" ( 49 | echo file "%~f1" does not exist 50 | exit /b 2 51 | ) 52 | 53 | if exist "%~f1\" ( 54 | echo "%~f1" is a directory but not a file 55 | exit /b 3 56 | ) 57 | (echo() 58 | echo file timestamps for %~f1 : 59 | (echo() 60 | 61 | 62 | "%~n0.exe" "%~f1" 63 | 64 | exit /b 0 65 | 66 | 67 | ****** end of jscript comment ******/ 68 | import System; 69 | import System.IO; 70 | 71 | var arguments:String[] = Environment.GetCommandLineArgs(); 72 | 73 | function printDateInfo(timeTag,dt){ 74 | Console.WriteLine( timeTag + " : " + dt.ToString("yyyy-MM-dd hh:mm:ss")); 75 | Console.WriteLine(timeTag + " thicks : " + dt.Ticks); 76 | Console.WriteLine( timeTag + " day of the week : " + dt.DayOfWeek); 77 | Console.WriteLine( timeTag + " day of the year : " + dt.DayOfYear); 78 | Console.WriteLine(); 79 | } 80 | 81 | var modified_date= File.GetLastWriteTime(Environment.GetCommandLineArgs()[1]); 82 | var creation_date= File.GetCreationTime(Environment.GetCommandLineArgs()[1]); 83 | var accessed_date= File.GetLastAccessTime(Environment.GetCommandLineArgs()[1]); 84 | 85 | printDateInfo("Modified",modified_date); 86 | printDateInfo("Created",creation_date); 87 | printDateInfo("Accessed",accessed_date); 88 | -------------------------------------------------------------------------------- /hybrids/.net/getCmdPID.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal 4 | 5 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 6 | set "jsc=%%v" 7 | ) 8 | 9 | 10 | if not exist "%~n0.exe" ( 11 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 12 | ) 13 | 14 | %~n0.exe 15 | 16 | ::pause 17 | endlocal & exit /b %errorlevel% 18 | 19 | */ 20 | 21 | //http://stackoverflow.com/questions/2531837/how-can-i-get-the-pid-of-the-parent-process-of-my-application 22 | import System; 23 | import System.Diagnostics; 24 | import System.ComponentModel; 25 | import System.Management; 26 | 27 | var myId = Process.GetCurrentProcess().Id; 28 | var query = String.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", myId); 29 | var search = new ManagementObjectSearcher("root\\CIMV2", query); 30 | var results = search.Get().GetEnumerator(); 31 | if (!results.MoveNext()) { 32 | Console.WriteLine("Error"); 33 | Environment.Exit(-1); 34 | } 35 | var queryObj = results.Current; 36 | var parentId = queryObj["ParentProcessId"]; 37 | var parent = Process.GetProcessById(parentId); 38 | Console.WriteLine(parent.Id); 39 | Environment.Exit(parent.Id); 40 | -------------------------------------------------------------------------------- /hybrids/.net/keyStates.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal 4 | 5 | set "jsc=" 6 | for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*jsc.exe") do set "jsc=%%#" 7 | 8 | if not exist "%jsc%" ( 9 | echo no .net framework installed 10 | exit /b 10 11 | ) 12 | 13 | 14 | ::if not exist "%~n0.exe" ( 15 | call "%jsc%" /r:"System.Windows.Forms.dll" /nologo /out:"%~n0.exe" "%~dpsfnx0"||( 16 | exit /b %errorlevel% 17 | ) 18 | ::) 19 | 20 | "%~n0.exe" 21 | 22 | endlocal & exit /b %errorlevel% 23 | 24 | */ 25 | 26 | import System; 27 | import Accessibility; 28 | import System.Windows.Forms; 29 | import System.Drawing; 30 | 31 | var caps="CAPS LOCK : OFF"; 32 | var num="NUM LOCK : OFF"; 33 | var scroll="SCROLL LOCK : OFF" 34 | 35 | if (Control.IsKeyLocked(Keys.CapsLock)) { 36 | caps="CAPS LOCK : ON"; 37 | } 38 | 39 | if (Control.IsKeyLocked(Keys.NumLock)) { 40 | caps="NUM LOCK : ON"; 41 | } 42 | 43 | if (Control.IsKeyLocked(Keys.Scroll)) { 44 | caps="SCROL LLOCK : ON"; 45 | } 46 | 47 | 48 | Console.WriteLine(caps); 49 | Console.WriteLine(num); 50 | Console.WriteLine(scroll); 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /hybrids/.net/keyreader.bat: -------------------------------------------------------------------------------- 1 | @if(@X) == (@Y) @end /* JScript comment 2 | @echo off 3 | :: reads a single key stroke and exits with its ascii code. 4 | setlocal enableDelayedExpansion 5 | 6 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 7 | set "jsc=%%v" 8 | ) 9 | 10 | if not exist "%~n0.exe" ( 11 | rem del /q /f "%~n0.exe" >nul 2>&1 12 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 13 | ) 14 | %~n0.exe %* 15 | exit /b %errorlevel% 16 | 17 | */ 18 | 19 | //http://stackoverflow.com/questions/57615/how-to-add-a-timeout-to-console-readline 20 | import System; 21 | import System.Threading; 22 | 23 | 24 | class Reader { 25 | static var inputThread; 26 | static var getInput, gotInput; 27 | static var input; 28 | 29 | function Reader() { 30 | getInput = new AutoResetEvent(false); 31 | gotInput = new AutoResetEvent(false); 32 | inputThread = new Thread(ThreadStart(Reader.reader)); 33 | inputThread.IsBackground = true; 34 | inputThread.Start(); 35 | } 36 | 37 | static function reader() { 38 | while (true) { 39 | try { 40 | getInput.WaitOne(); 41 | input = Console.ReadKey(); 42 | gotInput.Set(); 43 | } catch (err) { 44 | var key = Console.Read(); 45 | Environment.Exit(key); 46 | } 47 | } 48 | } 49 | 50 | function ReadKey(timeOutMillisecs: int) { 51 | getInput.Set(); 52 | var success = gotInput.WaitOne(timeOutMillisecs); 53 | if (success) { 54 | Environment.Exit(input.KeyChar.ToString().charCodeAt(0)); 55 | } else { 56 | Environment.Exit(-2); 57 | } 58 | } 59 | } 60 | 61 | var arguments: String[] = Environment.GetCommandLineArgs(); 62 | if (arguments.length == 1) { 63 | try { 64 | var key = Console.ReadKey(true); 65 | Environment.Exit(key.KeyChar.ToString().charCodeAt(0)); 66 | } catch (err) { 67 | var key = Console.Read(); 68 | Environment.Exit(key); 69 | } 70 | } else { 71 | if (arguments[1] == "/?" || arguments[1].toLowerCase().ToLower().Contains("help")) { 72 | print("Usage:"); 73 | print(" " + arguments[0] + " [timeout-in-milliseconds]"); 74 | print(" reads a key and exits with its ascii code"); 75 | print(" if a timeout is passed it will wait for input and if no key is pressed it will return -2"); 76 | } else { 77 | try { 78 | var to = Int32.Parse(arguments[1]); 79 | var rdr = new Reader(); 80 | rdr.ReadKey(to); 81 | } catch (err) { 82 | try { 83 | print("no valid number passed as timeout"); 84 | var key = Console.ReadKey(true); 85 | Environment.Exit(key.KeyChar.ToString().charCodeAt(0)); 86 | } catch (err) { 87 | var key = Console.Read(); 88 | Environment.Exit(key); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /hybrids/.net/listEncodings.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /****** jscript comment ****** 2 | 3 | @echo off 4 | :::::::::::::::::::::::::::::::::::: 5 | ::: compile the script :::: 6 | :::::::::::::::::::::::::::::::::::: 7 | setlocal 8 | 9 | if exist "%~n0.exe" goto :skip_compilation 10 | 11 | :: searching the latest installed .net framework 12 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do ( 13 | if exist "%%v\jsc.exe" ( 14 | rem :: the javascript.net compiler 15 | set "jsc=%%~dpsnfxv\jsc.exe" 16 | goto :break_loop 17 | ) 18 | ) 19 | echo jsc.exe not found && exit /b 0 20 | :break_loop 21 | 22 | 23 | call %jsc% /nologo /out:"%~n0.exe" "%~nx0" 24 | :::::::::::::::::::::::::::::::::::: 25 | ::: end of compilation :::: 26 | :::::::::::::::::::::::::::::::::::: 27 | :skip_compilation 28 | 29 | :: 30 | :::::::::: 31 | "%~n0.exe" 32 | :::::::: 33 | :: 34 | 35 | exit /b 0 36 | 37 | ## http://msdn.microsoft.com/en-us/library/system.text.encoding.getencodings.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2 38 | ## 39 | ****** end of jscript comment ******/ 40 | 41 | import System; 42 | import System.Text; 43 | 44 | Console.Write( "CodePage identifier and name " ); 45 | Console.Write( "BrDisp BrSave " ); 46 | Console.Write( "MNDisp MNSave " ); 47 | Console.WriteLine( "1-Byte ReadOnly " ); 48 | 49 | var ei= new Object(); 50 | var encs=new Enumerator(Encoding.GetEncodings()); 51 | 52 | while(!encs.atEnd()) { 53 | var enc=encs.item(); 54 | var e=enc.GetEncoding(); 55 | 56 | Console.Write( "{0,-6} {1,-25} ", enc.CodePage, enc.Name ); 57 | Console.Write( "{0,-8} {1,-8} ", e.IsBrowserDisplay, e.IsBrowserSave ); 58 | Console.Write( "{0,-8} {1,-8} ", e.IsMailNewsDisplay, e.IsMailNewsSave ); 59 | Console.WriteLine( "{0,-8} {1,-8} ", e.IsSingleByte, e.IsReadOnly ); 60 | 61 | encs.moveNext(); 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /hybrids/.net/msbuild/checkPort.bat: -------------------------------------------------------------------------------- 1 | 41 | 42 | 43 | 44 | <_/> 45 | 46 | 47 | 48 | 49 | 50 | 51 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /hybrids/.net/passHidder.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal enableDelayedExpansion 4 | 5 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 6 | set "jsc=%%v" 7 | ) 8 | 9 | if not exist "%~n0.exe" ( 10 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 11 | ) 12 | 13 | for /f "tokens=* delims=" %%p in ('"%~n0.exe"') do ( 14 | set "pass=%%p" 15 | ) 16 | 17 | echo your password is !pass! 18 | 19 | endlocal & exit /b %errorlevel% 20 | 21 | */ 22 | 23 | 24 | 25 | import System; 26 | 27 | 28 | 29 | var pwd = ""; 30 | var key; 31 | 32 | Console.Error.Write("Enter password: "); 33 | 34 | do { 35 | key = Console.ReadKey(true); 36 | 37 | if ( (key.KeyChar.ToString().charCodeAt(0)) >= 20 && (key.KeyChar.ToString().charCodeAt(0) <= 126) ) { 38 | pwd=pwd+(key.KeyChar.ToString()); 39 | Console.Error.Write("*"); 40 | } 41 | 42 | if ( key.Key == ConsoleKey.Backspace && pwd.Length > 0 ) { 43 | pwd=pwd.Remove(pwd.Length-1); 44 | Console.Error.Write("\b \b"); 45 | } 46 | 47 | 48 | } while (key.Key != ConsoleKey.Enter); 49 | Console.Error.WriteLine(); 50 | Console.WriteLine(pwd); 51 | -------------------------------------------------------------------------------- /hybrids/.net/powershell/checkRemotePort.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | for %%h in (/h /help -help -h "") do ( 4 | if /I "%~1" equ "%%~h" ( 5 | goto :printHelp 6 | ) 7 | ) 8 | 9 | if "%~2" equ "" goto :printHelp 10 | 11 | set "HOST=%~1" 12 | set /a PORT=%~2 13 | 14 | set "host=google.com" 15 | set /a port=443 16 | 17 | for /f %%a in ('powershell "$t = New-Object Net.Sockets.TcpClient;try{$t.Connect("""%HOST%""", %PORT%)}catch{};$t.Connected"') do set "open=%%a" 18 | 19 | if "%open%" equ "true" ( 20 | echo open 21 | endlocal & exit /b 0 22 | ) else ( 23 | echo closed 24 | endlocal & exit /b 1 25 | ) 26 | 27 | 28 | :printHelp 29 | echo Checks if port is open on a remote server 30 | echo( 31 | echo Usage: 32 | echo %~nx0 host port 33 | echo( 34 | echo If the port is not accessible an errorlevel 1 is set 35 | endlocal & exit /b 0 36 | -------------------------------------------------------------------------------- /hybrids/.net/powershell/enterNumber.bat: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @echo off & setlocal 3 | 4 | for /f "tokens=*" %%a in ('powershell -noprofile "iex (${%~f0} | out-string)"') do set "number=%%a" 5 | echo you've entered %number% 6 | 7 | endlocal 8 | goto :EOF 9 | 10 | : end batch / begin powershell #> 11 | 12 | do { 13 | [Console]::Error.Write("Enter a number:") 14 | $inputString = read-host 15 | $value = $inputString -as [Double] 16 | $ok = $value -ne $NULL 17 | if ( -not $ok ) {[Console]::Error.WriteLine("You must enter a numeric value") } 18 | } 19 | until ( $ok ) 20 | 21 | write-host "$value" 22 | -------------------------------------------------------------------------------- /hybrids/.net/selectFolder.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | :: FolderSelectorJS.bat 5 | setlocal 6 | 7 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 8 | set "jsc=%%v" 9 | ) 10 | 11 | if not exist "%~n0.exe" ( 12 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 13 | ) 14 | 15 | for /f "tokens=* delims=" %%p in ('"%~n0.exe"') do ( 16 | set "folder=%%p" 17 | ) 18 | if not "%folder%" == "" ( 19 | echo selected folder is %folder% 20 | ) 21 | 22 | endlocal & exit /b %errorlevel% 23 | 24 | */ 25 | 26 | import System; 27 | import System.Windows.Forms; 28 | 29 | var f=new FolderBrowserDialog(); 30 | f.SelectedPath=System.Environment.CurrentDirectory; 31 | f.Description="Please choose a folder."; 32 | f.ShowNewFolderButton=true; 33 | if( f.ShowDialog() == DialogResult.OK ){ 34 | Console.Write(f.SelectedPath); 35 | } 36 | -------------------------------------------------------------------------------- /hybrids/.net/setPrio.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | setlocal 5 | 6 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 7 | set "jsc=%%v" 8 | ) 9 | 10 | if not exist "%~n0.exe" ( 11 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 12 | ) 13 | 14 | "%~n0.exe" %* 15 | del "%~n0.exe" 16 | 17 | endlocal & exit /b %errorlevel% 18 | 19 | end of jscript comment*/ 20 | 21 | import System; 22 | import System.Threading; 23 | import System.Diagnostics; 24 | 25 | var arguments:String[] = Environment.GetCommandLineArgs(); 26 | 27 | function printHelp( ) { 28 | print(arguments[0] + " pid prio"); 29 | 30 | } 31 | 32 | if ( arguments.length == 1 || arguments[1].toLowerCase() == "-h" || arguments[1].toLowerCase() == "-help" ) { 33 | printHelp(); 34 | Environment.Exit(0); 35 | } 36 | 37 | if ( arguments.length != 3) { 38 | print("wrong number of arguments"); 39 | Environment.Exit(1); 40 | } 41 | 42 | try { 43 | var pid= Int32.Parse(arguments[1]); 44 | }catch(err){ 45 | print("process must be a number"); 46 | Environment.Exit(2); 47 | } 48 | 49 | var prio=arguments[2].toLowerCase(); 50 | var proc=""; 51 | try{ 52 | proc=Process.GetProcessById(pid); 53 | }catch(err){ 54 | print("process " + pid + " not found"); 55 | Environment.Exit(3); 56 | } 57 | 58 | switch(prio) { 59 | case "abovenormal": 60 | proc.PriorityClass = ProcessPriorityClass.AboveNormal; 61 | break; 62 | case "belownormal": 63 | proc.PriorityClass = ProcessPriorityClass.AboveNormal; 64 | break; 65 | case "high": 66 | proc.PriorityClass = ProcessPriorityClass.High; 67 | break; 68 | case "idle": 69 | proc.PriorityClass = ProcessPriorityClass.Idle; 70 | break; 71 | case "normal": 72 | proc.PriorityClass = ProcessPriorityClass.Normal; 73 | break; 74 | case "realTime": 75 | proc.PriorityClass = ProcessPriorityClass.RealTime; 76 | break; 77 | default: 78 | print("invalid prio: " + prio + " given"); 79 | Environment.Exit(5); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /hybrids/.net/split.net.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal 4 | 5 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 6 | set "jsc=%%v" 7 | ) 8 | 9 | if not exist "%~n0.exe" ( 10 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 11 | ) 12 | 13 | %~n0.exe %* 14 | 15 | endlocal & exit /b %errorlevel% 16 | 17 | */ 18 | 19 | import System; 20 | import System.IO; 21 | 22 | var arguments:String[] = Environment.GetCommandLineArgs(); 23 | 24 | if (arguments.length<3){ 25 | Console.WriteLine("Wrong arguments"); 26 | Console.WriteLine("usage:"); 27 | Console.WriteLine(arguments[0]+"file_to_split size_in_bytes"); 28 | Environment.Exit(1); 29 | } 30 | 31 | var file=arguments[1]; 32 | var max_size=parseInt(arguments[2]); 33 | 34 | if (max_size<=0){ 35 | Console.WriteLine("size must be bigger than zero"); 36 | Environment.Exit(2); 37 | } 38 | 39 | if (!File.Exists(file)){ 40 | Console.WriteLine("file"+file+" does not exist"); 41 | Environment.Exit(3); 42 | } 43 | 44 | function writeData(file,data:byte[]){ 45 | Console.WriteLine(data.Length); 46 | var writer = new BinaryWriter(File.Open(file, FileMode.Create)); 47 | writer.Write(data); 48 | writer.Close(); 49 | } 50 | 51 | function chunker(inputFile, chunkSize){ 52 | 53 | var part=0; 54 | var reader= new BinaryReader(File.Open(inputFile, FileMode.Open)); 55 | var data:byte[]=reader.ReadBytes(chunkSize); 56 | 57 | while(reader.BaseStream.Position !== reader.BaseStream.Length) { 58 | part++; 59 | Console.WriteLine("Processing part " + part); 60 | writeData(inputFile+".part."+part,data); 61 | data=reader.ReadBytes(chunkSize); 62 | 63 | } 64 | if (data.Length !== 0) { 65 | part++; 66 | Console.WriteLine("Processing part " + part) 67 | writeData(inputFile+".part."+part,data); 68 | } 69 | reader.Close(); 70 | } 71 | 72 | chunker(file,max_size); 73 | -------------------------------------------------------------------------------- /hybrids/.net/systemSounds.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | setlocal 5 | 6 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 7 | set "jsc=%%v" 8 | ) 9 | 10 | if not exist "%~n0.exe" ( 11 | "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0" 12 | ) 13 | 14 | "%~n0.exe" %* 15 | 16 | 17 | endlocal & exit /b %errorlevel% 18 | 19 | end oj jscript comment*/ 20 | 21 | import System; 22 | import System.Media; 23 | import System.Threading; 24 | 25 | 26 | var arguments:String[] = Environment.GetCommandLineArgs(); 27 | 28 | function printHelp( ) { 29 | print(arguments[0] + " [beep] [asterisk] [hand] [beep] [question]"); 30 | 31 | } 32 | 33 | if ( arguments.length == 1 || arguments[1].toLowerCase() == "-h" || arguments[1].toLowerCase() == "-help" ) { 34 | printHelp(); 35 | Environment.Exit(0); 36 | } 37 | 38 | 39 | 40 | for (var arg = 1; arg <= arguments.length-1; arg++ ) { 41 | 42 | if ( arguments[arg].toLowerCase() == "beep" ) { 43 | SystemSounds.Beep.Play(); 44 | System.Threading.Thread.Sleep(300); 45 | } 46 | 47 | if ( arguments[arg].toLowerCase() == "asterisk" ) { 48 | SystemSounds.Asterisk.Play(); 49 | System.Threading.Thread.Sleep(300); 50 | } 51 | 52 | if ( arguments[arg].toLowerCase() == "exclamation" ) { 53 | SystemSounds.Exclamation.Play(); 54 | System.Threading.Thread.Sleep(300); 55 | } 56 | 57 | if ( arguments[arg].toLowerCase() == "hand" ) { 58 | SystemSounds.Hand.Play(); 59 | System.Threading.Thread.Sleep(300); 60 | } 61 | 62 | if ( arguments[arg].toLowerCase() == "question" ) { 63 | SystemSounds.Question.Play(); 64 | System.Threading.Thread.Sleep(300); 65 | } 66 | 67 | } 68 | 69 | 70 | /* 71 | Asterisk 72 | Beep 73 | Exclamation 74 | Hand 75 | Question 76 | */ 77 | -------------------------------------------------------------------------------- /hybrids/.net/waitMS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | setlocal 4 | ::del %~n0.exe /q /f 5 | :: 6 | :: For precision better call this like 7 | :: call waitMS 500 8 | :: in order to skip compilation in case there's already built .exe 9 | :: as without pointed extension first the .exe will be called due to the ordering in PATEXT variable 10 | :: 11 | :: 12 | for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do ( 13 | set "jsc=%%v" 14 | ) 15 | 16 | if not exist "%~n0.exe" ( 17 | "%jsc%" /nologo /w:0 /out:"%~n0.exe" "%~dpsfnx0" 18 | ) 19 | 20 | 21 | %~n0.exe %* 22 | 23 | endlocal & exit /b %errorlevel% 24 | 25 | 26 | */ 27 | 28 | 29 | import System; 30 | import System.Threading; 31 | 32 | var arguments:String[] = Environment.GetCommandLineArgs(); 33 | function printHelp(){ 34 | Console.WriteLine(arguments[0]+" N"); 35 | Console.WriteLine(" N - milliseconds to wait"); 36 | Environment.Exit(0); 37 | } 38 | 39 | if(arguments.length<2){ 40 | printHelp(); 41 | } 42 | 43 | try{ 44 | var wait:Int32=Int32.Parse(arguments[1]); 45 | System.Threading.Thread.Sleep(wait); 46 | }catch(err){ 47 | Console.WriteLine('Invalid Number passed'); 48 | Environment.Exit(1); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /hybrids/iexpress/OKPopup.bat: -------------------------------------------------------------------------------- 1 | ;@echo off 2 | ;setlocal 3 | 4 | ;set ppopup_executable=popupe.exe 5 | ;set "message2=click OK to continue" 6 | ; 7 | ;del /q /f %tmp%\yes >nul 2>&1 8 | ; 9 | ;copy /y "%~f0" "%temp%\popup.sed" >nul 2>&1 10 | 11 | ;(echo(FinishMessage=%message2%)>>"%temp%\popup.sed"; 12 | ;(echo(TargetName=%cd%\%ppopup_executable%)>>"%temp%\popup.sed"; 13 | ;(echo(FriendlyName=%message1_title%)>>"%temp%\popup.sed" 14 | ; 15 | ;iexpress /n /q /m %temp%\popup.sed 16 | ;%ppopup_executable% 17 | ;rem del /q /f %ppopup_executable% >nul 2>&1 18 | 19 | ;pause 20 | 21 | ;endlocal 22 | ;exit /b 0 23 | 24 | 25 | [Version] 26 | Class=IEXPRESS 27 | SEDVersion=3 28 | [Options] 29 | PackagePurpose=InstallApp 30 | ShowInstallProgramWindow=1 31 | HideExtractAnimation=1 32 | UseLongFileName=0 33 | InsideCompressed=0 34 | CAB_FixedSize=0 35 | CAB_ResvCodeSigning=0 36 | RebootMode=N 37 | InstallPrompt=%InstallPrompt% 38 | DisplayLicense=%DisplayLicense% 39 | FinishMessage=%FinishMessage% 40 | TargetName=%TargetName% 41 | FriendlyName=%FriendlyName% 42 | AppLaunched=%AppLaunched% 43 | PostInstallCmd=%PostInstallCmd% 44 | AdminQuietInstCmd=%AdminQuietInstCmd% 45 | UserQuietInstCmd=%UserQuietInstCmd% 46 | SourceFiles=SourceFiles 47 | [SourceFiles] 48 | SourceFiles0=C:\Windows\System32\ 49 | [SourceFiles0] 50 | %FILE0%= 51 | 52 | 53 | [Strings] 54 | AppLaunched=subst.exe 55 | PostInstallCmd= 56 | AdminQuietInstCmd= 57 | UserQuietInstCmd= 58 | FILE0="subst.exe" 59 | DisplayLicense= 60 | InstallPrompt= 61 | 62 | 63 | -------------------------------------------------------------------------------- /hybrids/iexpress/bat2exeIEXP.bat: -------------------------------------------------------------------------------- 1 | ;@echo off 2 | ; rem https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat 3 | ;if "%~2" equ "" ( 4 | ; echo usage: %~nx0 batFile.bat target.Exe 5 | ;) 6 | ;set "target.exe=%__cd__%%~2" 7 | ;set "batch_file=%~f1" 8 | ;set "bat_name=%~nx1" 9 | ;set "bat_dir=%~dp1" 10 | 11 | ;copy /y "%~f0" "%temp%\2exe.sed" >nul 12 | 13 | ;(echo()>>"%temp%\2exe.sed" 14 | ;(echo(AppLaunched=cmd.exe /c "%bat_name%")>>"%temp%\2exe.sed" 15 | ;(echo(TargetName=%target.exe%)>>"%temp%\2exe.sed" 16 | ;(echo(FILE0="%bat_name%")>>"%temp%\2exe.sed" 17 | ;(echo([SourceFiles])>>"%temp%\2exe.sed" 18 | ;(echo(SourceFiles0=%bat_dir%)>>"%temp%\2exe.sed" 19 | ;(echo([SourceFiles0])>>"%temp%\2exe.sed" 20 | ;(echo(%%FILE0%%=)>>"%temp%\2exe.sed" 21 | 22 | 23 | ;iexpress /n /q /m %temp%\2exe.sed 24 | 25 | ;rem del /q /f "%temp%\2exe.sed" 26 | ; exit /b 0 27 | 28 | [Version] 29 | Class=IEXPRESS 30 | SEDVersion=3 31 | [Options] 32 | PackagePurpose=InstallApp 33 | ShowInstallProgramWindow=0 34 | HideExtractAnimation=1 35 | UseLongFileName=1 36 | InsideCompressed=0 37 | CAB_FixedSize=0 38 | CAB_ResvCodeSigning=0 39 | RebootMode=N 40 | InstallPrompt=%InstallPrompt% 41 | DisplayLicense=%DisplayLicense% 42 | FinishMessage=%FinishMessage% 43 | TargetName=%TargetName% 44 | FriendlyName=%FriendlyName% 45 | AppLaunched=%AppLaunched% 46 | PostInstallCmd=%PostInstallCmd% 47 | AdminQuietInstCmd=%AdminQuietInstCmd% 48 | UserQuietInstCmd=%UserQuietInstCmd% 49 | SourceFiles=SourceFiles 50 | 51 | [Strings] 52 | InstallPrompt= 53 | DisplayLicense= 54 | FinishMessage= 55 | FriendlyName=- 56 | PostInstallCmd= 57 | AdminQuietInstCmd= 58 | UserQuietInstCmd= 59 | ; 60 | -------------------------------------------------------------------------------- /hybrids/iexpress/hidder.bat: -------------------------------------------------------------------------------- 1 | ;:: uses AppLaunched and ShowInstallProgramWindow options in iexpress sed files 2 | ;:: to start a hidden process 3 | ;:: could require admin privileges 4 | ;::http://www.dostips.com/forum/viewtopic.php?f=3&t=5901 5 | 6 | 7 | ;@echo off 8 | ;setlocal 9 | ; rem https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat 10 | ;if "%~2" equ "" ( 11 | ; echo usage: %~nx0 batFile.bat target.Exe 12 | ;) 13 | ;set "target.exe=%__cd__%%~2" 14 | ;set "app_file=%~f1" 15 | ;set "app_name=%~nx1" 16 | ;set "app_dir=%~dp1" 17 | 18 | ;copy /y "%~f0" "%temp%\2exe.sed" >nul 19 | 20 | ;(echo()>>"%temp%\2exe.sed" 21 | ;if "%app_name:~-4%" equ ".bat" ( 22 | ;(echo(AppLaunched=cmd.exe /c "%app_name%")>>"%temp%\2exe.sed" 23 | ;) else ( 24 | ;echo(AppLaunched="%app_name%")>>"%temp%\2exe.sed" 25 | ;) 26 | ;(echo(TargetName=%target.exe%)>>"%temp%\2exe.sed" 27 | ;(echo(FILE0="%app_name%")>>"%temp%\2exe.sed" 28 | ;(echo([SourceFiles])>>"%temp%\2exe.sed" 29 | ;(echo(SourceFiles0=%app_dir%)>>"%temp%\2exe.sed" 30 | ;(echo([SourceFiles0])>>"%temp%\2exe.sed" 31 | ;(echo(%%FILE0%%=)>>"%temp%\2exe.sed" 32 | 33 | 34 | ;iexpress /n /q /m %temp%\2exe.sed 35 | 36 | ;rem del /q /f "%temp%\2exe.sed" 37 | ; exit /b 0 38 | 39 | [Version] 40 | Class=IEXPRESS 41 | SEDVersion=3 42 | [Options] 43 | PackagePurpose=InstallApp 44 | ShowInstallProgramWindow=1 45 | HideExtractAnimation=1 46 | UseLongFileName=1 47 | InsideCompressed=1 48 | CAB_FixedSize=0 49 | CAB_ResvCodeSigning=0 50 | RebootMode=N 51 | InstallPrompt=%InstallPrompt% 52 | DisplayLicense=%DisplayLicense% 53 | FinishMessage=%FinishMessage% 54 | TargetName=%TargetName% 55 | FriendlyName=%FriendlyName% 56 | AppLaunched=%AppLaunched% 57 | PostInstallCmd=%PostInstallCmd% 58 | AdminQuietInstCmd=%AdminQuietInstCmd% 59 | UserQuietInstCmd=%UserQuietInstCmd% 60 | SourceFiles=SourceFiles 61 | 62 | [Strings] 63 | InstallPrompt= 64 | DisplayLicense= 65 | FinishMessage= 66 | FriendlyName=- 67 | PostInstallCmd= 68 | AdminQuietInstCmd= 69 | UserQuietInstCmd= 70 | ; 71 | -------------------------------------------------------------------------------- /hybrids/iexpress/iexpYNButton.bat: -------------------------------------------------------------------------------- 1 | ;@echo off 2 | ; 3 | ;::Creates an .exe file that produces a pop-up with yes/no buttoms 4 | ;:: the execution halts the script execution (unlike msg.exe) and prints the result of the user action 5 | ;:: has no 'toxic' output.Works on every machine since WindowsXP 6 | ;:: (ab)uses iexpress command line options - check read.me file 7 | ; 8 | ;setlocal 9 | ;:::::::::::::::: USER OPTIONS :::::::::::::::: 10 | ;:: 11 | ;:::: the message of in the pop-up body 12 | ;set "message1=yes/no" 13 | ;::::: title of the pop-up 14 | ;set "message1_title=Are you agree?" 15 | ;:::: name of the produced executable 16 | ;set ppopup_executable=popupe.exe 17 | ; 18 | ;::does not accept a command line options at the moment 19 | ;::may be in a later version 20 | ; 21 | ;:: 22 | ;::::::::::::::::: END OF CHANGABLE OPTIONS :::: 23 | ; 24 | ;del /q /f %tmp%\yes >nul 2>&1 25 | ; 26 | ;copy /y "%~f0" "%temp%\popup.sed" >nul 2>&1 27 | ;(echo(InstallPrompt=%message1%)>>"%temp%\popup.sed" 28 | ;(echo(TargetName=%cd%\%ppopup_executable%)>>"%temp%\popup.sed"; 29 | ;(echo(FriendlyName=%message1_title%)>>"%temp%\popup.sed" 30 | ; 31 | ;iexpress /n /q /m %temp%\popup.sed 32 | ;%ppopup_executable% 33 | ;del /q /f %ppopup_executable% >nul 2>&1 34 | ;if exist "%tmp%\yes" (set ans=yes) else (set ans=no) 35 | ;echo %ans% 36 | ;pause 37 | ;rem del %ppopup_executable% 38 | ;endlocal 39 | ;exit /b 0 40 | 41 | 42 | [Version] 43 | Class=IEXPRESS 44 | SEDVersion=3 45 | [Options] 46 | PackagePurpose=InstallApp 47 | ShowInstallProgramWindow=1 48 | HideExtractAnimation=1 49 | UseLongFileName=0 50 | InsideCompressed=0 51 | CAB_FixedSize=0 52 | CAB_ResvCodeSigning=0 53 | RebootMode=N 54 | InstallPrompt=%InstallPrompt% 55 | DisplayLicense=%DisplayLicense% 56 | FinishMessage=%FinishMessage% 57 | TargetName=%TargetName% 58 | FriendlyName=%FriendlyName% 59 | AppLaunched=%AppLaunched% 60 | PostInstallCmd=%PostInstallCmd% 61 | AdminQuietInstCmd=%AdminQuietInstCmd% 62 | UserQuietInstCmd=%UserQuietInstCmd% 63 | SourceFiles=SourceFiles 64 | [SourceFiles] 65 | SourceFiles0=C:\Windows\System32\ 66 | [SourceFiles0] 67 | %FILE0%= 68 | 69 | 70 | [Strings] 71 | AppLaunched=cmd.exe /c "break>%tmp%\yes" 72 | PostInstallCmd= 73 | AdminQuietInstCmd= 74 | UserQuietInstCmd= 75 | FILE0="subst.exe" 76 | DisplayLicense= 77 | FinishMessage= 78 | 79 | 80 | ;InstallPrompt=messagee1 81 | ;DisplayLicense=F:\scriptests\sysinf 82 | ;FinishMessage=message2 83 | ;TargetName=F:\scriptests\popup1.exe 84 | ;FriendlyName=popuppkg 85 | ; 86 | 87 | -------------------------------------------------------------------------------- /hybrids/iexpress/licenseAgreement.bat: -------------------------------------------------------------------------------- 1 | ;::Uses DisplayLicense option in express sed file 2 | ;:: It requires a path to the text file with the license agreement which will 3 | ;:: be built-in produced exe file and later can be deleted if 4 | ;:: the .exe will be reused 5 | 6 | 7 | ;@echo off 8 | ;setlocal 9 | 10 | ;set "message1_title=Are you agree?" 11 | ;set "license_file=%windir%\win.ini" 12 | ;set ppopup_executable=popupe.exe 13 | 14 | ; 15 | ;del /q /f %tmp%\yes >nul 2>&1 16 | ; 17 | ;copy /y "%~f0" "%temp%\popup.sed" >nul 2>&1 18 | ;(echo(DisplayLicense=%license_file%)>>"%temp%\popup.sed" 19 | ;(echo(TargetName=%cd%\%ppopup_executable%)>>"%temp%\popup.sed"; 20 | ;(echo(FriendlyName=%message1_title%)>>"%temp%\popup.sed" 21 | ; 22 | ;iexpress /n /q /m %temp%\popup.sed 23 | ;%ppopup_executable% 24 | ;del /q /f %ppopup_executable% >nul 2>&1 25 | 26 | ;if exist "%tmp%\yes" (set ans=yes) else (set ans=no) 27 | ;echo %ans% 28 | ;pause 29 | 30 | ;endlocal 31 | ;exit /b 0 32 | 33 | 34 | [Version] 35 | Class=IEXPRESS 36 | SEDVersion=3 37 | [Options] 38 | PackagePurpose=InstallApp 39 | ShowInstallProgramWindow=1 40 | HideExtractAnimation=1 41 | UseLongFileName=0 42 | InsideCompressed=0 43 | CAB_FixedSize=0 44 | CAB_ResvCodeSigning=0 45 | RebootMode=N 46 | InstallPrompt=%InstallPrompt% 47 | DisplayLicense=%DisplayLicense% 48 | FinishMessage=%FinishMessage% 49 | TargetName=%TargetName% 50 | FriendlyName=%FriendlyName% 51 | AppLaunched=%AppLaunched% 52 | PostInstallCmd=%PostInstallCmd% 53 | AdminQuietInstCmd=%AdminQuietInstCmd% 54 | UserQuietInstCmd=%UserQuietInstCmd% 55 | SourceFiles=SourceFiles 56 | [SourceFiles] 57 | SourceFiles0=C:\Windows\System32\ 58 | [SourceFiles0] 59 | %FILE0%= 60 | 61 | 62 | [Strings] 63 | AppLaunched=cmd.exe /c "break>%tmp%\yes" 64 | PostInstallCmd= 65 | AdminQuietInstCmd= 66 | UserQuietInstCmd= 67 | FILE0="subst.exe" 68 | InstallPrompt= 69 | FinishMessage= 70 | 71 | 72 | -------------------------------------------------------------------------------- /hybrids/iexpress/read.me: -------------------------------------------------------------------------------- 1 | IExpress is tool intended for self-extracting packages and is built-in every Winows system. 2 | So scripts based on this are maximum possible compatible. 3 | Despite its UI wizard it can be used also from command line if it's suplied with SED file - 4 | basically an ini file.As ";" is a standard delimiter in batch files and is a remark for ini 5 | files so makes makes IExpress perfect for hybridization with batch scripts. 6 | It's options allows running a command in background,Yes/No pop-up,Licensce agreement message 7 | and a single button pop-up (functionlity not possible with simple batch commands) 8 | 9 | In all examples here the script copies itself in %temp% directory as sed file , appends parametrized 10 | inforrmation at the end and creates an exe with IExpress. 11 | Iexpress requires an exe file to be executed at the end otherwise the it will not create .exe 12 | but .cab file.So I've put there subst.exe from system32 - which executed without parameterswont do anything. 13 | As the post install command won't touch the extracted elements they will be deleted by the created .exe file. 14 | 15 | The produced exe can be deleted or reused.Depends on the user needs. 16 | 17 | First published here: 18 | http://www.dostips.com/forum/viewforum.php?f=3 19 | -------------------------------------------------------------------------------- /hybrids/jscript/calcjs.bat: -------------------------------------------------------------------------------- 1 | @if (@X) == (@Y) @end /* 2 | @cscript //E:JScript //nologo "%~f0" "%*" 3 | @exit /b %errorlevel% 4 | */WScript.StdOut.WriteLine(eval(WScript.Arguments.Item(0))); 5 | -------------------------------------------------------------------------------- /hybrids/jscript/deleteJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" %* 5 | 6 | exit /b %errorlevel% 7 | 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | 11 | ////// 12 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 13 | var ARGS = WScript.Arguments; 14 | if (ARGS.Length < 1 ) { 15 | WScript.Echo("No file passed"); 16 | WScript.Echo("Usage:"); 17 | WScript.Echo("Puts file or folder in the recycle bin."); 18 | WScript.Echo(WScript.ScriptName + " file|folder"); 19 | WScript.Quit(1); 20 | } 21 | var filename=ARGS.Item(0); 22 | var objShell=new ActiveXObject("Shell.Application"); 23 | 24 | ///// 25 | 26 | 27 | //fso 28 | ExistsItem = function (path) { 29 | return FSOObj.FolderExists(path)||FSOObj.FileExists(path); 30 | } 31 | 32 | getFullPath = function (path) { 33 | return FSOObj.GetAbsolutePathName(path); 34 | } 35 | // 36 | 37 | //paths 38 | getParent = function(path){ 39 | var splitted=path.split("\\"); 40 | var result=""; 41 | for (var s=0;s'); 12 | var JSON = htmlfile.parentWindow.JSON; 13 | 14 | //needs file existence checks 15 | var jsloc=WScript.Arguments.Item(0); 16 | var jsonPath=WScript.Arguments.Item(1); 17 | var newValue=WScript.Arguments.Item(2); 18 | 19 | 20 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 21 | var txtFile=FSOObj.OpenTextFile(jsloc,1); 22 | var json=txtFile.ReadAll(); 23 | 24 | try { 25 | var jParsed=JSON.parse(json); 26 | }catch(err) { 27 | WScript.Echo("Failed to parse the json content"); 28 | htmlfile.close(); 29 | txtFile.close(); 30 | WScript.Exit(1); 31 | //WScript.Echo(err.message); 32 | } 33 | eval("jParsed."+jsonPath+"=newValue"); 34 | WScript.Echo(eval("JSON.stringify(jParsed)")); 35 | 36 | 37 | htmlfile.close(); 38 | txtFile.close(); 39 | -------------------------------------------------------------------------------- /hybrids/jscript/enterNumberJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X) == (@Y) @end /* JScript comment 2 | @echo off 3 | 4 | for /f "tokens=*" %%a in ('cscript //E:JScript //nologo "%~f0" "%~nx0" %* ') do set "number=%%a" 5 | echo you've entered %number% 6 | 7 | exit /b %errorlevel% 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | 11 | WScript.StdErr.Write("Enter a number:"); 12 | WScript.StdIn.Read(0); 13 | var strMyName = WScript.StdIn.ReadLine(); 14 | var num=parseInt(strMyName); 15 | 16 | while(isNaN(num)){ 17 | WScript.StdErr.Write("Enter a number:"); 18 | WScript.StdIn.Read(0); 19 | var strMyName = WScript.StdIn.ReadLine(); 20 | var num=parseInt(strMyName); 21 | } 22 | 23 | WScript.StdOut.WriteLine(num); 24 | -------------------------------------------------------------------------------- /hybrids/jscript/fileTImesJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /****** jscript comment ****** 2 | @echo off 3 | setlocal 4 | for %%# in (/h /help -h -help) do ( 5 | if "%~1" equ "%%#" ( 6 | (echo() 7 | echo %~nx0 - Displays LastModified,LastAccessed and DateCreated times of a given file 8 | echo in format YYYY-MM-DD hh:mm:ss , the milliseconds passed since 1970-1-1 , day of the week 9 | (echo() 10 | echo example: 11 | echo call %~nx0 C:\file.ext 12 | ) 13 | ) 14 | 15 | if "%~1" equ "" ( 16 | echo no file passed 17 | exit /b 1 18 | ) 19 | 20 | if not exist "%~f1" ( 21 | echo file "%~f1" does not exist 22 | exit /b 2 23 | ) 24 | 25 | if exist "%~f1\" ( 26 | echo "%~f1" is a directory but not a file 27 | exit /b 3 28 | ) 29 | (echo() 30 | echo file timestamps for %~f1 : 31 | (echo() 32 | cscript //E:JScript //nologo "%~f0" "%~f1" 33 | exit /b %errorlevel% 34 | 35 | ****** end of jscript comment ******/ 36 | 37 | var file_loc = WScript.Arguments.Item(0); 38 | var fso = new ActiveXObject("Scripting.FileSystemObject"); 39 | var the_file=fso.GetFile(file_loc); 40 | 41 | function toDoubleDigit(number){ 42 | if (number<10){ 43 | return "0"+number; 44 | } 45 | return number; 46 | } 47 | 48 | function printDateInfo(timeTag,date){ 49 | var month=toDoubleDigit(date.getMonth()+1); 50 | var dayOfTheMonth=toDoubleDigit(date.getHours()); 51 | var hours=toDoubleDigit(date.getHours()); 52 | var minutes=toDoubleDigit(date.getMinutes()); 53 | var seconds=toDoubleDigit(date.getSeconds()); 54 | 55 | WScript.Echo( timeTag + " : " + date.getFullYear() + "-" + month + "-" + dayOfTheMonth + " " + hours + ":" + minutes + ":" + seconds ); 56 | WScript.Echo(timeTag + " - milliseconds passed : " + date.getTime()); 57 | WScript.Echo( timeTag + " day of the week : " + date.getDay()); 58 | WScript.Echo(); 59 | } 60 | var modified_date= new Date(the_file.DateLastModified); 61 | var creation_date= new Date(the_file.DateCreated); 62 | var accessed_date= new Date(the_file.DateLastAccessed); 63 | 64 | printDateInfo("Modified",modified_date); 65 | printDateInfo("Created",creation_date); 66 | printDateInfo("Accessed",accessed_date); 67 | -------------------------------------------------------------------------------- /hybrids/jscript/focusOn.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | cscript //E:JScript //nologo "%~f0" %* 4 | exit /b %errorlevel% 5 | @if (@X)==(@Y) @end JScript comment */ 6 | 7 | var ARGS=WScript.Arguments; 8 | 9 | if (ARGS.Length < 1 ) { 10 | WScript.Echo("No window title passed"); 11 | WScript.Quit(1); 12 | } 13 | 14 | var sh=new ActiveXObject("WScript.Shell"); 15 | if(!sh.AppActivate(ARGS.Item(0))){ 16 | WScript.Echo("Cannot find an app with window name starting with: " + ARGS.Item(0)); 17 | } 18 | -------------------------------------------------------------------------------- /hybrids/jscript/freememjs.bat: -------------------------------------------------------------------------------- 1 | @if (@X) == (@Y) @end /* JScript comment 2 | @echo off 3 | cscript //E:JScript //nologo "%~f0" 4 | exit /b %errorlevel% 5 | @if (@X)==(@Y) @end JScript comment */ 6 | 7 | 8 | WScript.Echo( GetObject('winmgmts:').ExecQuery('Select * from Win32_PerfFormattedData_PerfOS_Memory').ItemIndex(0).AvailableBytes ) 9 | -------------------------------------------------------------------------------- /hybrids/jscript/getInnerText.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" %* 5 | ::pause 6 | exit /b %errorlevel% 7 | 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | 11 | var link=WScript.Arguments.Item(0); 12 | var saveTo=WScript.Arguments.Item(1); 13 | 14 | 15 | var IE = new ActiveXObject("InternetExplorer.Application"); 16 | IE.Visible=false; 17 | IE.Navigate2(link); 18 | 19 | function sleep(milliseconds) { 20 | var start = new Date().getTime(); 21 | for (var i = 0; i < 1e7; i++) { 22 | if ((new Date().getTime() - start) > milliseconds){ 23 | break; 24 | } 25 | } 26 | } 27 | 28 | var counter=0; 29 | while (IE.Busy && counter<60*60*10) { 30 | //WScript.Echo(IE.Busy); 31 | sleep(1000); 32 | counter++; 33 | } 34 | 35 | if(IE.Busy){ 36 | WScript.Echo("Cant wait 4ever"); 37 | WScript.Quit(10); 38 | } 39 | 40 | function writeContent(file,content) { 41 | var ado = WScript.CreateObject("ADODB.Stream"); 42 | ado.Type = 2; // adTypeText = 2 43 | ado.CharSet = "iso-8859-1"; // right code page for output (no adjustments) 44 | //ado.Mode=2; 45 | ado.Open(); 46 | 47 | ado.WriteText(content); 48 | ado.SaveToFile(file, 2); 49 | ado.Close(); 50 | } 51 | 52 | var innerText=IE.document.body.innerText; 53 | IE.Quit(); 54 | writeContent(saveTo,innerText) 55 | -------------------------------------------------------------------------------- /hybrids/jscript/guid.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* 2 | @cscript //E:JScript //nologo "%~f0" %* 3 | @exit /b %errorlevel% 4 | @*/WScript.Echo((new ActiveXObject("Scriptlet.TypeLib")).Guid) 5 | -------------------------------------------------------------------------------- /hybrids/jscript/imgInfo.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | rem :: the first argument is the script name as it will be used for proper help message 5 | cscript //E:JScript //nologo "%~f0" %* 6 | 7 | exit /b %errorlevel% 8 | 9 | @if (@X)==(@Y) @end JScript comment */ 10 | 11 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 12 | var ARGS = WScript.Arguments; 13 | if (ARGS.Length < 1 ) { 14 | WScript.Echo("No file passed"); 15 | WScript.Echo("Usage:"); 16 | WScript.Echo(" Image"); 17 | WScript.Quit(1); 18 | } 19 | var filename=ARGS.Item(0); 20 | 21 | if (!FSOObj.FileExists(filename)){ 22 | WScript.Echo("File "+filename+" does not exists"); 23 | WScript.Quit(2); 24 | } 25 | 26 | function ID2Format(id){ 27 | var ids={}; 28 | ids["{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"]="BPM"; 29 | ids["{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"]="PNG"; 30 | ids["{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"]="GIF"; 31 | ids["{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"]="JPG"; 32 | ids["{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"]="TIFF"; 33 | 34 | return ids[id]; 35 | } 36 | 37 | var img=new ActiveXObject("WIA.ImageFile"); 38 | try { 39 | img.LoadFile(filename); 40 | }catch(err){ 41 | WScript.Echo("Probably "+ filename + " is not an image"); 42 | WScript.Echo(err.message); 43 | WScript.Quit(3); 44 | 45 | } 46 | 47 | 48 | 49 | 50 | WScript.Echo("Height:"+img.Height); 51 | WScript.Echo("Width:"+img.Width); 52 | WScript.Echo("HorizontalResolution:"+img.HorizontalResolution); 53 | WScript.Echo("VerticalResolution:"+img.VerticalResolution); 54 | //WScript.Echo("Format:"+img.FormatID); 55 | WScript.Echo("ActiveFrame:"+img.ActiveFrame); 56 | WScript.Echo("Extension:"+img.FileExtension); 57 | WScript.Echo("Format: "+ID2Format(img.FormatID)); 58 | WScript.Echo("FrameCount:"+img.FrameCount); 59 | WScript.Echo("IsAnimated:"+img.IsAnimated); 60 | WScript.Echo("PixelDepth:"+img.PixelDepth); 61 | WScript.Echo("IsExtendedPixelFormat:"+img.IsExtendedPixelFormat); 62 | WScript.Echo("IsAlphaPixelFormat:"+img.IsAlphaPixelFormat); 63 | 64 | for(var i=1;i<=img.Properties.Count;i++){ 65 | WScript.Echo(img.Properties(i).Name+": "+img.Properties(i)); 66 | } 67 | -------------------------------------------------------------------------------- /hybrids/jscript/jsonextractor.bat: -------------------------------------------------------------------------------- 1 | @if (@CodeSection == @Batch) @then 2 | 3 | @echo off & setlocal 4 | 5 | cscript /nologo /e:JScript "%~f0" %* 6 | goto :EOF 7 | 8 | @end // end batch / begin JScript hybrid chimera 9 | 10 | var htmlfile = WSH.CreateObject('htmlfile'); 11 | htmlfile.write(''); 12 | var JSON = htmlfile.parentWindow.JSON; 13 | 14 | //needs file existence checks 15 | var jsloc=WScript.Arguments.Item(0); 16 | var jsonPath=WScript.Arguments.Item(1); 17 | 18 | 19 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 20 | var txtFile=FSOObj.OpenTextFile(jsloc,1); 21 | var json=txtFile.ReadAll(); 22 | 23 | try { 24 | var jParsed=JSON.parse(json); 25 | }catch(err) { 26 | WScript.Echo("Failed to parse the json content"); 27 | htmlfile.close(); 28 | txtFile.close(); 29 | WScript.Exit(1); 30 | //WScript.Echo(err.message); 31 | } 32 | 33 | 34 | WScript.Echo(eval("JSON.stringify(jParsed."+jsonPath+")")); 35 | 36 | 37 | htmlfile.close(); 38 | txtFile.close(); 39 | -------------------------------------------------------------------------------- /hybrids/jscript/jspopup.bat: -------------------------------------------------------------------------------- 1 | @if (@x)==(@y) @end /***** jscript comment ****** 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" "%~nx0" %* 5 | exit /b 0 6 | 7 | @if (@x)==(@y) @end ****** end comment *********/ 8 | 9 | 10 | var wshShell = WScript.CreateObject("WScript.Shell"); 11 | var args=WScript.Arguments; 12 | var title=args.Item(0); 13 | 14 | var timeout=-1; 15 | var pressed_message="button pressed"; 16 | var timeout_message="timedout"; 17 | var message=""; 18 | 19 | function printHelp() { 20 | WScript.Echo(title + "[-title Title] [-timeout m] [-tom \"Time-out message\"] [-pbm \"Pressed button message\"] [-message \"pop-up message\"]"); 21 | } 22 | 23 | if (WScript.Arguments.Length==1){ 24 | runPopup(); 25 | WScript.Quit(0); 26 | } 27 | 28 | if (args.Item(1).toLowerCase() == "-help" || args.Item(1).toLowerCase() == "-h" ) { 29 | printHelp(); 30 | WScript.Quit(0); 31 | } 32 | 33 | if (WScript.Arguments.Length % 2 == 0 ) { 34 | WScript.Echo("Illegal arguments "); 35 | printHelp(); 36 | WScript.Quit(1); 37 | } 38 | 39 | for (var arg = 1 ; arg -1) { 58 | return; 59 | } 60 | 61 | 62 | var elements=tempString.split("/"); 63 | for (i = 0;i < elements.length;i++) { 64 | 65 | if (elements[i].toLowerCase().indexOf("count") > -1) { 66 | pages=elements[i].split(" ")[1]; 67 | 68 | } 69 | } 70 | } 71 | 72 | function getPages(fPath) { 73 | var fChars = getChars(fPath); 74 | 75 | for (i=0;i" && 88 | fChars[i+1] == ">" ) { 89 | 90 | inTag = false; 91 | checkTag(tempString); 92 | if (pages != "" ) { 93 | return; 94 | } 95 | 96 | tempString=""; 97 | 98 | } 99 | 100 | if (inTag) { 101 | if (fChars[i] != '\n' && fChars[i] != '\r') { 102 | tempString += fChars[i]; 103 | } 104 | } 105 | 106 | } 107 | 108 | } 109 | 110 | getPages(filename); 111 | if (pages == "") { 112 | WScript.Echo("1"); 113 | } else { 114 | WScript.Echo(pages); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /hybrids/jscript/phisycalDrives.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JSCRIPT COMMENT ** 2 | 3 | 4 | @echo off 5 | cscript //E:JScript //nologo "%~f0" 6 | exit /b 7 | 8 | // Sources of wisdom: 9 | //http://social.msdn.microsoft.com/Forums/vstudio/en-US/659030c8-bcf5-4542-bbc6-eaf9679e090a/cannot-create-object-wmi-in-javascript 10 | //http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/23/how-can-i-correlate-logical-drives-and-physical-disks.aspx 11 | //http://stackoverflow.com/a/1144788/388389 12 | 13 | ************** end of JSCRIPT COMMENT **/ 14 | 15 | 16 | String.prototype.replaceAll = function (find, replace) { 17 | var str = this; 18 | return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace); 19 | }; 20 | 21 | 22 | var winmgmts= GetObject("winmgmts:\\\\.\\root\\cimv2") 23 | var drives = winmgmts.ExecQuery( "SELECT * FROM Win32_DiskDrive", null, 48 ); 24 | //WScript.Echo(drives); 25 | 26 | var drvs = new Enumerator(drives); 27 | for (;!drvs.atEnd();drvs.moveNext()) { 28 | var drive=drvs.item(); 29 | 30 | WScript.Echo( "Physical Disk: " + drive.Caption + " -- " + drive.DeviceID ); 31 | var deviceID = drive.DeviceID.replaceAll( "\\" ,"\\\\"); 32 | var colPartitions = winmgmts.ExecQuery( "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=\"" + 33 | deviceID + "\"} WHERE AssocClass = Win32_DiskDriveToDiskPartition" , null, 48 ); 34 | 35 | var colParts = new Enumerator(colPartitions); 36 | for (;!colParts.atEnd();colParts.moveNext()) { 37 | 38 | var partition=colParts.item(); 39 | 40 | //WScript.Echo( "Disk Partition: " + partition.DeviceID ); 41 | var colLogicalDisks = winmgmts.ExecQuery( "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=\"" + 42 | partition.DeviceID + "\"} WHERE AssocClass = Win32_LogicalDiskToPartition" , null, 48); 43 | var colLD = new Enumerator(colLogicalDisks); 44 | 45 | if (typeof colLD.item() != "undefined") { 46 | for (;!colLD.atEnd();colLD.moveNext()) { 47 | var logicalDisk=colLD.item(); 48 | WScript.Echo( " Logical Disk: " + logicalDisk.DeviceID + " Disk Partition: harddisk" + partition.DeviceID.split("#")[1].split(",")[0] + "\\partition" + partition.DeviceID.split("#")[2] ); 49 | } 50 | } else { 51 | WScript.Echo( " Disk Partition: harddisk" + partition.DeviceID.split("#")[1].split(",")[0] + "\\partition" + partition.DeviceID.split("#")[2] ); 52 | } 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /hybrids/jscript/ppt2pdf.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" %* 5 | 6 | exit /b %errorlevel% 7 | 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | function printHelp(){ 11 | WScript.Echo(WScript.ScriptName + " - converts power point presentation to pdf.Requires installed MS Office."); 12 | WScript.Echo("Usage:"); 13 | WScript.Echo("[call] " + WScript.ScriptName + " pptFile pdfFile"); 14 | } 15 | 16 | if(WScript.Arguments.Item(0).toLowerCase()=="-h" || WScript.Arguments.Item(0).toLowerCase()=="-help" || WScript.Arguments.Item(0).toLowerCase()=="-?") { 17 | printHelp(); 18 | } 19 | 20 | if(WScript.Arguments.Length < 2) { 21 | printHelp(); 22 | WScript.Quit(1); 23 | } 24 | 25 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 26 | 27 | var source=WScript.Arguments.Item(0); 28 | var target=WScript.Arguments.Item(1); 29 | 30 | // no checks for directories. 31 | if(!FSOObj.FileExists(source)){ 32 | WScript.Echo("File " + source + "does not exists"); 33 | WScript.Quit(2); 34 | } 35 | 36 | if(FSOObj.FileExists(target)){ 37 | WScript.Echo("File " + target + "already exists"); 38 | WScript.Quit(3); 39 | } 40 | 41 | PP = new ActiveXObject("PowerPoint.Application"); 42 | PRSNT = PP.presentations.Open(source,0,0,0) 43 | //PRSNT.SaveCopyAs(target,32); 44 | //https://msdn.microsoft.com/en-us/vba/powerpoint-vba/articles/ppsaveasfiletype-enumeration-powerpoint 45 | PRSNT.SaveAs(target,32); 46 | PRSNT.Close(); 47 | PP.Quit(); 48 | -------------------------------------------------------------------------------- /hybrids/jscript/printJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" %* 5 | 6 | exit /b %errorlevel% 7 | 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | //gets an information that normally is acquired by right click-details 11 | // can get image dimensions , media file play time and etc. 12 | 13 | ////// 14 | FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 15 | var ARGS = WScript.Arguments; 16 | if (ARGS.Length < 1 ) { 17 | WScript.Echo("No file passed"); 18 | WScript.Echo("Usage (prints with default printer a file if possible)"); 19 | WScript.Echo(WScript.ScriptName + " file"); 20 | WScript.Quit(1); 21 | } 22 | var filename=ARGS.Item(0); 23 | var objShell=new ActiveXObject("Shell.Application"); 24 | 25 | ///// 26 | 27 | 28 | //fso 29 | ExistsItem = function (path) { 30 | return FSOObj.FolderExists(path)||FSOObj.FileExists(path); 31 | } 32 | 33 | getFullPath = function (path) { 34 | return FSOObj.GetAbsolutePathName(path); 35 | } 36 | // 37 | 38 | //paths 39 | getParent = function(path){ 40 | var splitted=path.split("\\"); 41 | var result=""; 42 | for (var s=0;s http://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx"); 25 | } 26 | 27 | function parseArgs(){ 28 | 29 | if (ARGS.Length < 3) { 30 | WScript.Echo("insufficient arguments"); 31 | printHelp(); 32 | WScript.Quit(43); 33 | } 34 | 35 | title=ARGS.Item(1); 36 | keys=ARGS.Item(2); 37 | } 38 | 39 | 40 | function escapeRegExp(str) { 41 | return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); 42 | } 43 | 44 | function replaceAll(str, find, replace) { 45 | return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); 46 | } 47 | 48 | parseArgs(); 49 | //in case the script is called with CALL command the carets will be doubled 50 | keys=replaceAll(keys,"^^","^"); 51 | 52 | if (title === "") { 53 | sh.SendKeys(keys); 54 | WScript.Quit(0); 55 | } 56 | if (sh.AppActivate(title)){ 57 | sh.SendKeys(keys); 58 | WScript.Quit(0); 59 | } else { 60 | WScript.Echo("Failed to find application with title " + title); 61 | WScript.Quit(1); 62 | } 63 | -------------------------------------------------------------------------------- /hybrids/jscript/shellCopy.bat: -------------------------------------------------------------------------------- 1 | @if (@x)==(@y) @end /***** jscript comment ****** 2 | @echo off 3 | cscript //E:JScript //nologo "%~f0" "%~nx0" %* 4 | exit /b %errorlevel% 5 | 6 | ***** end comment *********/ 7 | 8 | var FSOObj = new ActiveXObject("Scripting.FileSystemObject"); 9 | var ShellObj=new ActiveXObject("Shell.Application"); 10 | 11 | var ARGS = WScript.Arguments; 12 | var scriptName=ARGS.Item(0); 13 | var move = false; 14 | 15 | if (ARGS.Length == 0 ) { 16 | WScript.Echo("Uses shell.application to move/copy files. Usage:"); 17 | WScript.Echo(scriptName + "source destinationDirectory [move]"); 18 | WScript.Echo("Example:"); 19 | WScript.Echo("call " + scriptName + "\"C:\\file.txt\" \"D:\\folder\" "); 20 | WScript.Echo("To move files:"); 21 | WScript.Echo("call " + scriptName + "\"C:\\*.txt\" \"D:\\folder\" yes"); 22 | WScript.Quit(0); 23 | } 24 | 25 | if (ARGS.Length < 3 ) { 26 | WScript.Echo("ERROR: not enough arguments"); 27 | WScript.Quit(1); 28 | } 29 | 30 | 31 | if (ARGS.Length > 3 ) { 32 | if (ARGS.Item(3).toLowerCase() == "true") { 33 | move = true; 34 | } 35 | } 36 | 37 | var source = ARGS.Item(1); 38 | var destination = ARGS.Item(2); 39 | 40 | //options values 41 | var YES_TO_ALL=16; 42 | var YESTA_NEW_NAMES=312 43 | 44 | 45 | getFullPath = function (path) { 46 | return FSOObj.GetAbsolutePathName(path); 47 | } 48 | 49 | destination = getFullPath(destination); 50 | 51 | if (!FSOObj.FolderExists(destination)) { 52 | WScript.Echo("ERROR: directory " + destination + " does not exists"); 53 | WScript.Quit(1); 54 | } 55 | 56 | var folder = ShellObj.NameSpace(destination); 57 | 58 | if (move) { 59 | folder.MoveHere(source,YESTA_NEW_NAMES); 60 | } else { 61 | folder.CopyHere(source,YESTA_NEW_NAMES); 62 | } 63 | -------------------------------------------------------------------------------- /hybrids/jscript/slowTypeJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | cscript //E:JScript //nologo "%~nx0" %* 4 | exit /b %errorlevel% 5 | @if (@X)==(@Y) @end JScript comment */ 6 | 7 | if (WScript.Arguments.Count() == 0) { 8 | WScript.Echo(); 9 | WScript.Echo(WScript.ScriptName + " writes a passed script to the console with a certain delay"); 10 | WScript.Echo(); 11 | WScript.Echo("Usage:"); 12 | WScript.Echo(); 13 | WScript.Echo(WScript.ScriptName + " string delay-in-ms"); 14 | WScript.Quit(0); 15 | } 16 | 17 | if (WScript.Arguments.Count()<2) { 18 | WScript.Echo("not enough arguments"); 19 | WScript.Quit(1); 20 | } 21 | 22 | var string = WScript.Arguments.Item(0); 23 | var delay; 24 | try { 25 | delay = parseInt(WScript.Arguments.Item(1)); 26 | }catch(err){ 27 | WScript.Echo("cannot parse to number: " + WScript.Arguments.Item(1)); 28 | WScript.Quit(2); 29 | } 30 | 31 | if(isNaN(delay)) { 32 | WScript.Echo("cannot parse to number: " + WScript.Arguments.Item(1)); 33 | WScript.Quit(2); 34 | } 35 | 36 | for (var i = 0; i < string.length; i++) { 37 | WScript.Sleep(delay); 38 | WScript.StdOut.Write(string.charAt(i)); 39 | } 40 | -------------------------------------------------------------------------------- /hybrids/jscript/splitjs.bat: -------------------------------------------------------------------------------- 1 | @if (@x)==(@y) @end /***** jscript comment ****** 2 | @echo off 3 | cscript //E:JScript //nologo "%~f0" "%~nx0" %* 4 | exit /b %errorlevel% 5 | 6 | @if (@x)==(@y) @end ****** end comment *********/ 7 | 8 | //https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat 9 | 10 | var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject"); 11 | var AdoDBObj = new ActiveXObject("ADODB.Stream"); 12 | 13 | var ARGS = WScript.Arguments; 14 | var scriptName=ARGS.Item(0); 15 | 16 | if (ARGS.length <3) { 17 | WScript.Echo("Wrong arguments"); 18 | WScript.Echo("usage:"); 19 | WScript.Echo(scriptName +"file_to_split size_in_bytes"); 20 | WScript.Quit(1); 21 | } 22 | var file=ARGS.Item(1); 23 | var max_size=parseInt(ARGS.Item(2)); 24 | 25 | function getSize(file){ 26 | return FileSystemObj.getFile(file).size; 27 | } 28 | 29 | function isExist(file){ 30 | return FileSystemObj.FileExists(file); 31 | } 32 | 33 | function writeFile(fileName,data ){ 34 | AdoDBObj.Type = 1; 35 | AdoDBObj.Open(); 36 | AdoDBObj.Position=0; 37 | AdoDBObj.Write(data); 38 | AdoDBObj.SaveToFile(fileName,2); 39 | AdoDBObj.Close(); 40 | } 41 | 42 | function readFile(fileName,size,position){ 43 | AdoDBObj.Type = 1; 44 | AdoDBObj.Open(); 45 | AdoDBObj.LoadFromFile(fileName); 46 | AdoDBObj.Position=position; 47 | fileBytes=AdoDBObj.Read(size); 48 | AdoDBObj.Close(); 49 | return fileBytes; 50 | 51 | 52 | } 53 | 54 | function chunker(file,size){ 55 | var part=0; 56 | var position=0; 57 | var buffer=readFile(file,size,0); 58 | file_size=getSize(file); 59 | while (buffer !== null ) { 60 | part++; 61 | writeFile(file+"."+part,buffer); 62 | if (size*part <= file_size) { 63 | position=size*part; 64 | } else { 65 | position=file_size; 66 | } 67 | buffer=readFile(file,size,position); 68 | } 69 | } 70 | 71 | if (!isExist(file)){ 72 | WScript.Echo(file+" does not exist"); 73 | WScript.Quit(2); 74 | } 75 | 76 | if(max_size<=0){ 77 | WScript.Echo("Size must be bigger than 0.") 78 | WScript.Quit(); 79 | } 80 | 81 | chunker(file,max_size); 82 | -------------------------------------------------------------------------------- /hybrids/jscript/spplayer.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | cscript //E:JScript //nologo "%~f0" %* 5 | 6 | exit /b %errorlevel% 7 | 8 | @if (@X)==(@Y) @end JScript comment */ 9 | 10 | if (WScript.Arguments.Length == 0) { 11 | WScript.Echo(WScript.ScriptName + " file_to_play"); 12 | WScript.Quit(0) 13 | } 14 | var fso= new ActiveXObject("Scripting.FileSystemObject"); 15 | var file=WScript.Arguments.Item(0); 16 | 17 | if (!fso.FileExists(file)){ 18 | WScript.Echo(file + " does not exist"); 19 | WScript.Echo("usage:"); 20 | WScript.Echo(WScript.ScriptName + " file_to_play"); 21 | WScript.Quit(1); 22 | } 23 | 24 | 25 | var spVoice = new ActiveXObject("SAPI.SpVoice"); 26 | var spFile = new ActiveXObject("SAPI.SpFileStream.1"); 27 | spFile.Open(file); 28 | spVoice.SpeakStream(spFile); 29 | -------------------------------------------------------------------------------- /hybrids/jscript/toHexJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | rem :: the first argument is the script name as it will be used for proper help message 5 | cscript //E:JScript //nologo "%~f0" %* 6 | 7 | exit /b %errorlevel% 8 | 9 | @if (@X)==(@Y) @end JScript comment */ 10 | 11 | var string=""; 12 | if (WScript.Arguments.Length==0) { 13 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0); 14 | string=fso.ReadLine(); 15 | } else { 16 | string=WScript.Arguments.Item(0); 17 | } 18 | 19 | String.prototype.hexEncode = function(){ 20 | var hex, i; 21 | 22 | var result = ""; 23 | for (i=0; i\&]/gim , function(s) { 68 | return "&#" + s.charCodeAt(0) + ";"; 69 | }); 70 | }; 71 | 72 | 73 | function printToConsole(fileContent){ 74 | //WScript.Echo(fileContent); 75 | WScript.Echo(fileContent.toHtmlEntities()); 76 | } 77 | 78 | function printToFile(fileContent,file){ 79 | writeContent(fileContent.toHtmlEntities(),file); 80 | 81 | } 82 | 83 | if (WScript.Arguments.Length > 1) { 84 | var outputFile=WScript.Arguments.Item(1); 85 | printToFile(outputFile,getFileContent(inputFile)); 86 | } else { 87 | printToConsole(getFileContent(inputFile)); 88 | } 89 | -------------------------------------------------------------------------------- /hybrids/jscript/unHexJS.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | rem :: the first argument is the script name as it will be used for proper help message 5 | cscript //E:JScript //nologo "%~f0" %* 6 | 7 | exit /b %errorlevel% 8 | 9 | @if (@X)==(@Y) @end JScript comment */ 10 | 11 | var string=""; 12 | if (WScript.Arguments.Length==0) { 13 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0); 14 | string=fso.ReadLine(); 15 | } else { 16 | string=WScript.Arguments.Item(0); 17 | } 18 | 19 | String.prototype.hexDecode = function(){ 20 | var j; 21 | var hexes = this.match(/.{1,2}/g) || []; 22 | var back = ""; 23 | for(j = 0; j> a/4 // 8 to 11 26 | ).toString(16) // in hexadecimal 27 | : ( // or otherwise a concatenated string: 28 | [1e7] + // 10000000 + 29 | -1e3 + // -1000 + 30 | -4e3 + // -4000 + 31 | -8e3 + // -80000000 + 32 | -1e11 // -100000000000, 33 | ).replace( // replacing 34 | /[018]/g, // zeroes, ones, and eights with 35 | b // random hex digits 36 | ) 37 | } 38 | 39 | WScript.Echo(UUIDv4()); 40 | -------------------------------------------------------------------------------- /hybrids/jscript/write.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | cscript //E:JScript //nologo "%~nx0" %* 4 | exit /b %errorlevel% 5 | @if (@X)==(@Y) @end JScript comment */ 6 | // writes a string to the console without a new line at the end 7 | if(WScript.Arguments.Count()>0) WScript.StdOut.Write(WScript.Arguments.Item(0)); 8 | -------------------------------------------------------------------------------- /hybrids/jscript/xpath.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /* JScript comment 2 | @echo off 3 | 4 | set "file=%~f1" 5 | set "xpath=%~2" 6 | set "option=%~3" 7 | 8 | if "%~2" equ "" ( 9 | goto :printHelp 10 | ) 11 | 12 | for %%# in ("-h" "-help" "/h" "/help" "") do ( 13 | if /i "%~1" equ %%# ( 14 | goto :printHelp 15 | ) 16 | ) 17 | 18 | if exist "%file%\" ( 19 | echo file "%~1" does not exist 20 | exit /b 3 21 | ) 22 | if not exist "%file%" ( 23 | echo file "%~1" does not exist 24 | exit /b 4 25 | ) 26 | 27 | 28 | cscript //E:JScript //nologo "%~f0" /file:"%file%" /xpath:"%xpath%" /option:"%option%" 29 | 30 | exit /b %errorlevel% 31 | 32 | :printHelp 33 | echo %~nx0 prints the value (or list of values) 34 | echo of xml attribute/node in xml by given xpath expression 35 | echo( 36 | echo Usage: 37 | echo( 38 | echo call %~nx0 "filePath" "xpathExpression" 39 | exit /b %errorlevel% 40 | 41 | @if (@X)==(@Y) @end JScript comment */ 42 | 43 | if (WScript.Arguments.length<2) 44 | { 45 | WScript.Echo("Not enough arguments"); 46 | WScript.Quit(3); 47 | } 48 | 49 | 50 | function escapeRegExp(str) { 51 | return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); 52 | } 53 | 54 | function replaceAll(str, find, replace) { 55 | return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); 56 | } 57 | 58 | var xp=WScript.Arguments.Named.Item("xpath"); 59 | xp=replaceAll(xp,"'",'"'); 60 | 61 | var option=WScript.Arguments.Named.Item("option"); 62 | 63 | var objDoc; 64 | var objNodes; 65 | var loaded; 66 | 67 | try { 68 | objDoc = WScript.CreateObject("MSXML.DOMDocument"); 69 | loaded=objDoc.load(WScript.Arguments.Named.Item("file")); 70 | } catch (err){ 71 | WScript.Echo("Error while parsing the xml"); 72 | WScript.Echo(err.message); 73 | WScript.Quit(1); 74 | } 75 | 76 | if(!loaded){ 77 | WScript.Echo("Error while parsing the xml"); 78 | WScript.Echo(""); 79 | WScript.Echo("Error Code:"+objDoc.parseError.errorCode); 80 | WScript.Echo(""); 81 | WScript.Echo("Line:"+objDoc.parseError.line+" Posotion:"+objDoc.parseError.filepos); 82 | WScript.Echo(""); 83 | WScript.Echo("Reason:"+objDoc.parseError.reason); 84 | WScript.Echo(""); 85 | WScript.Echo("URL:"+objDoc.parseError.url); 86 | WScript.Echo(""); 87 | WScript.Echo(objDoc.parseError.srcText); 88 | WScript.Quit(5); 89 | } 90 | 91 | try { 92 | var objNodes = objDoc.selectNodes(xp); 93 | } catch (err){ 94 | WScript.Echo("invalid xpath expression"); 95 | WScript.Echo(err.message); 96 | WScript.Quit(2); 97 | } 98 | 99 | for (var i=0;i"%tmp%\makecab.dir.ddf" 42 | ; 43 | ;setlocal enableDelayedExpansion 44 | ;for /d /r "%dir_to_cab%" %%a in (*) do ( 45 | ; 46 | ; set "_dir=%%~pna" 47 | ; set "destdir=%dir_name%!_dir:%path_to_dir%=!" 48 | ; (echo(.Set DestinationDir=!destdir!>>"%tmp%\makecab.dir.ddf") 49 | ; for %%# in ("%%a\*") do ( 50 | ; (echo("%%~f#" /inf=no>>"%tmp%\makecab.dir.ddf") 51 | ; ) 52 | ;) 53 | ;(echo(.Set DestinationDir=!dir_name!>>"%tmp%\makecab.dir.ddf") 54 | ; for %%# in ("%~f1\*") do ( 55 | ; 56 | ; (echo("%%~f#" /inf=no>>"%tmp%\makecab.dir.ddf") 57 | ; ) 58 | 59 | ;makecab /F "%~f0" /f "%tmp%\makecab.dir.ddf" /d DiskDirectory1=%cd% /d CabinetNameTemplate=%cab_file%.cab 60 | ;del /q /f "%tmp%\makecab.dir.ddf" 61 | ;exit /b %errorlevel% 62 | 63 | ;; 64 | ;;;; rem end of the batch part ;;;;; 65 | 66 | ;;;; directives part ;;;;; 67 | ;; 68 | .New Cabinet 69 | .set GenerateInf=OFF 70 | .Set Cabinet=ON 71 | .Set Compress=ON 72 | .Set UniqueFiles=ON 73 | .Set MaxDiskSize=1215751680; 74 | 75 | .set RptFileName=nul 76 | .set InfFileName=nul 77 | 78 | .set MaxErrors=1 79 | ;; 80 | ;;;; end of directives part ;;;;; 81 | -------------------------------------------------------------------------------- /hybrids/makecab/fileinf.bat: -------------------------------------------------------------------------------- 1 | ; @echo off 2 | ;;goto :end_help 3 | ;:fileinf 4 | ;;setlocal DsiableDelayedExpansion 5 | ;;; 6 | ;;; 7 | ;;; fileinf /l list of full file paths separated with ; and surrounded with quotes 8 | ;;; fileinf /f text file with a list of files to be processed ( one on each line ) 9 | ;;; fileinf /? prints the help 10 | ;;; 11 | ;;; Batch/MakeCab hybrid file that gets property information about binary files 12 | ;;; by Vasil "npocmaka" Arnaudov 13 | ;;; 14 | ;; the ;s are standard delimtiers in batch and remark symbols for makecab 15 | ;; directive files which allows to combine them both in one file 16 | ;; http://stackoverflow.com/questions/20535473/how-can-i-determined-the-version-of-windows-installer-in-a-bat-file 17 | ;; http://stackoverflow.com/questions/1706892/how-do-i-retrieve-the-version-of-a-file-from-a-batch-file-on-windows-vista 18 | ;; alternative of FILEVER from windows 2003 res tool kit 19 | ;;:end_help 20 | 21 | ; REM Creating a Newline variable (the two blank lines are required!) 22 | ; set NLM=^ 23 | 24 | 25 | ; set NL=^^^%NLM%%NLM%^%NLM%%NLM% 26 | ; if "%~1" equ "/?" type "%~f0" | find ";;;" | find /v "find" && exit /b 0 27 | ; if "%~2" equ "" type "%~f0" | find ";;;" | find /v "find" && exit /b 0 28 | ; setlocal enableDelayedExpansion 29 | ; if "%~1" equ "/l" ( 30 | ; set "_files=%~2" 31 | ; echo !_files:;=%NL%! 32 | ; echo !_files:;=%NL%!>"%TEMP%\file.paths" 33 | ; set _process_file="%TEMP%\file.paths" 34 | ; goto :get_info 35 | ; ) 36 | 37 | ; if "%~1" equ "/f" if exist "%~2" ( 38 | ; set _process_file="%~2" 39 | ; goto :get_info 40 | ; ) 41 | 42 | ; echo incorect parameters & exit /b 1 43 | ; :get_info 44 | ; set "file_info=" 45 | 46 | ; rem :: check if all passed files exist 47 | ; for /f "useback tokens=* delims=" %%f in ("%TEMP%\file.paths") do ( 48 | ; if not exist "%%~f" ( 49 | ; echo file %%~f does not exist 50 | ; exit /b 5 51 | ; ) 52 | ;) 53 | 54 | ; makecab /d InfFileName=%TEMP%\file.inf /d "DiskDirectory1=%TEMP%" /f "%~f0" /f %_process_file% /v0>nul 55 | ; for /f "usebackq skip=4 delims=" %%f in ("%TEMP%\file.inf") do ( 56 | ; set "file_info=%%f" 57 | ; echo !file_info:,=%nl%! 58 | ; ) 59 | 60 | ; endlocal 61 | ;endlocal 62 | ; del /q /f %TEMP%\file.inf 2>nul 63 | ; del /q /f %TEMP%\file.path 2>nul 64 | ; exit /b 0 65 | 66 | .set DoNotCopyFiles=on 67 | .set DestinationDir=; 68 | .set RptFileName=nul 69 | .set InfFooter=; 70 | .set InfHeader=; 71 | .Set ChecksumWidth=8 72 | .Set InfDiskLineFormat=; 73 | .Set Cabinet=off 74 | .Set Compress=off 75 | .Set GenerateInf=ON 76 | .Set InfDiskHeader=; 77 | .Set InfFileHeader=; 78 | .set InfCabinetHeader=; 79 | .Set InfFileLineFormat=",file:*file*,date:*date*,size:*size*,csum:*csum*,time:*time*,vern:*ver*,vers:*vers*,lang:*lang*" 80 | -------------------------------------------------------------------------------- /hybrids/mshta/OpticalDrivesCount.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | for /f "usebackq" %%a in (`mshta ^"javascript^:code^(close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(new ActiveXObject^(^'IMAPI2.MsftDiscMaster2.1^'^).Count^)^)^); ^"`) do set OptDrives=%%a 3 | echo %OptDrives% 4 | -------------------------------------------------------------------------------- /hybrids/mshta/atob.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal 4 | 5 | if "%~1" equ "" ( 6 | echo %~nx1 - decodes string to base 64 7 | echo example: 8 | echo %~nx1 string [rtrnVar] 9 | echo( 10 | echo rtrnVar - variable where where the result will be stored. 11 | echo if not defined the result will be printed in console 12 | exit /b 0 13 | ) 14 | 15 | set "string=%~1" 16 | 17 | 18 | 19 | for /f "delims=" %%# in ('echo %string%^|mshta.exe "%~f0"') do ( 20 | set dec=%%# 21 | ) 22 | 23 | if "%~2" neq "" ( 24 | endlocal & ( 25 | set "%~2=%dec%" 26 | exit /b %errorlevel% 27 | ) 28 | ) else ( 29 | endlocal & ( 30 | echo %dec% 31 | exit /b %errorlevel% 32 | ) 33 | ) 34 | 35 | exit /b %errorlevel% 36 | 37 | 45 | 46 | 59 | -------------------------------------------------------------------------------- /hybrids/mshta/btoa.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal 4 | 5 | if "%~1" equ "" ( 6 | echo %~nx1 - encodes string to base 64 7 | echo example: 8 | echo %~nx1 string [rtrnVar] 9 | echo( 10 | echo rtrnVar - variable where where the result will be stored. 11 | echo if not defined the result will be printed in console 12 | exit /b 0 13 | ) 14 | 15 | set "string=%~1" 16 | 17 | 18 | 19 | for /f "delims=" %%# in ('echo %string%^|mshta.exe "%~f0"') do ( 20 | set b64=%%# 21 | ) 22 | 23 | if "%~2" neq "" ( 24 | endlocal & ( 25 | set "%~2=%b64%" 26 | exit /b %errorlevel% 27 | ) 28 | ) else ( 29 | endlocal & ( 30 | echo %b64% 31 | exit /b %errorlevel% 32 | ) 33 | ) 34 | 35 | exit /b %errorlevel% 36 | 37 | 45 | 46 | 59 | -------------------------------------------------------------------------------- /hybrids/mshta/freeMem.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | for /f "usebackq" %%a in (`mshta ^"javascript^:code^(close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableMBytes^)^)^); ^"`) do set free_mem=%%a 3 | echo %free_mem% 4 | -------------------------------------------------------------------------------- /hybrids/mshta/printClip.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :printclip 3 | :: prints clipboard data 4 | for /f "usebackq tokens=* delims=" %%i in ( 5 | `mshta "javascript:Code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(clipboardData.getData('Text'))));"` 6 | ) do ( 7 | (echo(%%i) 8 | ) 9 | exit /b %errorlevel% 10 | -------------------------------------------------------------------------------- /hybrids/mshta/say.bat: -------------------------------------------------------------------------------- 1 | :speak 2 | @echo off 3 | setlocal enableDelayedExpansion 4 | set "toSay=%~1" 5 | mshta "javascript:code(close((v=new ActiveXObject('SAPI.SpVoice')).GetVoices()&&v.Speak('!toSay!')))" 6 | endLocal 7 | -------------------------------------------------------------------------------- /hybrids/mshta/start.bckgrnd.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | rem ::: check if help need to be called ::: 5 | rem : 6 | 7 | for /f "usebackq tokens=1,2,3,4,5,6,7 delims= " %%A in ('-h -help /help /h "" /? -?') do ( 8 | for %%# in (%%A %%B %%C %%D "%%~E" ) do if /i "%~1" equ "%%~#" goto :help 9 | 10 | if "%~1" equ "%%~F" goto :help 11 | if "%~1" equ "%%~G" goto :help 12 | ) 13 | 14 | rem : 15 | rem ::: end help checks ::: 16 | 17 | 18 | rem ::: arg parsing and checking ::: 19 | rem : 20 | set /A shifter=1 21 | set "workdir=." 22 | set "commandline= " 23 | set "exec=" 24 | 25 | 26 | :arg_parser 27 | 28 | 29 | if "%~1" equ "-exec" set "exec=%~2" 30 | if "%~1" equ "-commandline" set "commandline=%~2" 31 | if "%~1" equ "-workdir" set "workdir=%~2" 32 | 33 | shift & shift 34 | set /A shifter=shifter + 1 35 | 36 | if %shifter% EQU 4 goto :end_arg_parser 37 | if "%~1" EQU "" goto :end_arg_parser 38 | goto :arg_parser 39 | 40 | 41 | :end_arg_parser 42 | rem : 43 | rem ::: end of arg parsing ::: 44 | 45 | rem ::: validate arguments ::: 46 | rem : 47 | 48 | set "exec_path=" 49 | if not defined exec echo executable not defined && exit /b 1 50 | if exist "%exec%" for /f "usebackq" %%E in ("%exec%") do set "exec_path=%%~dpfsnxE" 51 | if not defined exec_path for %%E in ("%exec%") do set "exec_path=%%~dpfsnx$PATH:E" 52 | if not defined exec_path echo executable "%exec%" does not exist && exit /b 2 53 | for %%W in ("%workdir%") do set "workdir=%%~dpW" 54 | if not exist "%workdir%" echo target directory "%workdir%" not exist && exit /b 3 55 | echo %commandline% | find """" >nul 2>&1 && ( echo command line contains quotes and you don't want this & exit /b 4) 56 | 57 | rem : 58 | rem ::: end of validation ::: 59 | 60 | rem ::: construct mshta command ::: 61 | rem : 62 | set "vbs_w32process=vbscript:execute("set w32ps=GetObject(""winmgmts:"").Get(""Win32_ProcessStartup"").SpawnInstance_():w32ps.ShowWindow=0:" 63 | set "vbs_stream_writer=CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(""Rerurn code: ""&" 64 | set "vbs_start_process=GetObject(""winmgmts:"").Get(""Win32_Process"").Create(""%exec_path% %commandline%"",""%workdir%"",w32ps,pid)&vbCrLf&""PID: ""&pid)" 65 | set "vbs_end=:Close")" 66 | 67 | rem : 68 | rem ::: end construct mshta command ::: 69 | 70 | rem ::: call mshta ::: 71 | rem : 72 | mshta %vbs_w32process%%vbs_stream_writer%%vbs_start_process%%vbs_end%| findstr "^" 73 | rem : 74 | rem ::: end mshta call ::: 75 | 76 | 77 | endlocal 78 | exit /b 0 79 | 80 | :help 81 | echo %~nx0 starts a background/invisible process and return its PID 82 | echo %~nx0 -exec executable [-commandline commandLine] [-workdir workdir] 83 | echo uses mshta/vbscript and does not require enabled WSH 84 | echo by Vasil "npocmaka" Arnaudov 85 | exit /b 0 86 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/buttons.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /*JScript comment 2 | @echo off 3 | echo -- %~f0 -- 4 | if "%~1" equ "" ( 5 | echo usage: 6 | echo %~nx0 [button_name [button_name[..]]] 7 | exit /b 0 8 | ) 9 | 10 | ( 11 | echo %* 12 | )|( 13 | mshta "about:buttonsChoose:
" 14 | )|( 15 | for /f "tokens=* delims=" %%R in ('more') do @( 16 | @(@echo(%%R) 17 | ) 18 | ) 19 | 20 | rem echo %result% 21 | exit /b 0 22 | 23 | **/ 24 | 25 | var argline; 26 | var errmessage; 27 | var elements = new Array(); 28 | var textnode; 29 | 30 | 31 | function clckd(a){ 32 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 33 | close(fso.Write(a)); 34 | } 35 | 36 | function prepare(){ 37 | window.resizeTo(400,250); 38 | try { 39 | var fso2= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0); 40 | argline=fso2.ReadLine(); 41 | var args=argline.split(" "); 42 | } catch (err) { 43 | errmessage = "cannot get the input"; 44 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 45 | fso.Write(errmessage); 46 | } 47 | 48 | var br_element = document.createElement('br');; 49 | 50 | var i; 51 | var temp_element; 52 | for (i = 0; i < args.length; i++) { 53 | temp_element = document.createElement("input"); 54 | temp_element.setAttribute("type", "button"); 55 | temp_element.setAttribute("value", args[i]); 56 | temp_element.setAttribute("number", i+1); 57 | temp_element.onclick= function(){clckd(this.number)}; 58 | elements.push(temp_element); 59 | } 60 | 61 | for (i = 0; i < args.length; i++) { 62 | var br_element = document.createElement('br');; 63 | var container = document.getElementById('container'); 64 | if (args[i] != "") { 65 | textnode=document.createTextNode(args[i]); 66 | container.appendChild(elements[i]); 67 | container.appendChild(br_element); 68 | } 69 | } 70 | container.appendChild(br_element); 71 | } 72 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/choose.button.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /*** Javascript comment 2 | @echo off 3 | rem :: a UI extension example for bat files 4 | rem :: that not require enabled WSH as it uses mshta 5 | rem :: As mshta allows JScript directives it is possible to 6 | rem :: to use the batch file as javascript source file 7 | rem :: seen first here 8 | rem :: https://groups.google.com/forum/#!msg/alt.msdos.batch.nt/b8q29_uLfQs/4uoVLRo1uOsJ 9 | rem :: 10 | rem :: by Vasil "npocmaka" Arnaudov 11 | rem :: 12 | 13 | 14 | ( 15 | mshta "about:chooserbuttons:" 16 | )|( 17 | for /f "tokens=* delims=" %%B in ('more') do @( 18 | echo selected buton: %%B 19 | ) 20 | ) 21 | exit /b 0 22 | 23 | **/ 24 | 25 | function clckd(a){ 26 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 27 | close(fso.Write(a)); 28 | } 29 | 30 | function prepare(){ 31 | window.resizeTo(200,150); 32 | var element1 = document.createElement("input"); 33 | element1.setAttribute("type", "button"); 34 | element1.setAttribute("value", "yep"); 35 | //this will not work on IE or MSHTA 36 | // element1.setAttribute("onclick", "clckd('yep');"); 37 | element1.onclick= function() {clckd('yep');}; 38 | 39 | var element2 = document.createElement("input"); 40 | element2.setAttribute("type", "button"); 41 | element2.setAttribute("value", "nope"); 42 | //this will not work on IE or MSHTA 43 | // element2.setAttribute("onclick", "clckd('nope');"); 44 | element2.onclick= function() {clckd('nope');}; 45 | 46 | 47 | var container = document.getElementById('container'); 48 | container.appendChild(element1); 49 | container.appendChild(element2); 50 | 51 | //alert(document.getElementById('container').innerHTML); 52 | } 53 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/countdown.bat: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | It's the final countdown 19 | 20 | 21 |

Seconds left

22 |
--
23 | 24 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/passwordSubmiter.bat: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | Password submitter 15 | 16 | 17 | 31 | 32 | 33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/radioButtons.bat: -------------------------------------------------------------------------------- 1 | @if (@X)==(@Y) @end /*JScript comment 2 | @echo off 3 | 4 | if "%~1" equ "" ( 5 | echo usage: 6 | echo %~nx0 [radio_button_name [radio_button_name[..]]] 7 | exit /b 0 8 | ) 9 | 10 | ( 11 | echo %* 12 | )|( 13 | mshta "about:radioChoose:
" 14 | )|( 15 | for /f "tokens=* delims=" %%R in ('more') do @( 16 | @(@echo(%%R) 17 | ) 18 | ) 19 | 20 | rem echo %result% 21 | exit /b 0 22 | 23 | **/ 24 | 25 | var argline; 26 | var result; 27 | var errmessage; 28 | var elements = new Array(); 29 | var textnode; 30 | 31 | function clckd(){ 32 | // alert(a); 33 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 34 | 35 | //fso.Write(line); 36 | //close(fso.Write(a)); 37 | 38 | for (i = 0; i < elements.length; i++) { 39 | if (elements[i].checked ) { 40 | close(fso.Write(i+1)); 41 | //alert(i+1); 42 | } 43 | } 44 | 45 | } 46 | 47 | function prepare(){ 48 | 49 | try { 50 | var fso2= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0); 51 | argline=fso2.ReadLine(); 52 | //alert(argline); 53 | //argline = "radio gaga radio gogo someone still loves you" 54 | var args=argline.split(" "); 55 | } catch (err) { 56 | errmessage = "cannot get the input"; 57 | var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 58 | fso.Write(errmessage); 59 | } 60 | 61 | var br_element = document.createElement('br');; 62 | 63 | var i; 64 | var temp_element; 65 | for (i = 0; i < args.length; i++) { 66 | temp_element = document.createElement("input"); 67 | temp_element.setAttribute("type", "radio"); 68 | temp_element.setAttribute("name", "gaga"); 69 | temp_element.setAttribute("value", i); 70 | temp_element.setAttribute("id", "gaga".concat(i)); 71 | temp_element.value=args[i]; 72 | elements.push(temp_element); 73 | } 74 | 75 | for (i = 0; i < args.length; i++) { 76 | var br_element = document.createElement('br');; 77 | var container = document.getElementById('container'); 78 | if (args[i] != "") { 79 | textnode=document.createTextNode(args[i]); 80 | container.appendChild(elements[i]); 81 | container.appendChild(textnode); 82 | container.appendChild(br_element); 83 | } 84 | } 85 | container.appendChild(br_element); 86 | var submit = document.createElement("input"); 87 | 88 | submit.setAttribute("type", "button"); 89 | submit.setAttribute("value", "submit"); 90 | submit.onclick= function() {clckd();}; 91 | container.appendChild(submit); 92 | 93 | //alert(document.getElementById('container').innerHTML); 94 | } 95 | -------------------------------------------------------------------------------- /hybrids/mshta/ui.extensions/userInput.bat: -------------------------------------------------------------------------------- 1 | 30 | 31 | 32 | User Input 33 | 34 | 35 | 49 | 50 | 51 |
52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /hybrids/mshta/weekNumber.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | for /f %%W in ( 4 | 'mshta vbscript:Execute("createobject(""scripting.filesystemobject"").GetStandardStream(1).writeline(DatePart(""ww"",Now()))"^^^&close^)' 5 | ) do @( 6 | set "weekn=%%W" 7 | ) 8 | 9 | echo %weekn% 10 | -------------------------------------------------------------------------------- /hybrids/wsh/EjectCD.bat: -------------------------------------------------------------------------------- 1 | @cScript.EXE //noLogo "%~f0?.WSF" //job:info %~nx0 %* 2 | @exit /b 0 3 | 4 | 5 | 69 | 70 | -------------------------------------------------------------------------------- /hybrids/wsh/vbexecutor.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set job=Execute 3 | for %%# in (-h /h /help -help) do ( 4 | if "%~1" equ "%%~#" ( 5 | (echo() 6 | echo Executes vbscript statements 7 | (echo() 8 | echo Usage: 9 | echo %~nx0 [function] statement [statement] 10 | (echo() 11 | echo double quotes in ststements must be replaced with single quotes 12 | echo in ordred to avoid collision with command line arguments 13 | (echo() 14 | echo default function is /Execute 15 | echo other options are /Eval and /ExecuteGlobal 16 | (echo() 17 | echo examples: 18 | echo call %~nx0 "Wscript.Echo('example')" "WScript.Sleep(3000)" 19 | echo call %~nx0 /Execute "Wscript.Echo('example')" "WScript.Sleep(3000)" 20 | echo call %~nx0 /ExecuteGlobal "Function SumTwo(a,b):SumTwo=a+b:End Function" "WScript.Echo(SumTwo(2,2))" 21 | echo call %~nx0 /Eval "WScript.Echo(2+2)" 22 | exit /b 0 23 | ) 24 | ) 25 | 26 | cscript /noLogo "%~f0?.WSF" //job:execute %* 27 | exit /b %ErrorLevel% 28 | 29 | 30 | 65 | 66 | -------------------------------------------------------------------------------- /math/isInteger.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :isInterer input [returnVar] 4 | setlocal enableDelayedexpansion 5 | set "input=%~1" 6 | 7 | if "!input:~0,1!" equ "-" ( 8 | set "input=!input:~1!" 9 | ) else ( 10 | if "!input:~0,1!" equ "+" set "input=!input:~1!" 11 | ) 12 | 13 | for %%# in (1 2 3 4 5 6 7 8 9 0) do ( 14 | if not "!input!" == "" ( 15 | set "input=!input:%%#=!" 16 | ) 17 | ) 18 | 19 | if "!input!" equ "" ( 20 | set result=true 21 | ) else ( 22 | set result=false 23 | ) 24 | 25 | endlocal & if "%~2" neq "" (set %~2=%result%) else echo %result% 26 | -------------------------------------------------------------------------------- /math/removeLeadingZeroes.bat: -------------------------------------------------------------------------------- 1 | ::http://stackoverflow.com/questions/14762813/remove-leading-zeros-in-batch-file 2 | 3 | :: exit /b number automatically removes leading zeroes and does not take the number as octal 4 | :: also requires small piece of coding , but could affect the performance a little bit 5 | 6 | :removeLeadingZeroes number [rtnVar] 7 | setlocal 8 | cmd /c exit /b %~1 9 | endlocal && ( 10 | if "%~2" neq "" (set %~2=%errorlevel%) else echo %errorlevel% 11 | ) 12 | -------------------------------------------------------------------------------- /network/bitsDownloader.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | :: uses bitsadmin utility to download a file 5 | :: bitsadmin is not available in winXP Home edition 6 | :: the only way to download a file with 'pure' batch 7 | :download 8 | 9 | if "%2" equ "" ( 10 | call :help 11 | exit /b 5 12 | ) 13 | 14 | if "%1" equ "" ( 15 | call :help 16 | exit /b 6 17 | ) 18 | set url=%~1 19 | set file=%~2 20 | rem ---- 21 | if "%~3" NEQ "" ( 22 | set /A timeout=%~3 23 | ) else ( 24 | set timeout=5 25 | ) 26 | 27 | bitsadmin /cancel download >nul 28 | bitsadmin /create /download download >nul 29 | call bitsadmin /addfile download "%url%" "%CD%\%file%" >nul 30 | bitsadmin /resume download >nul 31 | bitsadmin /setproxysettings download AUTODETECT >nul 32 | 33 | set /a attempts=0 34 | :repeat 35 | set /a attempts +=1 36 | if "%attempts%" EQU "10" ( 37 | echo TIMED OUT 38 | endlocal 39 | exit /b 1 40 | ) 41 | bitsadmin /info download /verbose | find "STATE: ERROR" >nul 2>&1 && endlocal && bitsadmin /cancel download && echo SOME KIND OF ERROR && exit /b 2 42 | bitsadmin /info download /verbose | find "STATE: SUSPENDED" >nul 2>&1 && endlocal && bitsadmin /cancel download &&echo FILE WAS NOT ADDED && exit /b 3 43 | bitsadmin /info download /verbose | find "STATE: TRANSIENT_ERROR" >nul 2>&1 && endlocal && bitsadmin /cancel download &&echo TRANSIENT ERROR && exit /b 4 44 | bitsadmin /info download /verbose | find "STATE: TRANSFERRED" >nul 2>&1 && goto :finishing 45 | 46 | w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:%timeout% >nul 2>&1 47 | goto :repeat 48 | :finishing 49 | bitsadmin /complete download >nul 50 | echo download finished 51 | endlocal 52 | goto :eof 53 | 54 | :help 55 | echo %~n0 url file [timeout] 56 | echo. 57 | echo url - the source for download 58 | echo file - file name in local directory where the file will be stored 59 | echo timeout - number in seconds between each check if download is complete (attempts are 10) 60 | echo. 61 | goto :eof 62 | -------------------------------------------------------------------------------- /network/checkNet.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :checkNet 3 | 4 | :: 5 | :: checks if a network interface with given name is connected 6 | :: or not through ipconfig command 7 | :: 8 | 9 | setlocal 10 | 11 | if "%~1" equ "" echo no network name passed & exit /b 1 12 | 13 | set "network_to_check=%~1" 14 | if "%network_to_check:~-1,1%" NEQ ":" set "network_to_check=%network_to_check%:" 15 | 16 | set nt=0 17 | setlocal enableDelayedExpansion 18 | for /f "skip=3 delims=" %%$ in ('ipconfig') do ( 19 | set "line=%%$" 20 | ! echo %%$ >&2 21 | 22 | if "!line:~0,1!" neq " " ( 23 | set /a nt=nt+1 24 | set _nt!nt!=!line! 25 | 26 | ) else ( 27 | ! echo ---- 28 | for /f %%# in ("!nt!") do ( 29 | ! echo a:%%# 30 | ! echo --- %%# --- 31 | 32 | set "_nt!nt!=!_nt%%#! !line!" 33 | 34 | ) 35 | ) 36 | ) 37 | 38 | set _nt|find /i "%network_to_check%" >nul 2>nul||( 39 | echo network not found 40 | exit /b 1 41 | ) 42 | 43 | set _nt| find /i "%network_to_check%"|find /i "Media disconnected" >nul 2>nul&&( 44 | echo disconnected 45 | exit /b 1 46 | ) 47 | 48 | echo connected 49 | 50 | endlocal 51 | endlocal 52 | -------------------------------------------------------------------------------- /other/beeper.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | ::Define a Linefeed variable 4 | (set LF=^ 5 | %=-=% 6 | ) 7 | 8 | for /f eol^=^%LF%%LF%^ delims^= %%A in ( 9 | 'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x07"' 10 | ) do echo(%%A 11 | -------------------------------------------------------------------------------- /other/continueEnter.bat: -------------------------------------------------------------------------------- 1 | :: continue only after enter is pressed 2 | :: Unlike set /p= will not save the typed non-enter keys 3 | :: in the buffer 4 | :: http://ss64.org/viewtopic.php?id=1695 5 | runas /user:# "" >nul 2>&1 6 | -------------------------------------------------------------------------------- /other/listBrosers.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableExtensions 3 | 4 | rem --- requires admin permissions --- 5 | 6 | echo. 7 | echo. 8 | echo INSTALLED BROWSERS 9 | echo. 10 | echo. 11 | 12 | rem ::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 | rem :: exporting registry values for installed browsers 14 | rem ::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 | 16 | rem for 64 bit systems 17 | START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet 18 | rem for 32 bit systems 19 | if not exist "%Temp%\BROW3.reg" START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet 20 | 21 | setLocal enableDelayedExpansion 22 | for /f "tokens=*" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /E "DefaultIcon]"') do ( 23 | rem extracting browser name from icon path 24 | set "browser=%%B" 25 | rem removing \DefaultIcon] string 26 | set "browser=!browser:\DefaultIcon]=!" 27 | rem get the browser name 28 | for %%P in ("!browser!") do echo %%~nP 29 | ) 30 | endLocal 31 | 32 | echo. 33 | echo. 34 | echo EXECUTABLES PATHS 35 | echo. 36 | echo. 37 | 38 | setLocal enableDelayedExpansion 39 | for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe\\\",0\"^"') do ( 40 | set "browser=%%~B" 41 | set "browser=!browser:\\=\!" 42 | echo !browser! 43 | 44 | ) 45 | setLocal enableDelayedExpansion 46 | for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe,0\"^"') do ( 47 | set "browser=%%~B" 48 | set "browser=!browser:\\=\!" 49 | set "browser=!browser:,0=!" 50 | echo !browser! 51 | 52 | ) 53 | endLocal 54 | 55 | 56 | rem delete temp file 57 | del /Q /F "%Temp%\BROW3.reg" 58 | 59 | 60 | echo. 61 | echo. 62 | echo DEFAULT BROWSER 63 | echo. 64 | echo. 65 | 66 | START /W REGEDIT /E "%Temp%\BROW5.reg" HKEY_CLASSES_ROOT\http\shell\open\command 67 | setLocal enableDelayedExpansion 68 | for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW5.reg" ^| find "@"') do ( 69 | set "default=%%B" 70 | rem removing double slashes 71 | set "default=!default:\\=\!" 72 | rem removing end slash 73 | set "default=!default:~0,-1!" 74 | rem get the name 75 | for %%D in ("!default!") do echo %%~nD 76 | ) 77 | endLocal 78 | del /Q /F "%Temp%\BROW5.reg" 79 | 80 | echo. 81 | echo. 82 | echo DEFAULT .HTML VIEWER 83 | echo. 84 | echo. 85 | 86 | START /W REGEDIT /E "%Temp%\BROW6.reg" HKEY_CLASSES_ROOT\htmlfile\shell\open\command 87 | setLocal enableDelayedExpansion 88 | for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW6.reg" ^| find "@"') do ( 89 | set "default=%%B" 90 | set "default=!default:\\=\!" 91 | set "default=!default:~0,-1!" 92 | for %%D in ("!default!") do echo %%~nD 93 | ) 94 | endLocal 95 | del /Q /F "%Temp%\BROW6.reg" 96 | echo. 97 | echo. 98 | pause 99 | :: 100 | :: by Vasil "npocmaka" Arnaudov 101 | :: 102 | -------------------------------------------------------------------------------- /other/listBrowsers.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: list installed browsers 3 | :: uses regedit so it's compatible with windows XP 4 | setlocal enableExtensions 5 | 6 | echo. 7 | echo. 8 | echo INSTALLED BROWSERS 9 | echo. 10 | echo. 11 | 12 | rem ::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 | rem :: exporting registry values for installed browsers 14 | rem ::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 | 16 | rem for 64 bit systems 17 | START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet 18 | rem for 32 bit systems 19 | if not exist "%Temp%\BROW3.reg" START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet 20 | 21 | setLocal enableDelayedExpansion 22 | for /f "tokens=*" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /E "DefaultIcon]"') do ( 23 | rem extracting browser name from icon path 24 | set "browser=%%B" 25 | rem removing \DefaultIcon] string 26 | set "browser=!browser:\DefaultIcon]=!" 27 | rem get the browser name 28 | for %%P in ("!browser!") do echo %%~nP 29 | ) 30 | endLocal 31 | 32 | echo. 33 | echo. 34 | echo EXECUTABLES PATHS 35 | echo. 36 | echo. 37 | 38 | setLocal enableDelayedExpansion 39 | for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe\\\",0\"^"') do ( 40 | set "browser=%%~B" 41 | set "browser=!browser:\\=\!" 42 | echo !browser! 43 | 44 | ) 45 | setLocal enableDelayedExpansion 46 | for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe,0\"^"') do ( 47 | set "browser=%%~B" 48 | set "browser=!browser:\\=\!" 49 | set "browser=!browser:,0=!" 50 | echo !browser! 51 | 52 | ) 53 | endLocal 54 | 55 | 56 | rem delete temp file 57 | del /Q /F "%Temp%\BROW3.reg" 58 | 59 | 60 | echo. 61 | echo. 62 | echo DEFAULT BROWSER 63 | echo. 64 | echo. 65 | 66 | START /W REGEDIT /E "%Temp%\BROW5.reg" HKEY_CLASSES_ROOT\http\shell\open\command 67 | setLocal enableDelayedExpansion 68 | for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW5.reg" ^| find "@"') do ( 69 | set "default=%%B" 70 | rem removing double slashes 71 | set "default=!default:\\=\!" 72 | rem removing end slash 73 | set "default=!default:~0,-1!" 74 | rem get the name 75 | for %%D in ("!default!") do echo %%~nD 76 | ) 77 | endLocal 78 | del /Q /F "%Temp%\BROW5.reg" 79 | 80 | echo. 81 | echo. 82 | echo DEFAULT .HTML VIEWER 83 | echo. 84 | echo. 85 | 86 | START /W REGEDIT /E "%Temp%\BROW6.reg" HKEY_CLASSES_ROOT\htmlfile\shell\open\command 87 | setLocal enableDelayedExpansion 88 | for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW6.reg" ^| find "@"') do ( 89 | set "default=%%B" 90 | set "default=!default:\\=\!" 91 | set "default=!default:~0,-1!" 92 | for %%D in ("!default!") do echo %%~nD 93 | ) 94 | endLocal 95 | del /Q /F "%Temp%\BROW6.reg" 96 | echo. 97 | echo. 98 | pause 99 | -------------------------------------------------------------------------------- /other/officeVersion.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :office_ver 3 | setlocal enableDelayedExpansion 4 | echo %~1 | find /i "help" >nul 2>&1 && ( goto :help ) 5 | 6 | for /f "tokens=2 delims==" %%O in ('ftype ^|findstr /r /I "\\OFFICE[0-9]*" 2^>nul') do ( 7 | set "verp=%%~O" 8 | goto :end_for 9 | ) 10 | :end_for 11 | 12 | for %%P in ("%verp%") do ( 13 | set "off_path=%%~dpP" 14 | for %%V in ("!off_path:~0,-1!") do ( 15 | 16 | set "office_version=%%~nV" 17 | goto :end_for2 18 | ) 19 | ) 20 | :end_for2 21 | 22 | echo internal version: %office_version% 23 | echo %office_version% | find /i "office7" >nul 2>&1&& ( 24 | echo "Office 97" 25 | if "%~1" neq "" ( endlocal & set "%~1=Office 97" 26 | exit /b 0 27 | ) 28 | ) 29 | echo %office_version% | find /i "office8" >nul 2>&1 && ( 30 | echo "Office XP" 31 | if "%~1" neq "" ( endlocal & set "%~1=Office XP" 32 | exit /b 0 33 | ) 34 | ) 35 | echo %office_version% | find /i "office9" >nul 2>&1 && ( 36 | echo "Office 2000" 37 | if "%~1" neq "" ( endlocal & set "%~1=Office 2000" 38 | exit /b 0 39 | ) 40 | ) 41 | echo %office_version% | find /i "office10" >nul 2>&1 && ( 42 | echo "Office XP" 43 | if "%~1" neq "" ( endlocal & set "%~1=Office XP" 44 | exit /b 0 45 | ) 46 | ) 47 | echo %office_version% | find /i "office11" >nul 2>&1 && ( 48 | echo "Office 2003" 49 | if "%~1" neq "" ( endlocal & set "%~1=Office 2003" 50 | exit /b 0 51 | ) 52 | ) 53 | echo %office_version% | find /i "office12" >nul 2>&1 && ( 54 | echo "Office 2007" 55 | if "%~1" neq "" ( endlocal & set "%~1=Office 2007" 56 | exit /b 0 57 | ) 58 | ) 59 | echo %office_version% | find /i "office14" >nul 2>&1 && ( 60 | echo "Office 2010" 61 | if "%~1" neq "" ( endlocal & set "%~1=Office 2010" 62 | exit /b 0 63 | ) 64 | ) 65 | echo %office_version% | find /i "office15" >nul 2>&1 && ( 66 | echo "Office 2013" 67 | if "%~1" neq "" ( endlocal & set "%~1=Office 2013" 68 | exit /b 0 69 | ) 70 | ) 71 | 72 | echo %office_version% | find /i "office16" >nul 2>&1 && ( 73 | echo "Office 2016" 74 | if "%~1" neq "" ( endlocal & set "%~1=Office 2016" 75 | exit /b 0 76 | ) 77 | ) 78 | 79 | endlocal 80 | goto :eof 81 | rem MAPPING: 82 | rem Office 97 - 7.0 83 | rem Office 98 - 8.0 84 | rem Office 2000 - 9.0 85 | rem Office XP - 10.0 86 | rem Office 2003 - 11.0 87 | rem Office 2007 - 12.0 88 | rem Office 2010 - 14.0 89 | rem Office 2013 - 15.0 90 | rem Office 2016 - 16.0 91 | :help 92 | echo %~n0 - displays current microsoft office version 93 | echo %~n0 [RtnVar] 94 | echo( 95 | RtnVar - stores result in variable RtnVar 96 | echo( 97 | echo by Vasil "npocmaka" Arnaudov 98 | -------------------------------------------------------------------------------- /other/pushdCounter.bat: -------------------------------------------------------------------------------- 1 | :pushd_counter 2 | ::http://ss64.org/viewtopic.php?id=1697 3 | @echo off 4 | set prompt_backup=%prompt% 5 | prompt $+ 6 | ( echo on 7 | for %%a in (1) do ( @rem 8 | ) 9 | )>%temp%\p.tmp 10 | @echo off 11 | prompt %prompt_backup% 12 | set "prompt_backup=" 13 | for /f "usebackq tokens=1 delims=() " %%P in ("%temp%\p.tmp") do ( 14 | set s=%%P 15 | ) 16 | del %temp%\p.tmp /q >nul 17 | setlocal EnableDelayedExpansion 18 | set "s=#!s!" 19 | set "len=0" 20 | for %%A in (2187 729 243 81 27 9 3 1) do ( 21 | set /A mod=2*%%A 22 | for %%Z in (!mod!) do ( 23 | if "!s:~%%Z,1!" neq "" ( 24 | set /a "len+=%%Z" 25 | set "s=!s:~%%Z!" 26 | 27 | ) else ( 28 | if "!s:~%%A,1!" neq "" ( 29 | set /a "len+=%%A" 30 | set "s=!s:~%%A!" 31 | ) 32 | ) 33 | ) 34 | ) 35 | endlocal & echo %len% 36 | set "s=" 37 | exit /b 38 | -------------------------------------------------------------------------------- /other/pushdCounterTmpF.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd >%temp%\temp.temp 3 | type %temp%\temp.temp | find /c "\" 4 | rem find /c "\" %temp%\temp.temp 5 | del %temp%\temp.temp /q >nul 6 | -------------------------------------------------------------------------------- /other/setlocalLevelCounter.bat: -------------------------------------------------------------------------------- 1 | set "lev=" 2 | (@for /l %%i in (1 1 33) do ( setlocal 2>nul && set lev=%%i ) && for /l %%o in (1 1 %lev% ) do ( endlocal & set lev=%lev%))&(set /a lev=32-lev) 3 | echo %lev% 4 | 5 | :: http://ss64.org/viewtopic.php?id=1778 6 | -------------------------------------------------------------------------------- /printing/printCHM.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if "%~1" equ "" ( 4 | echo usage: 5 | echo %~n0 file.chm 6 | exit /b 1 7 | ) 8 | 9 | if "%~x1" neq ".chm" ( 10 | echo you need a file with .chm etension 11 | exit /b 2 12 | ) 13 | 14 | start "" /b /wait hh -decompile ~~ %~sf1 15 | 16 | for /r "~~" %%h in (*.htm) do ( 17 | rundll32.exe "%systemroot%\system32\mshtml.dll",PrintHTML "%%~fh" 18 | ) 19 | 20 | rd "~~" /s /q >nul 2>nul 21 | -------------------------------------------------------------------------------- /stringutils/countOfSubstrings.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :checkCountOf string countOf [rtnrVar] 3 | :: checks count of a substring in a string 4 | setlocal EnableDelayedExpansion 5 | set "string=aa" 6 | 7 | set "string=%~1" 8 | set "checkCountOf=%~2" 9 | 10 | if "%~1" equ "" ( 11 | if "%~3" neq "" ( 12 | endlocal & ( 13 | echo 0 14 | set "%~3=0" 15 | exit /b 0 16 | ) 17 | ) else ( 18 | endlocal & ( 19 | echo 0 20 | exit /b 0 21 | ) 22 | ) 23 | 24 | 25 | ) 26 | 27 | if "!checkCountOf!" equ "$" ( 28 | set "string=#%string%#" 29 | set "string=!string:%checkCountOf%%checkCountOf%=#%checkCountOf%#%checkCountOf%#!" 30 | ) else ( 31 | set "string=$%string%$" 32 | set "string=!string:%checkCountOf%%checkCountOf%=$%checkCountOf%$%checkCountOf%$!" 33 | ) 34 | 35 | 36 | set LF=^ 37 | 38 | 39 | rem ** Two empty lines are required 40 | set /a counter=0 41 | 42 | 43 | for %%L in ("!LF!") DO ( 44 | for /f "delims=" %%R in ("!checkCountOf!") do ( 45 | set "var=!string:%%~R%%~R=%%~L!" 46 | set "var=!var:%%~R=%%~L!" 47 | 48 | for /f "tokens=* delims=" %%# in ("!var!") do ( 49 | set /a counter=counter+1 50 | ) 51 | ) 52 | ) 53 | 54 | if !counter! gtr 0 ( 55 | set /a counter=counter-1 56 | ) 57 | 58 | if "%~3" neq "" ( 59 | endlocal & ( 60 | echo %counter% 61 | set "%~3=%counter%" 62 | ) 63 | ) else ( 64 | endlocal & ( 65 | echo %counter% 66 | ) 67 | ) 68 | -------------------------------------------------------------------------------- /stringutils/endsWith.bat: -------------------------------------------------------------------------------- 1 | :endsWith [%1 - string to be checked;%2 - string for checking ] 2 | 3 | @echo off 4 | rem :: sets errorlevel to 1 if %1 ends with %2 else sets errorlevel to 0 5 | 6 | setlocal EnableDelayedExpansion 7 | 8 | set "string=%~1" 9 | set "checker=%~2" 10 | rem set "var=!string:%~2=&echo.!" 11 | set LF=^ 12 | 13 | 14 | rem ** Two empty lines are required 15 | rem echo off 16 | for %%L in ("!LF!") DO ( 17 | for /f "delims=" %%R in ("!checker!") do ( 18 | rem set "var=!string:%%~R%%~R=%%~L!" 19 | set "var=!string:%%~R=%%L#!" 20 | ) 21 | ) 22 | for /f "delims=" %%P in (""!var!"") DO ( 23 | set "temp=%%~P" 24 | ) 25 | 26 | if "%temp%" EQU "#" ( 27 | endlocal & exit /b 1 28 | ) else ( 29 | endlocal & exist /b 0 30 | ) 31 | -------------------------------------------------------------------------------- /stringutils/indexOf.bat: -------------------------------------------------------------------------------- 1 | :indexof [%1 - string ; %2 - find index of ; %3 - if defined will store the result in variable with same name] 2 | ::http://ss64.org/viewtopic.php?id=1687 3 | @echo off 4 | setlocal enableDelayedExpansion 5 | 6 | set "str=%~1" 7 | set "s=!str:%~2=&rem.!" 8 | set s=#%s% 9 | if "%s%" equ "#%~1" endlocal& if "%~3" neq "" (set %~3=-1&exit /b 0) else (echo -1&exit /b 0) 10 | 11 | set "len=0" 12 | for %%A in (2187 729 243 81 27 9 3 1) do ( 13 | set /A mod=2*%%A 14 | for %%Z in (!mod!) do ( 15 | if "!s:~%%Z,1!" neq "" ( 16 | set /a "len+=%%Z" 17 | set "s=!s:~%%Z!" 18 | 19 | ) else ( 20 | if "!s:~%%A,1!" neq "" ( 21 | set /a "len+=%%A" 22 | set "s=!s:~%%A!" 23 | ) 24 | ) 25 | ) 26 | ) 27 | endlocal & if "%~3" neq "" (set %~3=%len%) else echo %len% 28 | exit /b 0 29 | -------------------------------------------------------------------------------- /stringutils/lastIndexOf.bat: -------------------------------------------------------------------------------- 1 | :lastindexof [%1 - string ; %2 - find last index of ; %3 - if defined will store the result in variable with same name] 2 | ::http://ss64.org/viewtopic.php?id=1687 3 | @echo off 4 | setlocal enableDelayedExpansion 5 | 6 | 7 | set "str=%~1" 8 | set "splitter=%~2" 9 | 10 | set LF=^ 11 | 12 | 13 | rem ** Two empty lines are required 14 | echo off 15 | setlocal 16 | for %%L in ("!LF!") DO ( 17 | for /f "delims=" %%R in ("!splitter!") do ( 18 | set "var=!str:%%R=%%L!" 19 | ) 20 | ) 21 | 22 | for /f delims^=^" %%P in ("!var!") DO ( 23 | set "last_part=%%~P" 24 | ) 25 | 26 | if "!last_part!" equ "" if "%~3" NEQ "" ( 27 | echo "not contained" >2 28 | endlocal 29 | set %~3=-1 30 | exit 31 | ) else ( 32 | echo "not contained" >2 33 | endlocal 34 | echo -1 35 | ) 36 | setlocal DisableDelayedExpansion 37 | 38 | set ^"\n=^^^%LF%%LF%^%LF%%LF%^^" 39 | set $strLen=for /L %%n in (1 1 2) do if %%n==2 (%\n% 40 | for /F "tokens=1,2 delims=, " %%1 in ("!argv!") do (%\n% 41 | set "str=A!%%~2!"%\n% 42 | set "len=0"%\n% 43 | for /l %%A in (12,-1,0) do (%\n% 44 | set /a "len|=1<<%%A"%\n% 45 | for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"%\n% 46 | )%\n% 47 | for %%v in (!len!) do endlocal^&if "%%~b" neq "" (set "%%~1=%%v") else echo %%v%\n% 48 | ) %\n% 49 | ) ELSE setlocal enableDelayedExpansion ^& set argv=, 50 | 51 | 52 | %$strlen% strlen,str 53 | %$strlen% plen,last_part 54 | %$strlen% slen,splitter 55 | 56 | set /a lio=strlen-plen-slen 57 | endlocal & endlocal & endlocal & if "%~3" NEQ "" ( 58 | set "%~3=%lio%" 59 | ) else ( 60 | echo %lio% 61 | ) 62 | exit /b 0 63 | -------------------------------------------------------------------------------- /stringutils/reverse.bat: -------------------------------------------------------------------------------- 1 | :reverse [%1 - string to reverse ; %2 - if defined will store the result in variable with same name] 2 | @echo off 3 | setlocal disableDelayedExpansion 4 | set "str=%~1" 5 | set LF=^ 6 | 7 | 8 | rem ** Two empty lines are required 9 | set ^"\n=^^^%LF%%LF%^%LF%%LF%^^" 10 | set $strLen=for /L %%n in (1 1 2) do if %%n==2 (%\n% 11 | for /F "tokens=1,2 delims=, " %%1 in ("!argv!") do (%\n% 12 | set "str=A!%%~2!"%\n% 13 | set "len=0"%\n% 14 | for /l %%A in (12,-1,0) do (%\n% 15 | set /a "len|=1<<%%A"%\n% 16 | for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"%\n% 17 | )%\n% 18 | for %%v in (!len!) do endlocal^&if "%%~b" neq "" (set "%%~1=%%v") else echo %%v%\n% 19 | ) %\n% 20 | ) ELSE setlocal enableDelayedExpansion ^& set argv=, 21 | 22 | %$strLen% len,str 23 | setlocal enableDelayedExpansion 24 | 25 | set /a half=len/2 26 | set "res=!str:~%half%,-%half%!" 27 | 28 | for /L %%C in (%half%,-1,0) do ( 29 | set /a len=%len%-1-%%C 30 | if %%C neq %half% ( 31 | for %%c in (!len!) do ( 32 | set "res=!str:~%%c,1!!res!!str:~%%C,1!" 33 | ) 34 | ) 35 | 36 | ) 37 | endlocal & endlocal & if "%~2" NEQ "" (set %~2=%res%) else echo %res% 38 | -------------------------------------------------------------------------------- /stringutils/split.bat: -------------------------------------------------------------------------------- 1 | :split [%1 - string to be splitted;%2 - split by;%3 - possition to get; %4 - if defined will store the result in variable with same name] 2 | ::http://ss64.org/viewtopic.php?id=1687 3 | 4 | setlocal EnableDelayedExpansion 5 | 6 | set "string=%~2%~1" 7 | set "splitter=%~2" 8 | set /a position=%~3 9 | 10 | set LF=^ 11 | 12 | 13 | rem ** Two empty lines are required 14 | echo off 15 | for %%L in ("!LF!") DO ( 16 | for /f "delims=" %%R in ("!splitter!") do ( 17 | set "var=!string:%%~R%%~R=%%~L!" 18 | set "var=!var:%%~R=%%~L!" 19 | if "!var!" EQU "!string!" ( 20 | echo "%~1" does not contain "!splitter!" >&2 21 | exit /B 1 22 | ) 23 | ) 24 | ) 25 | 26 | if "!var!" equ "" ( 27 | endlocal & if "%~4" NEQ "" ( set "%~4=") 28 | ) 29 | if !position! LEQ 0 ( set "_skip=" ) else (set "_skip=skip=%position%") 30 | 31 | for /f "eol= %_skip% delims=" %%P in ("!var!") DO ( 32 | if "%%~P" neq "" ( 33 | set "part=%%~P" 34 | goto :end_for 35 | ) 36 | ) 37 | set "part=" 38 | :end_for 39 | if not defined part ( 40 | endlocal 41 | echo Index Out Of Bound >&2 42 | exit /B 2 43 | ) 44 | endlocal & if "%~4" NEQ "" (set %~4=%part%) else echo %part% 45 | exit /b 0 46 | -------------------------------------------------------------------------------- /stringutils/startsWith.bat: -------------------------------------------------------------------------------- 1 | :startsWith [%1 - string to be checked;%2 - string for checking ] 2 | @echo off 3 | rem :: sets errorlevel to 1 if %1 starts with %2 else sets errorlevel to 0 4 | 5 | setlocal EnableDelayedExpansion 6 | 7 | set "string=%~1" 8 | set "checker=%~2" 9 | rem set "var=!string:%~2=&echo.!" 10 | set LF=^ 11 | 12 | 13 | rem ** Two empty lines are required 14 | rem echo off 15 | for %%L in ("!LF!") DO ( 16 | for /f "delims=" %%R in ("!checker!") do ( 17 | rem set "var=!string:%%~R%%~R=%%~L!" 18 | set "var=!string:%%~R=#%%L!" 19 | ) 20 | ) 21 | for /f "delims=" %%P in (""!var!"") DO ( 22 | if "%%~P" EQU "#" ( 23 | endlocal & exit /b 1 24 | ) else ( 25 | endlocal & exit /b 0 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /stringutils/stringToHex.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :stringToHex 3 | del tmp.hex >nul 2>nul 4 | del tmp.str >nul 2>nul 5 | (echo|set /p=%~1)>tmp.str 6 | 7 | certutil -encodehex tmp.str tmp.hex >nul 8 | setlocal enableDelayedExpansion 9 | set "hex_str=" 10 | for /f "usebackq tokens=2 delims= " %%A in ("tmp.hex") do ( 11 | set "line=%%A" 12 | set hex_str=!hex_str!!line:~0,48! 13 | set hex_str=!hex_str: =! 14 | 15 | ) 16 | echo !hex_str! 17 | exit /b %errorlevel% 18 | -------------------------------------------------------------------------------- /stringutils/strlen0.3: -------------------------------------------------------------------------------- 1 | :strlen0.3 StrVar [RtnVar] 2 | setlocal EnableDelayedExpansion 3 | set "s=#!%~1!" 4 | set "len=0" 5 | for %%A in ( 6561 2187 729 243 81 27 9 3 1) do ( 6 | set /A mod=2*%%A 7 | for %%Z in (!mod!) do ( 8 | if !mod! GTR 8190 ( 9 | set mod=8190 10 | ) 11 | if "!s:~%%Z,1!" neq "" ( 12 | set /a "len+=%%Z" 13 | set "s=!s:~%%Z!" 14 | 15 | ) else ( 16 | if "!s:~%%A,1!" neq "" ( 17 | set /a "len+=%%A" 18 | set "s=!s:~%%A!" 19 | ) 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /stringutils/strlen2.5: -------------------------------------------------------------------------------- 1 | 2 | 3 | :strlen2.5 StrVar [RtnVar] 4 | :: http://ss64.org/viewtopic.php?id=424 5 | :: by Vasil "npocmaka" Arnaudov 6 | setlocal enableDelayedExpansion 7 | set "s=!%~1!" 8 | set len=0 9 | if defined s for /l %%N in (1,1,8192) do if "!s:~%%N,-%%N!" equ "" ( 10 | set len=%%N 11 | goto :break 12 | ) 13 | :break 14 | set /a len=2*!len!-1 15 | for %%E in (!len!) do ( 16 | set s=!s:~%%E! 17 | ) 18 | if "!s!" neq "" set /a len=!len!+1 19 | endlocal & if "%~2" neq "" (set %~2=%len%) else echo %len% 20 | exit /b 21 | 22 | -------------------------------------------------------------------------------- /stringutils/strlen2.9: -------------------------------------------------------------------------------- 1 | 2 | 3 | :strlen2.9 StrVar [RtnVar] 4 | :: http://ss64.org/viewtopic.php?id=424 5 | :: by Vasil "npocmaka" Arnaudov 6 | setlocal enableDelayedExpansion 7 | set "s=!%~1!" 8 | set len=0 9 | if defined s for /l %%N in (1,5,8192) do if "!s:~%%N,-%%N!" equ "" ( 10 | set len=%%N 11 | goto :break 12 | ) 13 | :break 14 | 15 | if !len! gtr 1 ( 16 | set /a len=2*!len!-12 17 | for %%E in (!len!) do ( 18 | set s=!s:~%%E! 19 | ) 20 | ) 21 | 22 | if defined s ( 23 | if "!s:~0!" neq "" set /a len=!len!+1 24 | if "!s:~1!" neq "" set /a len=!len!+1 25 | if "!s:~2!" neq "" set /a len=!len!+1 26 | if "!s:~3!" neq "" set /a len=!len!+1 27 | if "!s:~4!" neq "" set /a len=!len!+1 28 | if "!s:~5!" neq "" set /a len=!len!+1 29 | if "!s:~6!" neq "" set /a len=!len!+1 30 | if "!s:~7!" neq "" set /a len=!len!+1 31 | if "!s:~8!" neq "" set /a len=!len!+1 32 | if "!s:~9!" neq "" set /a len=!len!+1 33 | if "!s:~10!" neq "" set /a len=!len!+1 34 | if "!s:~11!" neq "" set /a len=!len!+1 35 | ) 36 | 37 | endlocal & if "%~2" neq "" (set %~2=%len%) else echo %len% 38 | exit /b 39 | 40 | -------------------------------------------------------------------------------- /stringutils/toLowerCase.bat: -------------------------------------------------------------------------------- 1 | :toLowerCase string [var] 2 | setlocal enableDelayedExpansion 3 | set "str=%~1" 4 | for %%# in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (set "str=!str:%%#=%%#!") 5 | endlocal & ( 6 | if "%~2" equ "" ( 7 | echo %str% 8 | ) else ( 9 | set "%~2=%str%" 10 | ) 11 | ) 12 | exit /b 0 13 | -------------------------------------------------------------------------------- /stringutils/toUpperCase.bat: -------------------------------------------------------------------------------- 1 | :toUpperCase string [var] 2 | setlocal enableDelayedExpansion 3 | set "str=%~1" 4 | for %%# in (A B C D E F G H I J K L M N O P P R S T U V W X Y Z) do (set "str=!str:%%#=%%#!") 5 | endlocal & ( 6 | if "%~2" equ "" ( 7 | echo %str% 8 | ) else ( 9 | set "%~2=%str%" 10 | ) 11 | ) 12 | exit /b 0 13 | -------------------------------------------------------------------------------- /system/checkPermissions.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: checks if the current session has admin permissions 3 | :: exist with 1 if there are 4 | :: and with 0 if there are no 5 | fltmc >nul 2>&1 && ( 6 | echo has admin permissions 7 | exit /b 1 8 | ) || ( 9 | echo has NOT admin permissions 10 | exit /b 0 11 | ) 12 | -------------------------------------------------------------------------------- /system/chkPermissions.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableDelayedExpansion 3 | :: checks if the current session has admin permissions 4 | :: uses only internal commands (checks existence of =:: variable) 5 | :: exist with 1 if there are 6 | :: and with 0 if there are no 7 | 8 | set "dv==::" 9 | if defined !dv! ( 10 | echo has NOT admin permissions 11 | endlocal & exit /b 0 12 | ) else ( 13 | echo has admin permissions 14 | endlocal & exit /b 1 15 | ) 16 | -------------------------------------------------------------------------------- /system/monitorInfo.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | del ~.txt /q /f >nul 2>nul 4 | start "" /w dxdiag /t ~ 5 | setlocal enableDelayedExpansion 6 | set currmon=1 7 | for /f "tokens=2 delims=:" %%a in ('find "Current Mode:" ~.txt') do ( 8 | echo Monitor !currmon! : %%a 9 | set /a currmon=currmon+1 10 | 11 | ) 12 | endlocal 13 | del ~.txt /q /f >nul 2>nul 14 | -------------------------------------------------------------------------------- /system/netVersions.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do ( 4 | set "l=" 5 | for /f "skip=1 tokens=2 delims=k" %%$ in ('"%%# #"') do ( 6 | if not defined l ( 7 | echo Installed: %%$ 8 | set l=%%$ 9 | ) 10 | ) 11 | ) 12 | 13 | echo latest installed .NET %l% 14 | -------------------------------------------------------------------------------- /system/screenres.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | ::gets the screen resolution depending on the windows version. 3 | setlocal 4 | for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b" 5 | 6 | 7 | if version lss 62 ( 8 | ::set "wmic_query=wmic desktopmonitor get screenheight, screenwidth /format:value" 9 | for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenwidth /format:value') do ( 10 | for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#" 11 | ) 12 | for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenheight /format:value') do ( 13 | for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#" 14 | ) 15 | 16 | ) else ( 17 | ::wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value 18 | for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentHorizontalResolution /format:value') do ( 19 | for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#" 20 | ) 21 | for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentVerticalResolution /format:value') do ( 22 | for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#" 23 | ) 24 | 25 | ) 26 | 27 | echo Resolution %x%x%y% 28 | 29 | endlocal 30 | --------------------------------------------------------------------------------