我想启用和禁用一个特定的 USB 磁盘, 我找到了这个方法 :
public static bool StateChange(bool Enable, int SelectedItem, IntPtr DevInfo)
{
bool result = false;
SP_DEVINFO_DATA devInfoData = new SP_DEVINFO_DATA(); ;
devInfoData.cbSize = Marshal.SizeOf(typeof(SP_DEVINFO_DATA));
if (true == SetupDiEnumDeviceInfo(DevInfo, SelectedItem, devInfoData))
{
SP_PROPCHANGE_PARAMS pcp = new SP_PROPCHANGE_PARAMS(); ;
pcp.ClassInstallHeader.cbSize = Marshal.SizeOf(typeof(SP_CLASSINSTALL_HEADER));
pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
pcp.Scope = DICS_FLAG_GLOBAL;
pcp.StateChange = (Enable ? DICS_ENABLE : DICS_DISABLE);
if (true == SetupDiSetClassInstallParams(DevInfo, devInfoData, pcp, Marshal.SizeOf(pcp)))
{
if (true == SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, devInfoData))
{
result = true;
}
}
}
return result;
}
But it fails when calling : SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, devInfoData) (returns false)
是因为我在运行窗口7x64?