?
Solved

WbemScripting.SWbemSink

Posted on 2005-03-24
18
Medium Priority
?
1,955 Views
Last Modified: 2009-04-09
Hi,

I'm testing this WMI code in VB.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/monitoring_events.asp

Pasted this code in Command1_click event, but getting the error denoted below:

Returns Run-time error "Object Required" in this line:

      Set sink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

Can anyone tell how to prevent the error message. Perhaps I need to add any DLL references to the project?

Thanks.
0
Comment
Question by:sramesh2k
  • 10
  • 8
18 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628292
Yes you need a reference to the WMI script go to Project --> references and scroll down, you cant miss it cos it says WMI in caps :) check that and ok it and try that script again, if you have any other probs let us no :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628300
The actual reference you need is called Microsoft WMI scripting V1.2 Library
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628302
Thanks gecko! There were two references starting with word WMI.. and added those two, but the error still appears.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628307
This seems like it is a vbscript so copy and paste the code into a text file and save as "script.vbs" making sure to type the quotes so it saves it as an actual vbscript, then run that vbscript and tell me if it works :)
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628315
It runs fine when i run as a .VBS. But I want to run this within a VB program as I have to add an Userinterface.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628333
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628334
That should allow you to use that wmi script in visual basic and get what you are looking for at the same time as making the GUI :)

Let me know how that goes :D
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628347
I added the Microsoft WMI Scripting V1.2 library that showed in the list. Saved the project and run it. Same error occurred.
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628357
Error details if anyone needs this:

Run-time error '424'
"Object Required"
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628366
Did you try what I suggested here :

Comment from gecko_au2003
Date: 03/24/2005 11:40PM PST
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628375
Yes, I tried all of the above suggestions.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628377
What about using the ShellExecute API to shell the vbscript file and then that way you could also make the GUI in visual basic ?

Unless another expert knows how to get the script above working in visual basic?
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628386
>> What about using the ShellExecute API to shell the vbscript

Good idea. I thought of using that earlier, but passing the script output to VB program may not be possible. Hence my idea of using the whole inside a VB project.
0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 1000 total points
ID: 13628416
I got this so far :

Sub SINK_OnObjectReady(objWbemObject, objAsyncContext)
        WScript.Echo "Display resolution changed to: " & _
        objWbemObject.targetinstance.displayfrequency & " Hz"
End Sub

Private Sub Form_Click()
Set services = GetObject("WinMgmts:")

Set sink = CreateObject("WbemScripting.SWbemSink", "") '<-- Deleted SINK_ and it just needs tested
'Set sink = CreateObject("WbemScripting.SWbemSink", "SINK_")
services.ExecNotificationQueryAsync sink, _
                    "SELECT * FROM __InstanceModificationEvent " & _
                    "WITHIN 20 " & _
                    "WHERE TargetInstance " & _
                    "ISA ""Win32_DisplayConfiguration"" " & _
                    "AND TargetInstance.DisplayFrequency > 70"


MsgBox "Change your display refresh rate" _
    & " to generate an event. " _
    & vbCr & "Click OK to stop watching for events."
End Sub

Try that out in visual basic adding a reference to WMI or WBEM scripting like that URL suggests :) Let me know if it actually works completely ie it tells you if the refresh rate has changed or w/e
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628459
Thanks, code runs in VB without any errors. But neither VBS or the program compiled in VB informs the change.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628474
In the code this line :

 "WHERE TargetInstance " & _
                    "ISA ""Win32_DisplayConfiguration"" " & _
                    "AND TargetInstance.DisplayFrequency > 70"  '<-- Checks to see if the refresh rate you select is greater then 70, so when you changed it, was it a higher frequency then 70 hz ie 75hz ??

I mean when I tested it , neither of them told me it had changed so I really have no clue other then to maybe change the >70 to > 60 or something like that maybe. Unless you can find another way of accessing the refresh rate and do it that way ? I mean what are you trying to do exactly, are you actually trying to access the refresh rate or was this just a test?
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13628534
I forgot to mention, thanks for the grade and points ! If you need more help then let me know and I will see what I can do :)
0
 
LVL 34

Author Comment

by:sramesh2k
ID: 13628973
Thanks again! BTW, it was just a test :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question