0

I am seeing 'command line' options for clearing the IE cache from a command line, but cannot figure out how to do this programmatically from python, or even from an MS Dos prompt for that matter. Here's what I found from StackOverflow: clear cache of browser by command line:

Deletes ALL History - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

Deletes History Only - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

Deletes Cookies Only - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

Deletes Temporary Internet Files Only - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

Deletes Form Data Only - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

Deletes Password History Only - RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

So my question is, how can I convert the above 'commands' into something I can run directly from python using subprocess, for example, that will clear the IE cache.

David Miller
  • 512
  • 2
  • 4
  • 17
  • 1
    Are you able to run it from CLI? If you do - look at https://docs.python.org/3/library/subprocess.html and see how to invoke it from python – balderman Oct 04 '19 at 09:33

1 Answers1

1

This worked for me. Just comment out whatever command you don't want/need.

import subprocess

commands = (
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255", # Deletes ALL History 
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1",   # Deletes History Only
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2",   # Deletes Cookies Only
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8",   # Deletes Temporary Internet Files Only
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16",  # Deletes Form Data Only 
            "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32",  # Deletes Password History Only
            )

for command in commands:
    with subprocess.Popen(command) as p:
        p.wait()
        print(f"{p.returncode} - {command}")
GordonAitchJay
  • 4,640
  • 1
  • 14
  • 16
  • That works, thanks! I think I was not properly invoking subcommand... – David Miller Oct 10 '19 at 23:41
  • 2
    @DavidMiller, from your last comment. It looks like your issue was solved with the suggestion given by Gordon. I suggest you to mark Gordon's answer as an accepted answer. It can help other users in similar kind of issue in future. Thanks for your understanding. – Deepak-MSFT Oct 14 '19 at 06:00