Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vbscript WMI Using Public Member Functions (nVidia NV2)

Posted on 2013-10-26
33
Medium Priority
?
847 Views
Last Modified: 2013-11-18
Hi All,

I am trying to use some nVidia functions in there WMI API (attached, it is a txt file but should be renamed to chm for help file)

I am new to vbscript so can be doing something wrong.

My code is as follows:

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array(".")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM SyncTopology", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
		NodeID = objItem.id
		WScript.Echo "id: " & NodeID
		WScript.Echo
   Next

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV")
	Set SyncClass = objWMIService.Get("Sync")
	if (SyncClass.toggleSource()) Then
		wscript.echo "done!"
	End if
	
Next

Open in new window


I am actually trying to use a different function but this one is the easiest and takes no arguments.

The class is 'Sync' the function is toggleSource, should be too easy!

I get an error on line:
	if (SyncClass.toggleSource()) Then

Open in new window


stating:
C:\Users\User\Desktop\test3.vbs(28, 2) SWbemObjectEx: Invalid method Parameter(s)

I can query attributes in the class just can run methods :(

I can use these methods in Powershell so they should work, just can't get it working in vbscript!! AHHH...
nvwmi.txt
0
Comment
Question by:acrouch817
  • 18
  • 15
33 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 39604763
I would suggest downloading the WMI Object Browser: http://www.microsoft.com/en-au/download/details.aspx?id=24045.  It will at least be able to tell you if your WMI path is correct.
I was going to suggest trying to call the method indirectly using the ExecMethod function of the SWbemObjectEx but it would be guess work until you know for sure that the path is correct (for vbs use anyway)
0
 

Author Comment

by:acrouch817
ID: 39610234
Hi tagit,

The path is correct, how would one use ExecMethod to run a method? I only see examples on how to use it with an executable (I apologize in advanced for what appears to be a 'stupid' question).
0
 
LVL 43

Expert Comment

by:Rob
ID: 39610299
I'd like you to just try testing the path with :NV instead of /NV

such that your GetObject becomes:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:NV")
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

Author Comment

by:acrouch817
ID: 39610308
When I try:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:NV")

Open in new window

I get an error: (null): 0x80041002
I tried:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV:Sync")

Open in new window

But get the same error when trying to access the method...
0
 
LVL 43

Expert Comment

by:Rob
ID: 39610313
As for the execMethod, you can use it with your namespace (but I can't test this in my environment):

Set WbemServices = GetObject("winmgmts:")
Set oService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:NV.Sync")
Set oPath = oService.Path_
WbemServices.ExecMethod oPath, "toggleSource"

Open in new window

0
 

Author Comment

by:acrouch817
ID: 39610334
Thanks for the help!

I tried the method example.

Had to change to "CIMV2\NV:Sync" (otherwise that line gave an error)

I get an error on the last line SWbemServicesEx: Not Found

....
0
 
LVL 43

Expert Comment

by:Rob
ID: 39610348
Ok so the path is right - sorry I just had to make absolutely sure.  The manual also confirms it.

Did you try the root/CIMV2/NV.Sync ??

It does seem you're doing everything right so I wonder if it's a permissions issue?  What is your environment? Wiindows 8 etc etc

Did you also download the WMI Browser?  It will show you the NV namespace along with the Sync objects and others beneath it.  It will also show you the methods etc.  If you have this up and you try and click it will also tell you if you don't have the right permissions to access it.
0
 

Author Comment

by:acrouch817
ID: 39610400
I am running Windows 7 Embedded, but again I can connect to the class just not the method :(

I did try NV.Sync and I get an error.


I did try the WMI Browser and maybe misinterpreted it, it shows a red line through the methods, I thought before this is just what the methods should show but now think that this means they are not accessible?
0
 

Author Comment

by:acrouch817
ID: 39610417
I can run the method with power shell though, as the same user check if powershell does something fancy that vbscript does not
0
 
LVL 43

Expert Comment

by:Rob
ID: 39610684
I did try the WMI Browser and maybe misinterpreted it, it shows a red line through the methods, I thought before this is just what the methods should show but now think that this means they are not accessible?

Certainly would seem that way... I had to run the WMI browser in IE8 to get it to work.  There certainly could be security restrictions in place for scripting vs using powershell.

Should've asked this earlier but why don't you just use powershell?
0
 

Author Comment

by:acrouch817
ID: 39613061
i am integrating this snipit in a larger vbs file already created, putting a powershell would be an ugly thing to add in the vbs script that I would like to avoid :)
0
 
LVL 43

Expert Comment

by:Rob
ID: 39613065
Sure and it would be.
How did you run the wmi browser? I could get it only to work in ie8
0
 
LVL 43

Expert Comment

by:Rob
ID: 39613071
It's certainly looking like the the methods are inaccessible for some reason.  Have you tried to run your script with elevated privledges.  ie right click your vbs and "run as administrator" ??
0
 
LVL 43

Expert Comment

by:Rob
ID: 39615771
Can you post a screenshot of the red lines through the methods?
Also does it ask you to log in when running the wmi browser?
0
 

Author Comment

by:acrouch817
ID: 39618332
Sorry for the late reply,,,, so before I was running it remotely from the domain controller on a network now I am running it on a client, directly with admin rights.

I get an error on:
WbemServices.ExecMethod oPath, "toggleSource"

It is:
SWbemServicesEx: not found....

Sorry to jump around :(
0
 
LVL 43

Expert Comment

by:Rob
ID: 39618631
All good to jump around :-)
What path did you use when you got that error?
0
 

Author Comment

by:acrouch817
ID: 39619382
ok, i am running on windows embedded and am remote right now and can't put IE 10 on it so objectbrowser is not working... :(

Using path \root\CIMV2\NV:Sync

If I use \root\CIMV2:NV.Sync, I get an error on this line so using the \NV:Sync
0
 
LVL 43

Expert Comment

by:Rob
ID: 39619468
If you press f12 and bring up the dev tools you can change the standards to ie7 or ie8. That should allow the browser to work
0
 
LVL 43

Expert Comment

by:Rob
ID: 39619472
And the \NV:Sync working?
0
 

Author Comment

by:acrouch817
ID: 39620218
ok back..

So yes \NV:Sync is working!

Also had no IE installed, got IE 9 installed Object Browser works!

Attached is the screen shot of the methods of Sync.

Thanks!
Untitled.png
0
 
LVL 43

Expert Comment

by:Rob
ID: 39623079
Ha, yes only works in IE (thanks Microsoft).

When you run the browser, right click it first and run as administrator.  Does that remove the red lines?

Ok so we know the path is correct and that the functions are there but permissions are not correct to allow you to use them, hence why I'm trying to get you to run the browser with elevated permissions to see if it makes a difference.

The other thing to note is that you should be prompted to login when the browser first opens  so try a few combinations here as well to see if it makes any difference.
0
 

Author Comment

by:acrouch817
ID: 39636208
sorry back so late, got all weekend on this one...

I tried a bunch of stuff, no luck.  I am logged on as Administrator though.  You can't start ObjectBrowser as admin, so I start IE as Admin and then try to go to ObjectBrowser, no change... :(
0
 
LVL 43

Expert Comment

by:Rob
ID: 39636228
:) fun when you've got all the time in the world eh?

When you run IE as admin and go to the ObjectBrowser, does it prompt you to log in?
0
 
LVL 43

Expert Comment

by:Rob
ID: 39636230
i get the following prompts:

namespace
click enable all privileges
enable all priv
0
 

Author Comment

by:acrouch817
ID: 39636399
ok o did some more work here....

I did not know about the enable so thanks, but tried this and no change...

FYI, never asked for a password....

but I looked at the method 'rename' of Win32_ComputerSystem class and this too has the red check but I can run it!

So maybe the permissions are OK?

I reran the original script and I am getting "SWbemObjectEX: Type mismatch", maybe I am inputting the data incorrect?

I am calling setSyncStateByID(2147881091, 1)


Function is described by:

boolean setSyncStateById  ( [in] uint32  syncDisplayIds[],  
  [in] uint32  syncState[]  
 )    


Parameters:
 syncDisplayIds  Array of display IDs to synchronize(SyncTopology.id), separated by comma. Order is important. For Mosaic topologies, user can specify either a master display or all displays in a Mosaic topology. If user does not specify any displays, the method will choose the best topology to synchronize. To un-synchronize the displays, user will have to pass all the displays with displaySyncState as UnSynced.  

 syncState  Possible values are: 0 - UnSynced, 1 - Slave, 2 - Master


Maybe the numbers really need to be an array???
0
 
LVL 43

Expert Comment

by:Rob
ID: 39636493
Yes that's what it looks like so what if you try:
 setSyncStateByID(Array(2147881091), Array(1))
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 39636494
Sounds right about the permissions as  well. But we needed to go through that process :-)
0
 

