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

RRSS脚本VBS源程序

  1. on error resume next
  2. set instreem=wscript.stdin
  3. set outstreem=wscript.stdout
  4. if (lcase(right(wscript.fullname,11))="wscript.exe") then
  5.    set objShell=wscript.createObject("wscript.shell")
  6.    objShell.Run("cmd.exe /k cscript //nologo "&chr(34)&wscript.scriptfullname&chr(34))
  7.    wscript.quit
  8. end if
  9. if wscript.arguments.count<4 then
  10.    usage()
  11.    wscript.echo "Not enough parameters."
  12.    wscript.quit
  13. end if
  14. ipaddress=wscript.arguments(0)
  15. username=wscript.arguments(1)
  16. password=wscript.arguments(2)
  17. stroption=wscript.arguments(3)
  18. select case stroption
  19.    case "-r"
  20.       intflag=2
  21.       strshow="reboot"
  22.    case "-s"
  23.       intflag=1
  24.       strshow="shutdown"
  25.    case "-l"
  26.       intflag=0
  27.       strshow="logoff"
  28.    case "-p"
  29.       intflag=8
  30.       strshow="power off"
  31.    case "-fr"
  32.       intflag=6
  33.       strshow="force reboot"
  34.    case "-fs"
  35.       inrflag=5
  36.       strshow="force shutdown"
  37.    case "-fl"
  38.       intflag=4
  39.       strshow="force logoff"
  40.    case "-fp"
  41.       intflag=12
  42.       strshow="force power off"
  43.    case else
  44.       usage()
  45.       wscript.echo "Parameters error."
  46.       wscript.quit
  47. end select
  48. usage()
  49. outstreem.write "Conneting "&ipaddress&"...."
  50. set objlocator=createobject("wbemscripting.swbemlocator")
  51. set objswbemservices=objlocator.connectserver(ipaddress,"root/cimv2",username,password)
  52. showerror(err.number)
  53. outstreem.write "Applying for security privilege...."
  54. objswbemservices.security_.privileges.add 23,true
  55. objswbemservices.security_.privileges.add 18,true
  56. showerror(err.number)
  57. if intflag<>0 then
  58.    outstreem.write "Checking boot os...."
  59.    strwqlquery="select * from win32_computersystem"
  60.    set colinstances=objswbemservices.execquery(strwqlquery)
  61.    for each objinstance in colinstances
  62.       bootos1=objinstance.properties_.item("systemstartupoptions")
  63.    next
  64.    strwqlquery="select * from win32_operatingsystem"
  65.    set colinstances=objswbemservices.execquery(strwqlquery)
  66.    for each objinstance in colinstances
  67.       bootos2=objinstance.properties_.item("caption")
  68.    next
  69.    showerror(err.number)
  70.    if bootos1(0)<>chr(34)&bootos2&chr(34) then
  71.       wscript.echo "Current os is not default boot os!"
  72.       outstreem.write "Do you want to continue?(y/n):"
  73.       strinput=instreem.readline
  74.       if lcase(strinput)<>"y" then
  75.          wscript.echo "Canceled!"
  76.          wscript.quit
  77.       end if
  78.    end if
  79. end if
  80. outstreem.write "Now, "&strshow&"ing target...."
  81. strwqlquery="select * from win32_operatingsystem where primary='true'"
  82. set colinstances=objswbemservices.execquery(strwqlquery)
  83. for each objinstance in colinstances
  84.    objinstance.win32shutdown(intflag)
  85. next
  86. if err.number=0 then
  87.    wscript.echo "OK!"&vbcrlf&"Target has been "&strshow&" Successfully!"
  88. else
  89.    wscript.echo "Error!"
  90. end if
  91. function showerror(errornumber)
  92. if errornumber<>0 then
  93.    wscript.echo "Error!"
  94.    wscript.quit
  95. else
  96.    wscript.echo "OK!"
  97. end if
  98. end function
  99. function usage()
  100. wscript.echo string(79,"*")
  101. wscript.echo "RRSS v1.03"
  102. wscript.echo "Remote Reboot and Shutdown Script, by zzzEVAzzz"
  103. wscript.echo "Welcome to visite www.isgrey.com"
  104. wscript.echo "Usage:"
  105. wscript.echo "cscript "&wscript.scriptfullname&" targetIP username password -r|s|l|p"
  106. wscript.echo "-r : reboot target."
  107. wscript.echo "-s : shutdown target."
  108. wscript.echo "-l : logoff target current user."
  109. wscript.echo "-p : power off target."
  110. wscript.echo string(79,"*")&vbcrlf
  111. end function
复制代码

原来ARGUMENTS还可以这么用啊.感觉跟数组似的
  1. ipaddress=wscript.arguments(0)
  2. username=wscript.arguments(1)
  3. password=wscript.arguments(2)
  4. stroption=wscript.arguments(3)
复制代码
枫中残雪:风停了,我的心却在动,让我心中的寒意走向远方

TOP

返回列表