【问题标题】:what "@if (@CodeSection == @Batch) @then" stands for:“@if (@CodeSection == @Batch) @then” 代表什么:
【发布时间】:2018-01-28 11:45:10
【问题描述】:

嘿,我想知道批处理中的这个表达式代表什么,我试图绕过 uac,我需要将击键发送到 cmd 窗口,我看到一个帖子使用带有这个表达式的批处理代码,我不知道如果有人能解释我不胜感激,它的功能是什么!

代码来自:Press Keyboard keys using a batch file

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the other program in the same Window
start "" /B cmd

%SendKeys% "echo off{ENTER}"

set /P "=Wait and send a command: " < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "echo Hello, world!{ENTER}"

set /P "=Wait and send an Up Arrow key: [" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{UP}"

set /P "=] Wait and send an Enter key:" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"

%SendKeys% "exit{ENTER}"

goto :EOF


@end


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

【问题讨论】:

标签: batch-file


【解决方案1】:

它不是 - 它是 Jscript。

如果这个文件作为Jscript运行,那么由于if会失败,那么@then@end之间的部分将被执行,Jscript部分将被执行.

如果它作为批处理文件运行,那么由于(@CodeSection不等于@Batch),命令@then被执行,因此该行后面的命令将被执行,最终到达goto :eof,它跳过了文件的其余部分。

【讨论】:

  • 对于那些没有在评论中明确说明这是他们的意图的程序员来说,应该是一个特殊的地狱。我愿意打赌这种事情在浪费新手到中级程序员时间的事情清单上得分很高。当然,微软应该为这种废话负部分责任。 *nix 系统很久以前就对这类事情进行了标准化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 1970-01-01
  • 2016-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多