Batch file 批处理一个脚本而不是另一个脚本时出现条件编译错误

Batch file 批处理一个脚本而不是另一个脚本时出现条件编译错误,batch-file,jscript,Batch File,Jscript,语言:批处理+一点JScript 主要思想:JScript为一个程序工作,而不是为另一个程序工作 错误消息:Microsoft JScript编译错误:条件编译已关闭 我的问题是,我试图从我的pastebin中获取一些信息到批处理变量中。我想我的代码来检查和执行该网站的代码。我已经让代码独立工作,但是当我将其添加到主程序时,我得到了一个MicrosoftJScript编译错误:条件编译被关闭了error。如果我自己运行同一个脚本,它工作得很好,但是当我将它添加到主脚本时,它会中断 我很确定我添加

语言:批处理+一点JScript

主要思想:JScript为一个程序工作,而不是为另一个程序工作

错误消息:Microsoft JScript编译错误:条件编译已关闭

我的问题是,我试图从我的pastebin中获取一些信息到批处理变量中。我想我的代码来检查和执行该网站的代码。我已经让代码独立工作,但是当我将其添加到主程序时,我得到了一个
MicrosoftJScript编译错误:条件编译被关闭了
error。如果我自己运行同一个脚本,它工作得很好,但是当我将它添加到主脚本时,它会中断

我很确定我添加的彩色文本脚本会破坏它,但我不是100%确定。那么,基本上,为什么网站数据代码本身可以工作,而不能与其他任何东西一起工作呢

我怎样才能解决这个问题

[非工作部件]菜单+彩色文本+网站信息

