From 389bdb217d54112d96b40bc967f86b17a605bed6 Mon Sep 17 00:00:00 2001 From: Tim Felser Date: Fri, 25 Aug 2017 16:42:50 +0200 Subject: Added a new command "removeall" Just like "findall" corresponds to "find" this new command acts like "remove" but it will also remove non-present devices. So it is easy to remove all instances of an USB driver. --- setup/devcon/cmds.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ setup/devcon/msg.mc | 21 +++++++++++++++ 2 files changed, 94 insertions(+) (limited to 'setup') diff --git a/setup/devcon/cmds.cpp b/setup/devcon/cmds.cpp index 1af49c5c..0002b393 100644 --- a/setup/devcon/cmds.cpp +++ b/setup/devcon/cmds.cpp @@ -1551,6 +1551,78 @@ Return Value: return failcode; } +int cmdRemoveAll(_In_ LPCTSTR BaseName, _In_opt_ LPCTSTR Machine, _In_ DWORD Flags, _In_ int argc, _In_reads_(argc) PTSTR argv[]) +/*++ + +Routine Description: + +REMOVEALL +remove devices +like remove, but also remove not-present devices + +Arguments: + +BaseName - name of executable +Machine - machine name, must be NULL +argc/argv - remaining parameters + +Return Value: + +EXIT_xxxx + +--*/ +{ + GenericContext context; + TCHAR strRemove[80]; + TCHAR strReboot[80]; + TCHAR strFail[80]; + int failcode = EXIT_FAIL; + + UNREFERENCED_PARAMETER(Flags); + + if (!argc) { + // + // arguments required + // + return EXIT_USAGE; + } + if (Machine) { + // + // must be local machine as we need to involve class/co installers + // + return EXIT_USAGE; + } + if (!LoadString(NULL, IDS_REMOVED, strRemove, ARRAYSIZE(strRemove))) { + return EXIT_FAIL; + } + if (!LoadString(NULL, IDS_REMOVED_REBOOT, strReboot, ARRAYSIZE(strReboot))) { + return EXIT_FAIL; + } + if (!LoadString(NULL, IDS_REMOVE_FAILED, strFail, ARRAYSIZE(strFail))) { + return EXIT_FAIL; + } + + context.reboot = FALSE; + context.count = 0; + context.strReboot = strReboot; + context.strSuccess = strRemove; + context.strFail = strFail; + failcode = EnumerateDevices(BaseName, Machine, 0, argc, argv, RemoveCallback, &context); + + if (failcode == EXIT_OK) { + + if (!context.count) { + FormatToStream(stdout, MSG_REMOVE_TAIL_NONE); + } else if (!context.reboot) { + FormatToStream(stdout, MSG_REMOVE_TAIL, context.count); + } else { + FormatToStream(stdout, MSG_REMOVE_TAIL_REBOOT, context.count); + failcode = EXIT_REBOOT; + } + } + return failcode; +} + int cmdRescan(_In_ LPCTSTR BaseName, _In_opt_ LPCTSTR Machine, _In_ DWORD Flags, _In_ int argc, _In_reads_(argc) PTSTR argv[]) /*++ @@ -2389,6 +2461,7 @@ DispatchEntry DispatchTable[] = { { TEXT("listclass"), cmdListClass, MSG_LISTCLASS_SHORT, MSG_LISTCLASS_LONG }, { TEXT("reboot"), cmdReboot, MSG_REBOOT_SHORT, MSG_REBOOT_LONG }, { TEXT("remove"), cmdRemove, MSG_REMOVE_SHORT, MSG_REMOVE_LONG }, + { TEXT("removeall"), cmdRemoveAll, MSG_REMOVEALL_SHORT, MSG_REMOVEALL_LONG }, { TEXT("rescan"), cmdRescan, MSG_RESCAN_SHORT, MSG_RESCAN_LONG }, { TEXT("resources"), cmdResources, MSG_RESOURCES_SHORT, MSG_RESOURCES_LONG }, { TEXT("restart"), cmdRestart, MSG_RESTART_SHORT, MSG_RESTART_LONG }, diff --git a/setup/devcon/msg.mc b/setup/devcon/msg.mc index a3c677e9..ca348bde 100644 --- a/setup/devcon/msg.mc +++ b/setup/devcon/msg.mc @@ -811,6 +811,27 @@ MessageId=61204 SymbolicName=MSG_REMOVE_TAIL Language=English %1!u! device(s) were removed. . +MessageId=61205 SymbolicName=MSG_REMOVEALL_LONG +Language=English +Devcon Removeall Command +Removes devices with the specified hardware or instance ID, including devices +that are not currently attached. Valid only on the local computer. +(To reboot when necesary, Include -r .) +%1 [-r] %2 [...] +%1 [-r] %2 = [...] + Specifies a device setup class. +Examples of : + * - All devices + ISAPNP\PNP0501 - Hardware ID + *PNP* - Hardware ID with wildcards (* matches anything) + @ISAPNP\*\* - Instance ID with wildcards (@ prefixes instance ID) + '*PNP0501 - Hardware ID with apostrophe (' prefixes literal match - matches exactly as typed, + including the asterisk.) +. +MessageId=61206 SymbolicName=MSG_REMOVEALL_SHORT +Language=English +%1!-20s! Remove devices, including those that are not currently attached. +. ;// ;// RESCAN -- cgit v1.3.1