Old devices and driver cleanup (one command)


  1. Posts : 46
    many
       #1

    Old devices and driver cleanup (one command)


    Found this little gem of a command today. Wanted to share it with you. Nice to schedule this as a task running once a month?

    Rundll32.exe c:\windows\system32\pnpclean.dll,RunDLL_PnpClean /DEVICES /DRIVERS /FILES [/MAXCLEAN]
    For pnpclean output see c:\windows\inf\setupapi.dev.log

    PNPCLEAN [/DEVICES] [/DRIVERS] [/FILES] [/MAXCLEAN] [/NOREMOVE] /? /help /h

    /DEVICES Removes devices missing for the default time period
    /DRIVERS Removes redundant drivers from the system
    /FILES Removes files/directories that are no longer needed that are related to devices and drivers.
    /MAXCLEAN Performs maximum cleanup
    For /DEVICES this will set the time period to 0 so that every missing device will be processed for removal. (Note: Default missing device timeout period is 30 days!!!)
    For /DRIVERS this will allow every driver that is not installed on some device to be processed for removal.
    For /FILES this currently has no effect on what is removed.
    /NOREMOVE Evaluate items only, do not remove

    Did some testing and using it without /MAXCLEAN is probably best for using it in Task Scheduler once a month.

    Cheers
      My Computer


  2. Posts : 56,921
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #2

    Could you post the source where you found this so we can learn a little more? Thanks.
      My Computers


  3. Posts : 177
    Windows 10 Home 64 Bits 2004 Latest Version
       #3

    Looking forward to hear this
      My Computer


  4. Posts : 32,582
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #4

    Apparently MS use this command themselves in the 'Windows update reliability tool'. But it was applied a little too enthusiastically a year ago resulting in this KB article...

    This issue occurs because Windows receives an update reliability tool during a Windows Update installation of KB 4023057. The tool is designed to clean up the INF driver cache as part of its remediation procedures....

    ...The applicability rules for the Windows update reliability tool have been improved. In addition, the latest version of this tool (10.0.14393.10020 or a later version) should not cause the issue.
    KB4098563 | USB device drivers are removed unexpectedly after Windows 10 is updated
      My Computers


  5. Posts : 46
    many
    Thread Starter
       #5

    Another command to get rid of older drivers (in c:\windows\system32\driverstore) that I used befor in a script is:

    For /f %%P in ('dism /online /get-drivers /format:table^|Findstr oem') do pnputil.exe /d %%P

    But it is limited to 3rd party drivers and doesn't remove "disconnected" devices. To get that done I used a little util called DeviceCleanupCmd.exe that also can remove "disconnected" devices that are not used within a given time frame.

    PnPClean.dll does it all in one command. It is not limited to Windows 10. Windows 2012R2 also has it. But then without the /FILES option.
      My Computer


  6. Posts : 8,000
    Windows 11 Pro 64 bit
       #6

    I use DriverStore Explorer. This scans and displays all drivers on the PC then you can highlight old drivers and decide whether you want to delete them.
      My Computers


  7. Posts : 17,057
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    TC,

    If you look at c:\windows\inf\setupapi.dev.log in Notepad & scroll down to the end, you'll see the posted instructions.

    There's a discussion of this utility in Inside the hack that fixes most of the Windows 10 build 10122 upgrade issues - DeploymentResearch [published in 2015]
    - The article says that the utility must be run as System
    - @IronZorg89, however, says that it can be run as Admin
    - The article refers to an earlier blog by Pieter Wigleven. This is now at installer stuck at 18 when upgrading from windows 10 10074 to 10112 - Pieter Wigleven Blog - MSDocs

    I have not found any other useful info or, indeed, anything else that predates the DeploymentResearch article.

    Denis
      My Computer


  8. Posts : 56,921
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #8

    Try3 said:
    TC,

    If you look at c:\windows\inf\setupapi.dev.log in Notepad & scroll down to the end, you'll see the posted instructions.

    There's a discussion of this utility in Inside the hack that fixes most of the Windows 10 build 10122 upgrade issues - DeploymentResearch [published in 2015]
    - The article says that the utility must be run as System
    - @IronZorg89, however, says that it can be run as Admin
    - The article refers to an earlier blog by Pieter Wigleven. This is now at installer stuck at 18 when upgrading from windows 10 10074 to 10112 - Pieter Wigleven Blog - MSDocs

    I have not found any other useful info or, indeed, anything else that predates the DeploymentResearch article.

    Denis
    Thanks, Denis, but I have no idea what you are talking about!
      My Computers


  9. Posts : 17,057
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #9

    TC,

    In your post #2, you asked the OP what the source was.

    {I had edited my response and somehow managed to lose the {quote} bit so you could see I was responding to that.}
    f14tomcat said:
    Could you post the source where you found this so we can learn a little more? Thanks.


    And your formatting problem in your post below this was also my fault. I had written the word quote [above] within square brackets & that confused the system when you then quoted me.

    Denis
      My Computer


  10. Posts : 56,921
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #10

    [QUOTE=Try3;1830984]TC,

    In your post #2, you asked the OP what the source was.

    {I had edited my response and somehow managed to lose the
    bit so you could see I was responding to that.}

    Denis
    oh! ok... got it now, thanks.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:37.
Find Us




Windows 10 Forums