@echo关闭
颜色0a
setlocal
调用:initColorPrint
电话:title
rem——菜单上的东西----
:菜单
电话:title
回声。
回显(键入“版本”以查看错误)
回声。
调用:colorPrint 09“%time%”
电话:colorPrint 06“@”
调用:彩色打印0c“%username%”
设置/p调用=^>
如果“%call%”==“version”转到:version
%呼叫%
转到菜单
:标题
title CMD^|用户:%username%
退出/b
雷姆——这部分不起作用----
:版本
@如果(@a==b)@end/*
@回音
setlocal
电话:东西
超时1
回声。
回显%code%
设置“代码=%code%”
超时3
出口
:东西
对于/f“delims=“%%I in('cscript/nologo/e:jscript“%~f0”https://pastebin.com/raw/wAtBQEeZ“')做什么(
设置“代码=%%I”
回声(%%I
)
退出/b
JScript*/
var x=新的ActiveXObject(“Microsoft.XMLHTTP”);
x、 open(“GET”,WSH.Arguments(0),true);
x、 setRequestHeader('User-Agent','XMLHTTP/1.0');
x、 发送(“”);
而(x.readyState!=4){WSH.Sleep(50)};
WSH.Echo(x.responseText);
rem——色彩材料-----
:彩色打印颜色Str[/n]
setlocal
设置“str=%~2”
调用:colorPrintVar%1 str%3
退出/b
:colorPrintVar Color StrVar[/n]
如果未定义%2退出/b
setlocal enableDelayedExpansion
设置“str=a%DEL%!%2:\=a%DEL%\..\%DEL%%DEL%%DEL%!”
设置“str=!str:/=a%DEL%/..\%DEL%%DEL%%DEL%!”
设置“str=!str:=\!”
pushd“%temp%”
findstr/p/A:%1“!str!\..\x”nul
如果/i“%~3”==“/n”回显(
退出/b
:initColorPrint
对于/F“tokens=1,2 delims=#”%%a in(“'prompt#$H#$E#和echo on&for%%b in(1)do rem””)do set“DEL=%a”
%temp%\x“set/p”=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%。%DEL%
退出/b
:清除彩色打印
删除“%temp%\x”
退出/b
图片:

[工作]网站信息代码

@if(@a==@b)@end/*
@回音
setlocal
电话:东西
超时1
回声。
回显%code%
设置“代码=%code%”
超时3
出口
:东西
对于/f“delims=“%%I in('cscript/nologo/e:jscript“%~f0”https://pastebin.com/raw/wAtBQEeZ“')做什么(
设置“代码=%%I”
回声(%%I
)
退出/b
JScript*/
var x=新的ActiveXObject(“Microsoft.XMLHTTP”);
x、 open(“GET”,WSH.Arguments(0),true);
x、 setRequestHeader('User-Agent','XMLHTTP/1.0');
x、 发送(“”);
而(x.readyState!=4){WSH.Sleep(50)};
WSH.Echo(x.responseText);
工作画面:


您正在尝试编写一个混合脚本,该脚本是部分cmd.exe批处理和部分JScript(通过CSCRIPT执行)

您必须确保批处理从不尝试执行JScript代码,相反,JScript也决不能尝试执行批处理代码

通过EXIT/B(和/或可能使用:labels进行GOTO/CALL)可以很容易地防止批处理看到JScript,但是CSCRIPT引擎总是试图将整个脚本解析为JScript

一个成功的混合脚本的诀窍是在一开始就有一行是有效的批处理和JScript。第一行在批处理中不应该做任何事情,而在JScript中,除了开始一个JScript多行注释外,它什么也不做。所有批处理代码如下,然后以EXIT/B结束。然后有一行关闭JScript多行注释,然后是JScript代码

看起来您试图将一个工作的混合脚本粘贴到另一个脚本中,但不了解它的工作原理。您只需重新构造代码,以确保所有批处理代码都对JScript隐藏(作为注释的一部分)

@if(@a==@b)@end/*这是一个无害的混合批处理/JScript行,它以JScript注释开头。
@rem==========================批处理代码==========================
@回音
颜色0a
setlocal
调用:initColorPrint
电话:title
rem——菜单上的东西----
:菜单
电话:title
回声。
回显(键入“版本”以查看错误)
回声。
调用:colorPrint 09“%time%”
电话:colorPrint 06“@”
调用:彩色打印0c“%username%”
设置/p调用=^>
如果“%call%”==“version”转到:version
%呼叫%
转到菜单
:标题
title CMD^|用户:%username%
退出/b
:版本
@回音
setlocal
电话:东西
超时1
回声。
回显%code%
设置“代码=%code%”
超时3
出口
:东西
对于/f“delims=“%%I in('cscript/nologo/e:jscript“%~f0”https://pastebin.com/raw/wAtBQEeZ“')做什么(
设置“代码=%%I”
回声(%%I
)
退出/b
rem——色彩材料-----
:彩色打印颜色Str[/n]
setlocal
设置“str=%~2”
调用:colorPrintVar%1 str%3
退出/b
:colorPrintVar Color StrVar[/n]
如果未定义%2退出/b
setlocal enableDelayedExpansion
设置“str=a%DEL%!%2:\=a%DEL%\..\%DEL%%DEL%%DEL%!”
设置“str=!str:/=a%DEL%/..\%DEL%%DEL%%DEL%!”
设置“str=!str:=\!”
pushd“%temp%”
findstr/p/A:%1“!str!\..\x”nul
如果/i“%~3”==“/n”回显(
退出/b
:initColorPrint
对于/F“tokens=1,2 delims=#”%%a in(“'prompt#$H#$E#和echo on&for%%b in(1)do rem””)do set“DEL=%a”
%temp%\x“set/p”=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%。%DEL%
退出/b
:清除彩色打印
删除“%temp%\x”
退出/b
=================================================================================================================================*/
var x=新的ActiveXObject(“Microsoft.XMLHTTP”);
x、 open(“GET”,WSH.Arguments(0),true);
x、 setRequestHeader('User-Agent','XMLHTTP/1.0');
x、 发送(“”);
而(x.rea
@if (@a==@b) @end /* This is a harmless hybrid batch/JScript line that begins a JScript comment.

@rem ================== Batch code ==========================
@echo off
color 0a
setlocal
call :initColorPrint
call :title

rem ---- Menu Stuff ----

:menu
call :title
echo.
echo (Type 'version' to see error)
echo.
call :colorPrint 09 "%time%"
call :colorPrint 06 "@"
call :colorPrint 0c "%username%"
set /p call=^>
if "%call%" =="version" goto :version
%call%
goto menu

:title
title CMD ^| User: %username%
exit /b

:version
@echo off
setlocal
call :stuff
timeout 1 
echo.
echo %code%
set "code=%code%"
timeout 3
exit

:stuff
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "https://pastebin.com/raw/wAtBQEeZ"') do (
set "code=%%I"
echo(%%I
)
exit /b

rem ----- Color Stuff -----

:colorPrint Color  Str  [/n]
setlocal
set "str=%~2"
call :colorPrintVar %1 str %3
exit /b

:colorPrintVar  Color  StrVar  [/n]
if not defined %~2 exit /b
setlocal enableDelayedExpansion
set "str=a%DEL%!%~2:\=a%DEL%\..\%DEL%%DEL%%DEL%!"
set "str=!str:/=a%DEL%/..\%DEL%%DEL%%DEL%!"
set "str=!str:"=\"!"
pushd "%temp%"
findstr /p /A:%1 "." "!str!\..\x" nul
if /i "%~3"=="/n" echo(
exit /b

:initColorPrint
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
<nul >"%temp%\x" set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%.%DEL%"
exit /b

:cleanupColorPrint
del "%temp%\x"
exit /b

====================== JScript Code ======================== */
var x=new ActiveXObject("Microsoft.XMLHTTP");
x.open("GET",WSH.Arguments(0),true);
x.setRequestHeader('User-Agent','XMLHTTP/1.0');
x.send('');
while (x.readyState!=4) {WSH.Sleep(50)};
WSH.Echo(x.responseText);