Skip to content

Commit

Permalink
Update vbexecutor.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
npocmaka committed Oct 15, 2015
1 parent 17657fe commit a2a7acf
Showing 1 changed file with 57 additions and 19 deletions.
76 changes: 57 additions & 19 deletions hybrids/wsh/vbexecutor.bat
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
@echo off
set job=Execute
for %%# in (-h /h /help -help) do (
if "%~1" equ "%%~#" (
(echo()
echo Executes vbscript statements
(echo()
echo Usage:
echo %~nx0 statement [statement]
(echo()
echo double quotes in ststements must be replaced with single quotes
echo in ordred to avoid collision with command line arguments
(echo()
echo example:
echo call %~nx0 "Wscript.Echo('example')" "WScript.Sleep(3000)"
exit /b 0
)
if "%~1" equ "%%~#" (
(echo()
echo Executes vbscript statements
(echo()
echo Usage:
echo %~nx0 [function] statement [statement]
(echo()
echo double quotes in ststements must be replaced with single quotes
echo in ordred to avoid collision with command line arguments
(echo()
echo default function is /Execute
echo other options are /Eval and /ExecuteGlobal
(echo()
echo examples:
echo call %~nx0 "Wscript.Echo('example')" "WScript.Sleep(3000)"
echo call %~nx0 /Execute "Wscript.Echo('example')" "WScript.Sleep(3000)"
echo call %~nx0 /ExecuteGlobal "Function SumTwo(a,b):SumTwo=a+b:End Function" "WScript.Echo(SumTwo(2,2))"
echo call %~nx0 /Eval "WScript.Echo(2+2)"
exit /b 0
)
)
cscript /noLogo "%~f0?.WSF" //job:execute %*

cscript /noLogo "%~f0?.WSF" //job:execute %*
exit /b %ErrorLevel%

<job id="execute">
<job id="Execute">
<script language="VBScript">
For i=0 to WScript.Arguments.Count-1
Execute(Replace(WScript.Arguments.Item(i),"'","""")):
Next
funct="/execute"
start=0:
Function startsWith (str , prefix )
startsWith = CBool (Left(str, Len(prefix)) = prefix )
End Function

check=LCase(WScript.Arguments.Item(0)):

If startsWith(check,"/") then
start=1:
select case check
case "/execute"
case "/executeglobal"
funct="/executeglobal"
case "/eval"
funct="/eval"
case else
Wscript.Echo("Invalid evaluation function " & check ):
Wscript.Quit(1):
end select
end if

For i=start to WScript.Arguments.Count-1
select case funct
case "/execute"
Execute(Replace(WScript.Arguments.Item(i),"'","""")):
case "/executeglobal"
ExecuteGlobal(Replace(WScript.Arguments.Item(i),"'","""")):
case "/eval"
Eval(Replace(WScript.Arguments.Item(i),"'",""""))
end select

Next
</script>
</job>

0 comments on commit a2a7acf

Please sign in to comment.