Reputation: 1
I am using Setup Api calls to disable USB when they are plugged in, but the calls are giving inconsistent results or not blocking the USB's.
The Api's that I am using are as follows:
The above two API's give the status of the USB device plugged in that is enabled or disabled. if enabled we go ahead to disable the device using the below API's
we set all the change params required and pass to the above API's but they are failing to disable the USB.
code as below:
setupapi.SP_PROPCHANGE_PARAMS ChangeParams = new setupapi.SP_PROPCHANGE_PARAMS();
ChangeParams.ClassInstallHeader.cbSize = Marshal.SizeOf(typeof(setupapi.SP_CLASSINSTALL_HEADER));
ChangeParams.ClassInstallHeader.InstallFunction = setupapi.DIF_PROPERTYCHANGE;
ChangeParams.Scope = setupapi.DICS_FLAG_CONFIGSPECIFIC; //DICS_FLAG_GLOBAL;
ChangeParams.StateChange = bEnable ? setupapi.DICS_ENABLE : setupapi.DICS_DISABLE;
ChangeParams.HwProfile = 0;
int PropChangeSize = Marshal.SizeOf(typeof(setupapi.SP_PROPCHANGE_PARAMS));
PSP_PROPCHANGE_PARAMS = Marshal.AllocHGlobal(PropChangeSize);
Marshal.StructureToPtr(ChangeParams, PSP_PROPCHANGE_PARAMS, true);
bool bRes = setupapi.SetupDiSetClassInstallParams(set, ref data, PSP_PROPCHANGE_PARAMS, PropChangeSize);
bRes = setupapi.SetupDiChangeState(set, ref data);
Any help to make disable the USB would be helpful.
Upvotes: 0
Views: 30