全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1625|回复: 9
打印 上一主题 下一主题

找asp猛男

[复制链接]
跳转到指定楼层
1#
发表于 2012-10-24 14:52:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
50金钱
嗯,话说某vbs脚本如下:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization")
Set vmcollecion = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)
Wscript.Echo VbCrLF
Wscript.Echo "Name                                    Description                        State "
Wscript.Echo "--------------------------------------- ---------------------------------- -------------"
' loop through all instances in collection
For each vm in vmcollecion
' decode system state, based on codes identified via trial and error
VMStateCode = vm.EnabledState
Select Case VMStateCode
         Case 2 VMState = "Running"
          Case 3      VMState = "PowerOff"
          Case 4      VMState = "ShuttingDown"
         Case 10    VMState = "Reset"
         Case 32768 VMState = "Paused"
         Case 32770 VMState = "Starting"
  Case 32771 VMState = "SnapshotInProgress"
         Case 32772 VMState = "Migrating"
         Case 32773 VMState = "Saving"
         Case 32774 VMState = "Stopping"
         Case 32776 VMState = "Pausing"
         Case 32777 VMState = "Resuming"
         Case 32769 VMState = "Saved"
  Case  Else  VMState = "Unclassified (so far)"
End Select
' print out VM info state
Wscript.Echo VbCrLF
Wscript.Echo  vm.ElementName & Space(40 - Len(vm.ElementName)) & _
    vm.Description & Space(35 - Len(vm.Description)) & _
   VMState & " (" & VMStateCode & ")"
' request state change if appropriate - the host should never be eligible
if ( VMState = "Running" or VMState = "Paused") and vm.Description <> "Microsoft Hosting Computer System" Then
  Wscript.Echo Space(40) & "Saving " & vm.ElementName
  RequestReturn = vm.RequestStateChange(32769)
  if RequestReturn = 4096 Then
   Wscript.Echo Space(40) & "Save request submitted"
  Else
   Wscript.Echo Space(40) & "Something goofy happened (" & RequestReturn & ")"
  End If
End If
Next
Wscript.Echo VbCrLF

找猛男做成asp的

2#
发表于 2012-10-24 14:57:13 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
3#
发表于 2012-10-24 14:58:26 | 只看该作者
Ho..目测这代码有点邪恶

评分

参与人数 1威望 +2 收起 理由
xuyanjian + 2 是很邪恶啊

查看全部评分

4#
发表于 2012-10-24 15:02:25 | 只看该作者
asp是什么
5#
发表于 2012-10-24 15:03:17 | 只看该作者
把Wscript.Echo换成response.write
然后for循环里好像得改下

评分

参与人数 1威望 +15 收起 理由
xuyanjian + 15 先给15.

查看全部评分

6#
发表于 2012-10-24 15:05:42 来自手机 | 只看该作者
为什么不做成php?微软都放弃asp了。。。
7#
 楼主| 发表于 2012-10-24 15:47:13 | 只看该作者
老刘 发表于 2012-10-24 15:05
为什么不做成php?微软都放弃asp了。。。

懒得再去装php
.net执行速度太慢了
8#
发表于 2012-10-24 16:04:11 | 只看该作者
php.
9#
发表于 2012-10-24 16:06:08 | 只看该作者
美女要不?
10#
发表于 2012-10-24 17:17:31 | 只看该作者
本帖最后由 哈哈大侠 于 2012-10-24 17:32 编辑

asp和vbs本来是一样的东西,但是有些对象要换一下,设置了下ContentType应该可以保持输出格式,语法什么喵了一下好像没什么问题,for那应该是这样的(循环数组)。GetObject在asp里没有要改下。调试无果,说字符无效,百度查了下发现是asp没有权限玩wmi,百度没找到调用wmi成功的例子,可以结贴了 给分吧,权限不够可是没办法的
  1. <%
  2.     Response.ContentType = "text/plain"
  3.     strComputer = "."
  4.         ' Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\virtualization")
  5.         Set objWMIService = Server.CreateObject("winmgmts:\" & strComputer & "\root\virtualization")
  6.     Set vmcollecion = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)
  7.     Response.Write VbCrLF
  8.     Response.Write "Name                                    Description                        State "
  9.     Response.Write "--------------------------------------- ---------------------------------- -------------"
  10.     ' loop through all instances in collection
  11.     For each vm in vmcollecion
  12.     ' decode system state, based on codes identified via trial and error
  13.     VMStateCode = vm.EnabledState
  14.     Select Case VMStateCode
  15.              Case 2 VMState = "Running"
  16.               Case 3      VMState = "PowerOff"
  17.               Case 4      VMState = "ShuttingDown"
  18.              Case 10    VMState = "Reset"
  19.              Case 32768 VMState = "Paused"
  20.              Case 32770 VMState = "Starting"
  21.       Case 32771 VMState = "SnapshotInProgress"
  22.              Case 32772 VMState = "Migrating"
  23.              Case 32773 VMState = "Saving"
  24.              Case 32774 VMState = "Stopping"
  25.              Case 32776 VMState = "Pausing"
  26.              Case 32777 VMState = "Resuming"
  27.              Case 32769 VMState = "Saved"
  28.       Case  Else  VMState = "Unclassified (so far)"
  29.     End Select
  30.     ' print out VM info state
  31.     Response.Write VbCrLF
  32.     Response.Write  vm.ElementName & Space(40 - Len(vm.ElementName)) & _
  33.         vm.Description & Space(35 - Len(vm.Description)) & _
  34.        VMState & " (" & VMStateCode & ")"
  35.     ' request state change if appropriate - the host should never be eligible
  36.     if ( VMState = "Running" or VMState = "Paused") and vm.Description <> "Microsoft Hosting Computer System" Then
  37.       Response.Write Space(40) & "Saving " & vm.ElementName
  38.       RequestReturn = vm.RequestStateChange(32769)
  39.       if RequestReturn = 4096 Then
  40.        Response.Write Space(40) & "Save request submitted"
  41.       Else
  42.        Response.Write Space(40) & "Something goofy happened (" & RequestReturn & ")"
  43.       End If
  44.     End If
  45.     Next
  46.     Response.Write VbCrLF
  47.     %>
复制代码

评分

参与人数 1威望 +15 收起 理由
xuyanjian + 15 给了15分再说

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-6-11 01:57 , Processed in 0.071261 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表