Board logo

标题: [其他] 请教这句代码是什么意思 [打印本页]

作者: 大地    时间: 2019-2-24 12:56     标题: 请教这句代码是什么意思

请教这句代码是什么意思,没看懂,大神帮我分析一下,多谢.

%1 mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&&exit /b
作者: ivor    时间: 2019-2-24 14:01

  1. if "%1" neq "once" PowerShell -Command "& {start-process  %0 -Verb RunAs -Args once}" & exit
  2. pause
复制代码
同样功能的powershell
作者: 大地    时间: 2019-2-24 15:23

回复 2# ivor


    大师 能否讲得详细点  语句到底执行什么,,我只知道退了,(我是菜鸟)
作者: Batcher    时间: 2019-2-25 11:00

  1. @echo off
  2. %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("""%~f0""","::",,"runas",1)(close)&exit /b
  3. net session
  4. pause
复制代码
以上面这个test.bat为例:
代码执行到第2行的时候,%1默认为空,实际执行的就是mshta命令
ShellExecute以管理员权限再次调用"%~f0"也就是test.bat本身,并传递位置参数"::"
然后退出test.bat的第一次执行,也就是说第2行下面的代码都不会被执行

被ShellExecute调用的test.bat再次执行到第2行的时候,1%的值是::,也就是一个注释符号,所以后面的mshta命令不再执行
从第3行开始往下继续执行的命令都获得了管理员权限。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2