?
Solved

WbemScripting.SWbemSink

Posted on 2005-03-24
18
Medium Priority
?
1,916 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 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