Author Comment

by:acrouch817
ID: 39636554
FIGURED IT OUT!!

working on code will be back!  Thanks for the help!!!!
0
 
LVL 43

Expert Comment

by:Rob
ID: 39636590
Yes! Sounds great! Please post back :-)
0
 

Author Comment

by:acrouch817
ID: 39655590
So finally back!

This was how I needed to input the code:

SyncType = Array(0)
NodeID = Array(12345678)

Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" & '." & "\root\cimv2\NV")

Set colComputers = objWMIService.ExecQuery ("Select * from Sync")

For Each objComputer in colComputers
		ErrCode = objComputer.setSyncStateById(NodeID, SyncType)
Next

Open in new window


Obviously simplified down...

What is the Array(X) do?  It is hard to google because if you google 'array' you get array informaiton :)
0
 

Author Closing Comment

by:acrouch817
ID: 39655591
Great help through the problem!
0
 
LVL 43

Expert Comment

by:Rob
ID: 39655620
the sync state function is expecting two arguments: nodeID and syncType. But it also is designed so that you can give it more than one nodeID so even though your only doing one node it doesn't know that and is expecting an array, so you have to pass it an array with only one element.

You could also do this if you had more than one nodeID, or wanted to change the same nodeID's syncType multiple times:

SyncType = Array(0,1,0) ' corresponding states for following IDs 
NodeID = Array(12345678, 2341235, 3388382) ' assuming these are valid IDs

Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" & '." & "\root\cimv2\NV")

Set colComputers = objWMIService.ExecQuery ("Select * from Sync")

For Each objComputer in colComputers
		ErrCode = objComputer.setSyncStateById(NodeID, SyncType)
Next

Open in new window


Make sense?
0
 

Author Comment

by:acrouch817
ID: 39657844
Yes, I think now it does :)
0

Featured Post

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!

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

972 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