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:
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:
stating:
C:\Users\User\Desktop\test 3.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
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
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
stating:
C:\Users\User\Desktop\test
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
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).
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")
such that your GetObject becomes:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:NV")
ASKER
When I try:
I tried:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:NV")
I get an error: (null): 0x80041002I tried:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV:Sync")
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"
ASKER
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
....
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.
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.
ASKER
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 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?
ASKER
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?
ASKER
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
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?
Also does it ask you to log in when running the wmi browser?
ASKER
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 :(
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?
What path did you use when you got that error?
ASKER
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
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?
ASKER
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
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.
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.
ASKER
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... :(
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?
When you run IE as admin and go to the ObjectBrowser, does it prompt you to log in?
ASKER
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(214788109 1, 1)
Function is described by:
boolean setSyncStateById ( [in] uint32 syncDisplayIds[],
[in] uint32 syncState[]
)
Parameters:
syncDisplayIds Array of display IDs to synchronize(SyncTopology.i d), 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???
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(214788109
Function is described by:
boolean setSyncStateById ( [in] uint32 syncDisplayIds[],
[in] uint32 syncState[]
)
Parameters:
syncDisplayIds Array of display IDs to synchronize(SyncTopology.i
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(214 7881091), Array(1))
setSyncStateByID(Array(214
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
FIGURED IT OUT!!
working on code will be back! Thanks for the help!!!!
working on code will be back! Thanks for the help!!!!
Yes! Sounds great! Please post back :-)
ASKER
So finally back!
This was how I needed to input the code:
Obviously simplified down...
What is the Array(X) do? It is hard to google because if you google 'array' you get array informaiton :)
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
Obviously simplified down...
What is the Array(X) do? It is hard to google because if you google 'array' you get array informaiton :)
ASKER
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:
Make sense?
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
Make sense?
ASKER
Yes, I think now it does :)
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)