编辑:现在我重新阅读了你的问题,我不确定你在问什么。您是在问如何运行 vbscript 吗?只需将其保存filename.vbs
并执行它
cscript filename.vbs
(或者cscript /nologo filename.vbs
如果您想避免显示 Microsoft 的 cscript 虚荣垃圾邮件)。
另一方面,如果您想将其合并到批处理脚本中,那么有很多方法可以将批处理脚本中的内容回显到外部文件。大多数人只是做类似的事情
echo Set oolApp = CreateObject^("Outlook.Application"^)>> vbsfile
或类似的,^
根据需要转义。但是,您可能会发现此页的 heredoc 方法很有用。这是使用我昨天帮助您制作的脚本的示例:
@if (@X)==(@Y) @end /* (batch + jscript hybrid script init)
:: *** Batch script *****
@echo off
setlocal enabledelayedexpansion
set recipient=myemail@esomeemail.com
for /f "delims=" %%I in ('wget "%~1" -O- -q 2^>NUL ^| findstr /i "last.*updated.*as.*of"') do (
for /f "delims=" %%x in ('cscript /nologo /e:jscript "%~f0" "%%I"') do (
set /a "thirtyMinutes = 30 * 60 * 1000"
if %%x GEQ !thirtyMinutes! (
call :doEmail
)
)
exit /b
)
exit /b
:doEmail
call :heredoc vbs >email.vbs && goto endvbs
' Create email object
Set oolApp = CreateObject("Outlook.Application")
Set email = oolApp.CreateItem(0)
email.Recipients.Add("!recipient!")
' Create the body of the email
MailBody = "<^!DOCTYPE HTML PUBLIC ""-//W3C//DTD W3 HTML//EN"">"
MailBody = MailBody & "<HTML>" & vbcrlf
MailBody = MailBody & "<HEAD><TITLE>No Invoices</TITLE></HEAD>"
MailBody = MailBody & "<BODY>" & vbcrlf
MailBody = MailBody & "<B>For Your Information</B>,<BR><BR>"
MailBody = MailBody & "No invoices were issued today.<BR><BR>"
MailBody = MailBody & "</BODY></HTML>"
' Send the Email
email.Subject = "No Invoices Issued"
email.HTMLBody = MailBody
email.Send
:endvbs
cscript /nologo email.vbs
del email.vbs
goto :EOF
:: https://stackoverflow.com/a/15032476/1683264
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
set "line=%%A" && set "line=!line:*:=!"
if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
if "!line:~0,13!"=="call :heredoc" (
for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
if #%%i==#%1 (
for /f "tokens=2 delims=&" %%I in ("!line!") do (
for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
)
)
)
)
)
goto :EOF
:: *** JScript script *****/
var args = [];
for (var i=0; i<WScript.arguments.length; i++) { args.push(WScript.arguments(i)) }
var t = args.join(' ').replace(/^\s+|<[^>]+>|\s+$/g,'').replace(/\ /g, ' ').split(' ');
var h = t[4].split(':')[0];
if (/pm/i.test(t[5])) h = h * 1 + 12;
var ds = t[6] + ' ' + t[7] + ', ' + new Date().getFullYear() + ' ' + h + ':' + t[4].split(':')[1];
var diff = new Date() - new Date(ds);
WScript.echo(diff);
我没有对此进行测试,但请尝试一下,看看您的想法。