MCSE技术论坛

首页 » 开发者俱乐部 » windows脚本 » 求助:(WMI)从800A03EE错误到800A0401错误
alonenetwork - 2008-1-8 15:21:00
Option Explicit

Dim objSpooler
Dim objEventSource
Dim strWQLQuery
Dim objNextEvent
Dim strComputer = "."
Dim objWMIService

strWQLQuery = "SELECT * FROM _InstanceModificationEvent WITHIN 5" & _
      "WHERE TargetInstance ISA 'Win32_Service' AND " & _
      "TargetInstance.Name= 'Spooler' AND targetInstance.State = 'Stopped'"

Set objWMIService = GetObject("winmgmts:" _
                                  & "{impersonationLevel = impersonate}!\\" & _
                                  strComputer & "\root\cimv2")
Set objSpooler=objWMIService.Get("Win32_Service ="'Spooler'"")

If  objSpooler.State = "Running"  Then
          Set objEventSource = GetObject("winmgmts:{impersonationLevel = impersonate}"). _
                                            ExecNotificationQuery(strWQLQuery)
          WScript.Echo  "Waiting for the Event ..."
          Set objNextEvent = objEventSource.NextEvent
          WScript.Echo  "The Event took place"
          WScript.Echo  objNextEvent.TargetInstance.DisplayName & " is " & _
                                  objNextEvent.TargetInstance.State
          WScript.Echo  "Synchronous Processing Continues"
          WScript.Echo  "If ..." & vbCrLf & _
                                  "then you are using asynchronous processing"
WScript.Echo "If ..." & vbCrLf & _
      "then you are using asynchronous processing"
Else
WScript.Echo "The Spooler Service is not running"
End If

MsgBox "Click on OK to Finish"


上面是我的代码,得出800A0401错误,如果按照书上的写法出现800A03EE错误。
附上书中源码:
Option Explicit

Dim objSpooler
Dim objEventSource
Dim strWQLQuery
Dim objNextEvent

strWQLQuery = "SELECT * FROM _InstanceModificationEvent WITHIN 5" & _
                          "WHERE TargetInstance ISA 'Win32_Service' AND " & _
                          "TargetInstance.Name= 'Spooler' AND targetInstance.State = 'Stopped'"

Set objSpooler = GetObject("winmgmts:{impersonationLevel = impersonate}!" & _
                          "Win32_Service ="'Spooler'"")

If objSpooler.State = "Running" Then
              Set objEventSource = GetObject("winmgmts:{impersonationLevel = impersonate}"). _
                                                ExecNotificationQuery(strWQLQuery)
              WScript.Echo  "Waiting for the Event ..."
            Set objNextEvent = objEventSource.NextEvent
            WScript.Echo " The Event took place"
            WScript.Echo    objNextEvent.TargetInstance.DisplayName & " is " & _
                                      objNextEvent.TargetInstance.State
            WScript.Echo    "Synchronous Processing Continues"
            WScript.Echo    "If ..." & vbCrLf & _
                                      "then you are using asynchronous processing"
            WScript.Echo    "If ..." & vbCrLf & _
                                    "then you are using asynchronous processing"
Else
                                      WScript.Echo "The Spooler Service is not running"
End If

MsgBox "Click on OK to Finish"

另我查找了一份代码,没想到可以执行,结果是否正确我没看,警告没跳出来。附上源码:
Const HIDDEN_WINDOW = 12
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("Notepad.exe", null, objConfig, intProcessID)


有哪位高手给我看看,感谢。如果有可能请发信息。
邮箱:seechina@hotmail.com    hbmr00@sina.com
QQ:297496445

电脑环境:
OS 名称 Microsoft Windows 2000 Professional
版本 5.0.2195 Service Pack 4 内部版本号 2195
没有安装WMI SDK
另有windows 2000 server family系统,同样没有通过。
Steven - 2008-1-8 19:28:00
你只说了错误代码是不够的,你运行了vbs之后他会跳出一个错误对话框,告诉你第几行第几个字出错了,把那个copy了然后发上来。

还有更重要的是...你根本没告诉我你这个脚本是做什么用的,目的是什么,一上来就给我一堆代码让我怎么帮你啊。你说清楚一些详细信息,我也许可以帮你写一个没那么复杂的.
alonenetwork - 2008-1-9 8:49:00
嗯,谢谢。
此脚本用于在本地机器上监控一个Spooler服务,在《WMI技术指南》一书的第四章的4.6.2节。并不是为了做某一个特定的项目处理,只是按照书上代码进行运行测试,以更加容易理解"同步和异步事件处理"的一些细节。

给出错误代码的详细细节:
800A03EE
脚本: E:\Documents and Settings\Administrator\桌面\e.vbs
行:  7
字符: 111
错误: 缺少')'
代码: 800A03EE
源:  Microsoft VBScript编译器错误
这个是第二个代码的错误信息,下面给出第一个800A0410的错误信息。
800A0410
脚本: E:\Documents and Settings\Administrator\桌面\e.vbs
行:  7
字符: 17
错误: 语句未结束
代码: 800A0410
源:  Microsoft VBScript编译器错误
此为windows 2000 server family环境下编译错误信息
Steven - 2008-1-11 19:20:00
改好了,你自己试一下。

Option Explicit

On Error Resume Next
Dim strComputer
Dim objWMIService
Dim propValue
Dim objItem
Dim SWBemlocator
Dim UserName
Dim Password

strComputer = "."
UserName = ""
Password = ""
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set objItems = objWMIService.ExecQuery("Select * from Win32_Service where caption = 'print Spooler'",,48)

strWQLQuery = "SELECT * FROM  _InstanceModificationEvent WITHIN 5" & _
                          "WHERE TargetInstance ISA 'Win32_Service' AND " & _
                          "TargetInstance.Name= 'Spooler' AND targetInstance.State = 'Stopped'"

For Each oSingleItem In objItems
If oSingleItem.State = "Running" Then
              Set objEventSource = GetObject("winmgmts:{impersonationLevel = impersonate}"). _
      ExecNotificationQuery(strWQLQuery)
              WScript.Echo  "Waiting for the Event ..."
            Set objNextEvent = objEventSource.NextEvent
            WScript.Echo " The Event took place"
            WScript.Echo    objNextEvent.TargetInstance.DisplayName & " is " & _
                                      objNextEvent.TargetInstance.State
            WScript.Echo    "Synchronous Processing Continues"
            WScript.Echo    "If ..." & vbCrLf & _
                                      "then you are using asynchronous processing"
            WScript.Echo    "If ..." & VbCrLf & _
                                    "then you are using asynchronous processing"
Else
                                      WScript.Echo "The Spooler Service is not running"
End If

MsgBox "Click on OK to Finish"

Next


Steven - 2008-1-11 19:25:00
基本上我把一半的code重写了一遍,这个是个监视某个服务运行情况的脚本,可以在后台运行。
1
查看完整版本: 求助:(WMI)从800A03EE错误到800A0401错误