Open FuPeiJiang opened 1 month ago
I had misunderstood:
ok:=DllCall("Setupapi\SetupUninstallOEMInfW","WStr","oem23.inf","Uint",0x0001,"Ptr",0,"Int") ;0x0001=SUOI_FORCEDELETE
SetupUninstallOEMInfW works, but DiUninstallDriver didn't
if (forceDelete
&& MethodExists("newdev.dll", "DiUninstallDriverW")
&& !NativeMethods.DiUninstallDriver(
IntPtr.Zero,
Path.Combine(driverStoreEntry.DriverFolderLocation, driverStoreEntry.DriverInfName),
DIURFLAG.NO_REMOVE_INF,
out _))
{
throw new Win32Exception();
}
if (!NativeMethods.SetupUninstallOEMInf(
driverStoreEntry.DriverPublishedName,
forceDelete ? SetupUOInfFlags.SUOI_FORCEDELETE : SetupUOInfFlags.NONE,
IntPtr.Zero))
{
throw new Win32Exception();
}
this code only tries DiUninstallDriver
when forceDelete
is true, while SetupUninstallOEMInf(SUOI_FORCEDELETE)
was the only one to work
for this to work, MethodExists("newdev.dll", "DiUninstallDriverW")
must evaluate to false, then it'll fallback to SetupUninstallOEMInf(SUOI_FORCEDELETE)
, but newdev.dll
was available
it'd be nice if SetupUninstallOEMInf
was used as a fallback if DiUninstallDriver
fails
bool success = false
if (forceDelete && MethodExists("newdev.dll", "DiUninstallDriverW")) {
success = NativeMethods.DiUninstallDriver(
IntPtr.Zero,
Path.Combine(driverStoreEntry.DriverFolderLocation, driverStoreEntry.DriverInfName),
DIURFLAG.NO_REMOVE_INF,
out _)
}
if (!success && !NativeMethods.SetupUninstallOEMInf(
driverStoreEntry.DriverPublishedName,
forceDelete ? SetupUOInfFlags.SUOI_FORCEDELETE : SetupUOInfFlags.NONE,
IntPtr.Zero))
{
throw new Win32Exception();
}
; #define DIURFLAG_NO_REMOVE_INF 0x00000001 // Do not remove inf from the system
; #define DIURFLAG_UNCONFIGURE_INF 0x00000002 // Unconfigure inf, if possible
ok:=DllCall("newdev\DiUninstallDriverW","Ptr",0,"WStr","C:\Windows\System32\DriverStore\FileRepository\.inf","Uint",0x00000002,"Int*",&NeedReboot:=0,"Int")
I don't think DiUninstallDriverW
provides a way to "force" past ERROR_INF_IN_USE_BY_DEVICES(0xE000023D), those are the only flags, and I don't understand much of them,
C:\Windows\INF\setupapi.dev.log
I think it has to do with undocumented flags:
Rapr.exe
: DrvSetupUninstallDriver(0x00000001
)Rapr.exe
(Force Deletion) : DrvSetupUninstallDriver(0x20000000
)devcon.exe dp_delete
: DrvSetupUninstallDriver(0x00000001
)devcon.exe -f dp_delete
DrvSetupUninstallDriver(0x10000001
->0x00010002
)I don't know how
DrvSetupUninstallDriver
is reached/called, I'll probably use windbgsidenote:
devcon -f dp_delete
works but I don't want to cleanup registry or don't even know how to/ where to.