hackoo

Vbs2Bat_Integration.bat

May 28th, 2020
1,046
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. Title Vbs2Bat Intergration using Regex with vbscript by Hackoo 2020
  3. Set "InputFile=%~1"
  4. If ["%InputFile%"] EQU [""] Goto :Help
  5. Set "TempFile=%Temp%\%~n1.tmp"
  6. Set "OutPutFile=%~dpn1_.txt"
  7. Call :Search_Replace "%InputFile%" "%TempFile%"
  8. REM ------------------------Generate the formatted file------------------------------
  9. > "%OutPutFile%" (
  10.     echo @echo off
  11.     echo Call :Generate_VBS_File
  12.     echo Call :Execute_VBS_File
  13.     echo REM -----------------------------------------------------------------------------
  14.     echo :Generate_VBS_File
  15.     echo ^>"%%tmp%%\%%~n0.vbs" (
  16. )
  17. >> "%OutPutFile%" (@for /f "tokens=* delims=" %%a in ('Type "%TempFile%"') do echo. echo    %%a)
  18. >> "%OutPutFile%" (
  19.     echo ^)
  20.     echo Exit /B
  21.     echo REM -----------------------------------------------------------------------------
  22.     echo :Execute_VBS_File
  23.     echo cscript //nologo "%%tmp%%\%%~n0.vbs"
  24.     echo If Exist "%%tmp%%\%%~n0.vbs" Del "%%tmp%%\%%~n0.vbs"
  25.     echo Exit /B
  26.     echo REM -----------------------------------------------------------------------------
  27. )
  28. REM ---------------------------------------------------------------------------------
  29. If Exist "%TempFile%" Del "%TempFile%"
  30. If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Exit
  31. ::-----------------------------------------------------------------------------------
  32. :Search_Replace <InputFile> <OutPutFile>
  33. (
  34.     echo WScript.StdOut.WriteLine Search_Replace(Data^)
  35.     echo Function Search_Replace(Data^)
  36.     echo Dim strPattern, strReplace, strResult,oRegExp
  37.     echo Data = "%~1"
  38.     echo Data = WScript.StdIn.ReadAll
  39.     echo Set oRegExp = New RegExp
  40.     echo oRegExp.Global = True
  41.     echo oRegExp.Multiline = True
  42.     echo oRegExp.IgnoreCase = True
  43.     echo strPattern1 = "[)&<|>]"
  44.     echo oRegExp.Pattern = strPattern1
  45.     echo strReplace1 = "^$+"
  46.     echo strResult1 = oRegExp.Replace(Data,strReplace1^)
  47.     echo strPattern2 = "[%%]"
  48.     echo oRegExp.Pattern = strPattern2
  49.     echo strReplace2 = "%%$+"
  50.     echo strResult2 = oRegExp.Replace(strResult1,strReplace2^)
  51.     echo Search_Replace = strResult2
  52.     echo End Function
  53. )>"%tmp%\%~n0.vbs"
  54. cscript //nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
  55. If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
  56. Exit /B
  57. ::----------------------------------------------------------------------------------
  58. :Help
  59. Mode 70,4 & Color 0C
  60. echo(
  61. echo      You should drag and drop a VBS file over,
  62. echo      this script "%~nx0" to be converted !
  63. Timeout /T 10 /NoBreak>nul
  64. Exit
  65. ::----------------------------------------------------------------------------------
RAW Paste Data