I’m trying the “Win\USB Stick To Drive Letter” example and the WQL SelectQuery is failing with error -2147217405, which indicates access denied.
I have verified that call WindowsWMIMBS.InitSecurity(false) is present in App.Open.
dim w1 as new WindowsWMIMBS
var b as boolean = w1.ConnectServer("root\cimv2") //This works fine, b is true
b = w1.query("WQL", "select * from Win32_DiskDrive where InterfaceType='USB'")
//b is now false because Query has failed with error -2147217405 (0x80041003),
//which is a permissions issue
Anyone have any insights as to what might be wrong?
I have it set to elevate to Administrator and still the same error. I’m able to execute the select query from wbemtest.exe so it’s something with the component or xojo. Will keep playing around with it.
@kevin_g Indeed, but the line was in App.Open in the demo project shipped with MBS. The documentation says it needs to be executed before the first window is instantiated, which app.open should do. When I get in front of xojo later I’ll try putting it in the constructor to see if that makes a difference anyway. Or maybe if I upgrade the project to API 2.0 App.Opening might make a difference. Lots to try.
You can call this method before creating WindowsWMIMBS object, you can prepare security settings for remote connections.
Calling InitSecurity with remote=true will initialize security with kImpersonationLevelImpersonate. If remote=false, we use kImpersonationLevelIdentity which is the default.
Please call in App.Constructor before Xojo can initialize COM and prevent our function from working!
Oh ok so it indeed must be in the Constructor method!
@Christian_Schmitz It may be a good idea to update the “win\USB Stick to Drive Letter” example because .InitSecurity is in the open event instead of constructor in the example and that may be the issue. I will verify later when I’m in front of Xojo.