Deleting browser histories

Hello,

I want to delete browsers histories. But this is important not to delete saved passwords.

You have one code.

Name: Delete the system temp files, internet temp files and browser cache files for all users

Can you add to this code to delete the histories while deleting the browser cookies (If not possible, can you make a new script, it will delete the history of all browsers on the computer)

(Or if this code deletes the history of browsers, it didn’t delete the history when I tried it. Could you please let me know about it)

I wish you good work.

Best regards.

Hi @hguler07,

Thanks for your request. We will update you script once it is prepared by our script developers.

Kind Regards,
PremJK

Hi @hguler07,

Our script developers want to know for which browser you want to delete histories.

Kind Regards,
PremJK

Hello,

Chrome and Firefox are generally used in our institution.

Kind Regards

Hi @hguler07,

Please run this script and provide your feedback
https://scripts.itarian.com/frontend/web/topic/script-to-remove-history-from-chrome-and-firefox-excluding-logins

Kind Regards,
PremJK

​​Hello,

The script works. But it is deleting data from chrome browser of another user on Computer. Instead of logging into the system, I also ran the script as a logged-in user and still failed.

I’m taking relevant screenshots. The only problem is that the user I am currently using is deleting the data.


Best regards

Hi @hguler07,

Thanks for trying and providing output. Will share this with our script developers and update you.

Kind Regards,
PremJK

Hi @hguler07,

Our script developers wants to know whether you checked with opening browser and check for history and login details ,since it doesn’t delete all the folder .The login details will be saved in that folders and also if browser is being used while running the script it cannot delete certain files and folders which is used by browser.

Only history, cookies, cache will be deleted and login details will be preserved. Please check the image attached

Kind Regards,
PremJK

Hello

Yes I have tested it as you say it does not delete my history in chrome browser in any way.

I checked in Firefox the result is the same.
I am sharing the related screenshots

the code I'm running

#Packages
import os
import subprocess
import shutil
import time
import re
#----------------------------------------------------------------------------------------------------
start_time = time.time()
#----------------------------------------------------------------------------------------------------
#Functions
def remove(path):
#Remove the file or directory
if os.path.isdir(path):
try:
shutil.rmtree(path)
except OSError:
print "Unable to remove folder: %s" % path
else:
try:
if os.path.exists(path):
os.remove(path)
except OSError:
print "Unable to remove file: %s" % path


def chrome_cleanup(dirpath,folder_to_exclude):
for root, dirs, files in os.walk(dirpath, topdown=True):
for file_ in files:
full_path = os.path.join(root, file_)
if folder_to_exclude not in full_path:
print 'removing -> ' + full_path
remove(full_path)
for folder in dirs:
full_path = os.path.join(root, folder)
if folder_to_exclude not in full_path:
remove(full_path)

def firefox_cleanup(dirpath,folder_to_exclude):
for root, dirs, files in os.walk(dirpath, topdown=True):
for file_ in files:
full_path = os.path.join(root, file_)
if folder_to_exclude[0] not in full_path and folder_to_exclude[1] not in full_path:
print 'removing -> ' + full_path
remove(full_path)
for folder in dirs:
full_path = os.path.join(root, folder)
if folder_to_exclude[0] not in full_path and folder_to_exclude[1] not in full_path:
remove(full_path)

def permissions(dirpath):
mode=0o777
if os.path.isdir(dirpath):
try:
for root,dirs,files in os.walk(dirpath,topdown=False):
for dircs in [os.path.join(root,d) for d in dirs]:
os.chmod(dircs,mode)
for s_file in [os.path.join(root,f) for f in files]:
os.chmod(s_file,mode)
except Exception as E:
print E

#path_creation
def path_creation(fil_users):
fir_ls=[]
chr_ls=[]
ls=[]
#firefox
for i in fil_users:
try:
path="C:\Users\%s\AppData\Roaming\Mozilla\Firefox\ Profiles"%i
if os.path.exists(path):
os.chdir(path)
ls.append(os.popen('cd').read().rstrip())
except:
print("No Path")

for i in ls:
os.chdir(i)
out=os.popen('dir').read()
fir_ls.append(re.findall('\w+.default-release',out))
fir_ls_n=[]
for i in fir_ls:
if i[0]:
fir_ls_n.append(i[0])
else:pass
l=[]
for i,j in zip(fir_ls_n,ls):
l.append(os.path.join(j,i))
#chrome
for i in fil_users:
chr_path='C:\Users\%s\AppData\Local\Google\Chrome\ User Data\Default'%i
if os.path.exists(chr_path):
chr_ls.append(chr_path)
else:
pass
return [l,chr_ls]
#-----------------------------------------------------------------------------------------------------
#codes
users=os.popen("net user").read().split()[5:-5]
filtered_users=[i for i in users if i!='Guest']
#print filtered_users

paths=path_creation(filtered_users)
#print paths[1]

# save_path_chrome=[]
# for i in paths[1]:
# save_path_chrome.append(i+"\Login Data")
# tot_chrome=zip(paths[1],save_path_chrome)

save_path_fire=[]
for i in paths[0]:
save_path_fire.append([i+"\logins.json",i+"\key4.db"])
tot_fire=zip(paths[0],save_path_fire)

#print paths[0]
#print paths[1]
#print save_path_chrome
#print tot_chrome
#print tot_fire[0][1]
try:
#chrome
for i in paths[1]:
if os.path.exists(i):
print("Starting Google Chrome...
")
print("Chrome Permission fixing...")
permissions(i)
print("Cleaning Up Chrome....
")
chrome_cleanup(i,'Login Data')
print("Chrome Completed!!!
")
#firefox
for i,j in tot_fire:
if os.path.exists(i):
print("Starting Mozilla Firefox...
")
print("Firefox Permission fixing...")
permissions(i)
print("Cleaning Up Firefox....
")
firefox_cleanup(i,j)
print("Firefox Completed!!!
")
except Exception as E:
print E
finally:
print "Code Executed"
print("--- %s seconds ---" % (time.time() - start_time))

Can you please inform me if there is a mistake I made after the necessary investigations, finally I ran the code as a system user. I wish you good work.

Best regards

Hi @hguler07,

Thanks for trying and providing your feedback. We have asked our script developers to investigate the issue.

Kind Regards,
PremJK

Hi @hguler07,

Our script developers want to arrange remote session to test the script in your environment. Can you please help us in remote session.

Kind Regards,
PremJK

Hi

Of course, I can share my Anydesque Id with you. I’m available until 18:00 today. GMT + 03: 00
I’m sending you a private message in terms of security

Kind Regards,

Hi @hguler07,

Thank you so much. We will create a support ticket to arrange remote session.

Kind Regards,
PremJK

Hi @hguler07,

Can you please check your Inbox for private message and provide requested detail.

Kind Regards,
PremJK

Hello.

I want to inform you about the latest developments.
Your support team connected to my computer at 11:00 today. They checked the problem. I normally test a script file first on my own computer. If I see it working properly, I apply it to other computers in the institution. Your developer team asked me to try this code on the test machine. When we close the Browsers on the computer next to me and test the code. Successfully cleared the history of Google Chrome and Firefox browsers. And it did not delete saved passwords as I wanted.

The code was working properly. Couldn’t run the code properly just because of possibilities that I couldn’t predict

Thank you very much for your help and attention.
I wish you healthy days.
Best regards.

Hi @hguler07,

We are glad to hear that script is working good for you. Please reach us if you have any other request or issues, we are happy to assist.

Kind Regards,
PremJK