Link to home
Start Free TrialLog in
Avatar of acrouch817
acrouch817

asked on

vbscript WMI Using Public Member Functions (nVidia NV2)

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
Avatar of Rob
Rob
Flag of Australia image

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)
Avatar of acrouch817
acrouch817

ASKER

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).
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")
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...
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

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

....
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.
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?
I can run the method with power shell though, as the same user check if powershell does something fancy that vbscript does not
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?
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 :)
Sure and it would be.
How did you run the wmi browser? I could get it only to work in ie8
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" ??
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?
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 :(
All good to jump around :-)
What path did you use when you got that error?
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
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
And the \NV:Sync working?
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
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.
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... :(
:) 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?
i get the following prompts:

User generated image
click enable all privileges
User generated image
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???
Yes that's what it looks like so what if you try:
 setSyncStateByID(Array(2147881091), Array(1))
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
FIGURED IT OUT!!

working on code will be back!  Thanks for the help!!!!
Yes! Sounds great! Please post back :-)
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 :)
Great help through the problem!
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?
Yes, I think now it does :)