[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 批处理以管理员权限运行自身

本帖最后由 919141923 于 2013-11-9 22:12 编辑

有些批处理要以管理员权限运行,把这段代码放在批处理开头,那么批处理将会以管理员权限运行(在nt6系统),而不用右键菜单。当然,那段vbs是在网上找的,有改动。
  1. @if not exist "%~1" (
  2. for /f "delims=[] tokens=2" %%i in ('ver') do @(
  3. for /f "tokens=2 delims=. " %%1 in ("%%i") do @(
  4. if /i "%%1"=="6" (
  5. title 正在试图以管理员权限运行本程序,请稍候...
  6. echo 如果弹出了用户账户控制的窗口,请点击 "是"
  7. (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"
  8. echo Function ChrData^(Data^)
  9. echo MyArray = Split^(Data, ",", -1, 1^)
  10. echo For each OldData in MyArray
  11. echo Newdata=NewData^&chr^(OldData^)
  12. echo Next
  13. echo ChrData=NewData
  14. echo End Function
  15. echo execute Chrdata^(data^))>"%tmp%\admin.vbs"
  16. call cscript /nologo "%tmp%\admin.vbs" cmd /c ""%~f0" "%~dp0" %*"
  17. del /f /q "%tmp%\admin.vbs"
  18. goto :eof
  19. ))))
  20. @if exist "%~1" (
  21. cd /d %1
  22. shift
  23. )
复制代码

本帖最后由 apang 于 2013-11-9 21:52 编辑

那么麻烦呀?还有高丽文哦?
  1. @echo off
  2. %1 %2
  3. ver|find "6.">nul&&mshta vbscript:createobject("shell.application").shellexecute("""%~0""","goto :st",,"runas",1)(window.close)&&exit /b
  4. :st
  5. echo,%cd%
  6. pause
复制代码
2

评分人数

TOP

本帖最后由 919141923 于 2014-2-15 15:36 编辑

算了,编辑掉

TOP

Mark一下,这个很厉害啊

TOP

学习了,谢谢分享

TOP

那么麻烦呀?还有高丽文哦?
apang 发表于 2013-11-9 21:37



    可不可以加一段代码把windows的用户账户控制的选择都省了?就是选择“是”“否”
初九的冬天

TOP

這代碼還真厲害,立馬試試

TOP

回复 2# apang


  第二行的 1%,2% 什么意思? 两个参数?

TOP

回复 8# cfwyy77_bat

没发现有1%、2%,你自己造的变量吧。

TOP

回复 9# happy886rr


    第3行会调用自身,传入%1和%2的值。
测试代码之前请做好备份

TOP

本帖最后由 cfwyy77_bat 于 2017-6-9 15:08 编辑

回复 9# happy886rr


我问的是2楼的代码,看了10楼说的,我才基本明白了, vb执行自身的时候 “goto :st” 作为两个参数传入了,就跳过了第三行去执行需要的代码。

原谅我挖了个老贴,把9,10楼两个大神都引出来了

TOP

返回列表