So, im pretty new to this here, but heres the issue I cannot seem to get past. writing a section of code in batch to launch a program, and simulate a single keypress. here is that code block in question
@echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
ping -n 5 -w 1 127.0.0.1
start .\cc6.exe
%SendKeys% "{ENTER}"
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
code returns "Conditional Compilation is off" error. Searching for a solution tells me that adding
/*@cc_on @*/
to the code should resolve the sitation and turn conditional compilation on. however adding that segment in results in " '/*@cc_on'is not recognized as an internal or external command, operable program or batch file." error.
You need to use the conditional compilation via @if command this way:
@if (@CodeSection == @Batch) @then
@echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
ping -n 5 -w 1 127.0.0.1
start .\cc6.exe
%SendKeys% "{ENTER}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
The @if command ignore the following code until the next @end; the (@CodeSection == @Batch) part is just an expression that have false value in JScript but that is valid in Batch, and the @then part may be any word that just complete the syntax for Batch part. You must also include a goto :EOF command before the JScript section, otherwise it would be executed as Batch code.
Most programming languages use if to indicate conditions, or conditional expressions and statements.
To turn on conditional compilation for JScript, you'd also need an if statement.
Conventionally, you'd separate the batch code from JScript via commenting.
JScript was introduced in 1996 and supported only by IE 3.0 for client side scripting, and has syntax similar to Javascript, "Microsoft's dialect of the ECMAScript".
@cc_on activates conditional compilation in IE 10 and earlier versions within script comments, meaning the codes within comments are to be treated as codes & executed, and not treated as comments. Of course it'll only be executed by browsers/applications that know about it, otherwise it'll be ignored or treated as comment. (Kind of like 'I didn't know' excuse most offenders give for breaking the law, or the different behaviour in people who see beyond what can be observed by the known senses)
IE 11+ & Windows store apps don't support conditional compilation.
The code you're running is in a batch file, and not in Internal Explorer to execute client side scripting, so you won't need @cc_on in your code.
Try the below format in your batch file:
@if (@a==@a) @end /*
cscript //E:JScript //nologo "%~f0" %*
REM --- Insert other batch codes here ---
exit /b
*/
// --- JScript codes below this line ----
// --- insert more scripts ---
WScript.Echo(" Code activated, blah!");
WScript.Quit(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With