What am I missing? I keep getting an error on line:
Set refSink = CreateObject("WBemScripting.SWbemSink","EVENTSINK_")


***********************************
<html>
<head>
<title>Service Monitor</title>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<HTA:APPLICATION
ID = "XApp"
APPLICATIONNAME = "Service Monitor"
BORDER = "thick"
CAPTION = "yes"
ICON = ""
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "no"
SCROLLFLAT = "yes"
VERSION = "1.0"
INNERBORDER = "no"
SELECTION = "no"
MAXIMIZEBUTTON = "yes"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal">

<OBJECT ID="WindowsShell"
CLASSID="clsid:13709620-C279-11CE-A49E-444553540000"></Object>
<OBJECT ID="refSink"
CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></OBJECT>

<SCRIPT LANGUAGE="VBScript">
Set WshShell = CreateObject("WScript.Shell")
Set WSHFso = CreateObject("Scripting.FileSystemObject")
Window.ResizeTo 600, 650
Window.MoveTo 5, 5

Dim refWMI
Dim refSink
Dim strQuery
Dim strComputer
Dim strServiceName
Dim iCheckEvery

Sub Test()
strComputer = "." 'Server to check
iCheckEvery = 30 'Seconds between checks

'connect to WMI and create a sink object
Set refWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set refSink = CreateObject("WBemScripting.SWbemSink","EVENTSINK_")

'execute an async notification query and block with a msgbox
strQuery = "SELECT * FROM __instancemodificationevent " & _
"WITHIN " & iCheckEvery & " WHERE TargetInstance ISA 'Win32_Service'"
refWMI.ExecNotificationQueryAsync refSink, strQuery
MsgBox("Now blocked and waiting...")

'cancel event notification
refSink.Cancel
Set refSink = Nothing
Set refWMI = Nothing
End Sub

'callback for Event Notification
Sub EVENTSINK_OnObjectReady(refEvent,refContext)
Msgbox(refEvent.TargetInstance.State)
End Sub
</script>

</head>
<body>
<form name="form1">
<input name="bTest"type="button" value="Open" onClick="Test">
</form>
</body>

Re: HTA WBemScripting.SWbemSink Problem by Michael

Michael
Tue Nov 01 19:31:28 CST 2005

Lando wrote:
> What am I missing? I keep getting an error on line:
> Set refSink = CreateObject("WBemScripting.SWbemSink","EVENTSINK_")

The VBScript CreateObject function is not the same as the
WScript.CreateObject method. The 2nd argument of each has completely
differemnt meaning and purpose. The WScript version (whose 2nd argument is
related to event sinking) can only be used from WSH hosted
(wscript/cscript.exe) scripts, not from an HTA...

These google threads should lead you to a solution...

hta event sink wmi OR wbem group:*.scripting - Google Groups
http://groups.google.com/groups?q=hta%20event%20sink%20wmi%20OR%20wbem%20group:*.scripting

--
Michael Harris
Microsoft MVP Scripting





Re: HTA WBemScripting.SWbemSink Problem by Lando

Lando
Tue Nov 01 19:53:03 CST 2005

Thanks but I looked but it didn't help. I'm not a professional programmer and
I don't really even understand how this is working. All I know that it does
in Wscript. Can you post some sample code that I would use to get this
working? Maybe I could figure out from there. Thanks again Michael.

"Michael Harris (MVP)" wrote:

> Lando wrote:
> > What am I missing? I keep getting an error on line:
> > Set refSink = CreateObject("WBemScripting.SWbemSink","EVENTSINK_")
>
> The VBScript CreateObject function is not the same as the
> WScript.CreateObject method. The 2nd argument of each has completely
> differemnt meaning and purpose. The WScript version (whose 2nd argument is
> related to event sinking) can only be used from WSH hosted
> (wscript/cscript.exe) scripts, not from an HTA...
>
> These google threads should lead you to a solution...
>
> hta event sink wmi OR wbem group:*.scripting - Google Groups
> http://groups.google.com/groups?q=hta%20event%20sink%20wmi%20OR%20wbem%20group:*.scripting
>
> --
> Michael Harris
> Microsoft MVP Scripting
>
>
>
>
>