标题: [其他] 批处理以管理员权限运行自身 [打印本页]
作者: 919141923 时间: 2013-11-9 16:58 标题: 批处理以管理员权限运行自身
本帖最后由 919141923 于 2013-11-9 22:12 编辑
有些批处理要以管理员权限运行,把这段代码放在批处理开头,那么批处理将会以管理员权限运行(在nt6系统),而不用右键菜单。当然,那段vbs是在网上找的,有改动。- @if not exist "%~1" (
- for /f "delims=[] tokens=2" %%i in ('ver') do @(
- for /f "tokens=2 delims=. " %%1 in ("%%i") do @(
- if /i "%%1"=="6" (
- title 正在试图以管理员权限运行本程序,请稍候...
- echo 如果弹出了用户账户控制的窗口,请点击 "是"
- (echo data="83,101,116,32,111,98,106,87,77,73,83,101,114,118,105,99,101,115,32,61,32,71,101,116,79,98,106,101,99,116,40,34,119,105,110,109,103,109,116,115,58,123,105,109,112,101,114,115,111,110,97,116,105,111,110,76,101,118,101,108,61,105,109,112,101,114,115,111,110,97,116,101,125,33,92,92,46,92,114,111,111,116,92,99,105,109,118,50,34,41,32,13,10,83,101,116,32,111,98,106,87,98,101,109,79,98,106,101,99,116,83,101,116,32,61,32,111,98,106,87,77,73,83,101,114,118,105,99,101,115,46,69,120,101,99,81,117,101,114,121,40,95,32,13,10,34,83,69,76,69,67,84,32,42,32,70,82,79,77,32,87,105,110,51,50,95,80,114,111,99,101,115,115,32,87,72,69,82,69,32,34,32,38,95,32,13,10,34,69,120,101,99,117,116,97,98,108,101,80,97,116,104,61,39,34,32,38,32,82,101,112,108,97,99,101,40,87,83,99,114,105,112,116,46,70,117,108,108,78,97,109,101,44,34,92,34,44,34,92,92,34,41,32,38,32,34,39,32,97,110,100,32,34,32,38,32,95,32,13,10,34,67,111,109,109,97,110,100,76,105,110,101,32,76,73,75,69,32,39,37,34,32,38,32,87,83,99,114,105,112,116,46,83,99,114,105,112,116,78,97,109,101,32,38,32,34,37,39,34,41,32,13,10,102,111,114,32,101,97,99,104,32,111,98,106,87,98,101,109,79,98,106,101,99,116,32,105,110,32,111,98,106,87,98,101,109,79,98,106,101,99,116,83,101,116,32,13,10,99,109,100,108,105,110,101,32,61,32,111,98,106,87,98,101,109,79,98,106,101,99,116,46,67,111,109,109,97,110,100,76,105,110,101,32,13,10,110,101,120,116,32,13,10,105,102,32,87,83,99,114,105,112,116,46,65,114,103,117,109,101,110,116,115,46,67,111,117,110,116,32,116,104,101,110,32,13,10,102,105,108,101,32,61,32,87,83,99,114,105,112,116,46,65,114,103,117,109,101,110,116,115,40,48,41,32,13,10,105,102,32,102,105,108,101,61,34,47,63,34,32,116,104,101,110,32,13,10,99,97,108,108,32,83,104,111,119,72,101,108,112,40,41,32,13,10,87,83,99,114,105,112,116,46,81,117,105,116,32,13,10,101,110,100,32,105,102,32,13,10,83,101,116,32,82,101,103,69,120,32,61,32,110,101,119,32,82,101,103,69,120,112,32,13,10,82,101,103,69,120,46,73,103,110,111,114,101,67,97,115,101,32,61,32,116,114,117,101,32,13,10,82,101,103,69,120,46,71,108,111,98,97,108,32,61,32,116,114,117,101,32,13,10,82,101,103,69,120,46,80,97,116,116,101,114,110,32,61,32,34,92,92,124,92,47,124,92,124,124,92,40,124,92,41,124,92,91,124,92,93,124,92,123,124,92,125,124,92,94,124,92,36,124,92,46,124,92,42,124,92,63,124,92,43,34,32,13,10,116,101,109,112,49,32,61,32,82,101,103,69,120,46,82,101,112,108,97,99,101,40,87,83,99,114,105,112,116,46,83,99,114,105,112,116,78,97,109,101,44,32,34,92,36,38,34,41,32,13,10,116,101,109,112,50,32,61,32,82,101,103,69,120,46,82,101,112,108,97,99,101,40,102,105,108,101,44,32,34,92,36,38,34,41,32,13,10,82,101,103,69,120,46,71,108,111,98,97,108,32,61,32,102,97,108,115,101,32,13,10,82,101,103,69,120,46,80,97,116,116,101,114,110,32,61,32,34,94,46,42,63,34,32,38,32,116,101,109,112,49,32,38,32,34,91,34,34,92,115,93,42,34,32,38,32,116,101,109,112,50,32,38,32,34,34,34,63,92,115,42,34,32,13,10,97,114,103,115,32,61,32,82,101,103,69,120,46,82,101,112,108,97,99,101,40,99,109,100,108,105,110,101,44,32,34,34,41,32,13,10,39,87,83,99,114,105,112,116,46,69,99,104,111,32,102,105,108,101,44,32,97,114,103,115,32,13,10,101,108,115,101,32,13,10,102,105,108,101,32,61,32,34,99,109,100,46,101,120,101,34,32,13,10,39,97,114,103,115,32,61,32,34,47,107,32,99,100,32,47,100,32,34,34,34,32,38,32,67,114,101,97,116,101,79,98,106,101,99,116,40,34,87,83,99,114,105,112,116,46,83,104,101,108,108,34,41,46,67,117,114,114,101,110,116,68,105,114,101,99,116,111,114,121,32,38,32,67,104,114,40,51,52,41,32,13,10,101,110,100,32,105,102,32,13,10,39,-17717,-12092,-19206,-15637,32,13,10,83,101,116,32,115,104,32,61,32,67,114,101,97,116,101,79,98,106,101,99,116,40,34,83,104,101,108,108,46,65,112,112,108,105,99,97,116,105,111,110,34,41,32,13,10,99,97,108,108,32,115,104,46,83,104,101,108,108,69,120,101,99,117,116,101,40,32,102,105,108,101,44,32,97,114,103,115,44,32,44,32,34,114,117,110,97,115,34,32,41,32,13,10,102,117,110,99,116,105,111,110,32,83,104,111,119,72,101,108,112,40,41,32,13,10,100,105,109,32,72,101,108,112,83,116,114,32,13,10,72,101,108,112,83,116,114,32,61,32,34,-11564,-17956,-16147,-11087,-13843,-18467,-11061,-12080,-19508,-12046,-24157,34,32,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,87,83,99,114,105,112,116,46,83,99,114,105,112,116,78,97,109,101,32,38,32,34,32,91,112,114,111,103,114,97,109,93,32,91,112,97,114,97,109,101,116,101,114,115,93,46,46,46,34,32,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,34,112,114,111,103,114,97,109,32,-11606,-11061,-12080,-19004,-19508,-12046,34,32,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,34,112,97,114,97,109,101,116,101,114,115,32,-19285,-18979,-18184,32,112,114,111,103,114,97,109,32,-19004,-19762,-13571,34,32,38,32,118,98,67,114,76,102,32,95,32,13,10,38,32,118,98,67,114,76,102,32,13,10,87,83,99,114,105,112,116,46,69,99,104,111,32,72,101,108,112,83,116,114,32,13,10,101,110,100,32,102,117,110,99,116,105,111,110,32,13,10,13,10"
- echo Function ChrData^(Data^)
- echo MyArray = Split^(Data, ",", -1, 1^)
- echo For each OldData in MyArray
- echo Newdata=NewData^&chr^(OldData^)
- echo Next
- echo ChrData=NewData
- echo End Function
- echo execute Chrdata^(data^))>"%tmp%\admin.vbs"
- call cscript /nologo "%tmp%\admin.vbs" cmd /c ""%~f0" "%~dp0" %*"
- del /f /q "%tmp%\admin.vbs"
- goto :eof
- ))))
- @if exist "%~1" (
- cd /d %1
- shift
- )
复制代码
作者: apang 时间: 2013-11-9 21:37
本帖最后由 apang 于 2013-11-9 21:52 编辑
那么麻烦呀?还有高丽文哦?- @echo off
- %1 %2
- ver|find "6.">nul&&mshta vbscript:createobject("shell.application").shellexecute("""%~0""","goto :st",,"runas",1)(window.close)&&exit /b
-
- :st
- echo,%cd%
- pause
复制代码
作者: 919141923 时间: 2013-11-9 22:16
本帖最后由 919141923 于 2014-2-15 15:36 编辑
算了,编辑掉
作者: linlianboy 时间: 2013-11-9 22:32
Mark一下,这个很厉害啊
作者: xybzm 时间: 2013-11-10 20:14
学习了,谢谢分享
作者: 1270697389 时间: 2013-12-17 18:26
那么麻烦呀?还有高丽文哦?
apang 发表于 2013-11-9 21:37
可不可以加一段代码把windows的用户账户控制的选择都省了?就是选择“是”“否”
作者: 飛雪 时间: 2014-2-1 23:19
這代碼還真厲害,立馬試試
作者: cfwyy77_bat 时间: 2017-6-9 09:55
回复 2# apang
第二行的 1%,2% 什么意思? 两个参数?
作者: happy886rr 时间: 2017-6-9 11:18
回复 8# cfwyy77_bat
没发现有1%、2%,你自己造的变量吧。
作者: ShowCode 时间: 2017-6-9 14:04
回复 9# happy886rr
第3行会调用自身,传入%1和%2的值。
作者: cfwyy77_bat 时间: 2017-6-9 15:06
本帖最后由 cfwyy77_bat 于 2017-6-9 15:08 编辑
回复 9# happy886rr
我问的是2楼的代码,看了10楼说的,我才基本明白了, vb执行自身的时候 “goto :st” 作为两个参数传入了,就跳过了第三行去执行需要的代码。
原谅我挖了个老贴,把9,10楼两个大神都引出来了
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |