Display warning for the user before running the script to delete temp files

After speaking to @Jack_C I understand there is no way to schedule script to run at system start up. Since when this script runs it closes the web browsers and will potentially slow the PC down whilst it deletes, is there any way to display a warning message before it runs? Also, can it be customised to delete temporary files for the Edge browser?

https://scripts.comodo.com/frontend/…-for-all-users

Hi @nct

This could be possible.
We will get in touch with you shortly once completed.

Thank you

Thanks, would be good if a warning could be displayed maybe 30, 20 and 10 mins before the clean up starts and closes as it will close the web browsers.

Any update on this yet? @Aravind_pandi

Hi @nct

We are at the last step of progress.
Sure will give you positive result by tomorrow.

Hi @nct

Please refer the following Script which generates the warning message before running the script with particular time interval which has provided.

Note:

Run as Logged in user

time=r’5 Seconds#provide the time which you want to show in message box.
t_set=5.0 #provide the required time in seconds as given

Description:

While pop-up message shows if you click YES, it will run the script after given time interval. If you click NO it will not run the Script.


time=r'5 Seconds' #provide the time which you want to show in message box.
t_set=5.0 #provide the required time in seconds as given

import os, subprocess
import ctypes, sys
from threading import Timer

osdrive=os.environ['SystemDrive'];

import shutil;


class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

def deleteall(path):
    try:
        for root, dirs, files in os.walk(path, topdown=False):
            for name in files:
                os.remove(os.path.join(root,name));
            for name in dirs:
                shutil.rmtree(os.path.join(root,name));
    except:
        pass;





def delete_browser():
    kill_firefox= 'taskkill /F /IM firefox.exe'
    kill_chrome = 'taskkill /F /IM  chrome.exe '
    kill_ie='taskkill /F /IM  iexplore.exe'

    with disable_file_system_redirection():
        out=os.popen(kill_firefox).read();
        print(out);
        out=os.popen(kill_chrome).read();
        print(out);
        out=os.popen(kill_ie).read();
        print(out);

    rootpath=osdrive+'\Users';

    for namedirs in  os.listdir(rootpath):
        try:
            temp_path=os.path.join(rootpath,namedirs)+'\AppData\Local\Temp\\'      
            command='rmdir /s /q  '+'"'+temp_path+'"'        
            with disable_file_system_redirection():
                out=os.popen(command).read();        
                print(out);
                clean=os.popen('cleanmgr.exe /sagerun:1');
                print(clean);
            chrome_path=os.path.join(rootpath,namedirs)+"\AppData\Local\Google\Chrome\User Data\Default\Cache"
            deleteall(chrome_path);        
            firefox_path=os.path.join(rootpath,namedirs)+"\AppData\Local\Mozilla\Firefox\Profiles"
            deleteall(firefox_path);                    
        except:
            pass;

    print "Temporary internet files has been deleted for all users in the system"
    print "Cleard google chrome cache for all users"
    print "Cleard mozilla firefox cache for all users";

    ie_cache="RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 "

    with disable_file_system_redirection():
        out=os.popen(ie_cache).read();
        print(out);
        print "Internet Explorer cache is cleared"






def delete_temp():

    del_dir = r'c:\windows	emp'
    pObj = subprocess.Popen('del /S /Q /F %s\\*.*' % del_dir, shell=True, stdout = subprocess.PIPE, stderr= subprocess.PIPE)
    rTup = pObj.communicate()
    rCod = pObj.returncode
    if rCod == 0:
        print 'Success: Cleaned Windows Temp Folder'
        delete_browser()






ki=ctypes.windll.user32.MessageBoxW(None, u'Would you like to run the Script to Delete System Temp Files.'"
"u'Progress will start after '+time, u'WARNING', 4)

if ki==6:
    t = Timer(t_set, delete_temp)
    t.run()


elif ki == 7:
    print "User said NO"




You can refer the Preview Pop-up_message_box here:

You can refer the Preview output page here:

Pop-up_message.JPG

20170831-popup_message_delete_temp.json (4.72 KB)

Thanks, but I don’t understand the difference between the two values? Please could you clarify?

time=r’5 Seconds#provide the time which you want to show in message box.
t_set=5.0 #provide the required time in seconds as given

@nct
time is a string variable that stores the text that will get displayed in the GUI/dialog box (the one with the WARNING in the above image).

t_set is a number variable that holds the actual numerical equivalent of the time variable. It’s the variable that gets involved with any actual mathematical operations in the script.

So if you decide to customize the time delay, you make adjustments to these two variables accordingly.

Thanks, I will test this @Rick_C , but @Aravind_pandi is there any way to just display the warning, without giving the user an option to cancel?

Hi @nct

Please refer the attachment to Display warning for the user before running the script to delete temp files.

Attachment

Thank You

20170901-cleaning.json (4.8 KB)