WindowsWMIMBS failing

Anyone using WindowsWMIMBS?

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?

You have App.Constructor with this?

Sub Constructor()
	// required for Windows 8.1 or later
	Call WindowsWMIMBS.InitSecurity(False)
End Sub

Yes, that is in App.Open.

Strange. I just run my “WMI Query” example here on Windows 11 (23H2) and the query works fine there.

Maybe it needs to run as admin?

App.Open is not the same as App.Constructor

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

Appreciate the replies from both of you, thanks.

From the MBS documentation:

WindowsWMIMBS.InitSecurity(remote as boolean) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Windows MBS Win Plugin 12.2 :x: No :white_check_mark: Yes :x: No :x: No Desktop, Console & Web

Initializes security.

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.

Thanks again to you both. :slight_smile: