Delete Temp Internet Files and Temp Files

Discussion in 'Scripting' started by Eric Eichenlaub, Jul 14, 2003.

  1. Hello,

    Has anyone created a script that will delete a Users Temporary Internet
    Files and Temp Files? I want a script that could be ran as a user logoff
    script in Active Directory to cleanup a users temp files upon logoff.

    Any help would be greatly appreciated.

    Thx
     
    Eric Eichenlaub, Jul 14, 2003
    #1
    1. Advertisements

  2. Eric Eichenlaub

    Robert Cohen Guest

    If you know where the temp internet files are stored, just use (obviously
    chnaging to the location of the temp files. I just don't know where they
    are stored.

    Const DeleteReadOnly = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile("C:\locationoftempfiles\*.tmp"), DeleteReadOnly
    --
    Sorry, I am no longer including my e-mail address as I am getting to much
    spam. I really have no desire to enlarge "it" by three inches, that is even
    if I get e-mailed 10 times a day from different e-mail addresses so I can't
    block it.
    Besides I finally came to believe what others have said, if you have a
    question, you should ask the group as others might benefit from it. Anyone
    on the group who I converse with off topic or on the side, can easily find
    my e-mail address.
     
    Robert Cohen, Jul 14, 2003
    #2
    1. Advertisements

  3. I tried this but it doesn't seem to work:

    Const DeleteReadOnly = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile("%USERPROFILE%\Local Settings\Temp\*.*"), DeleteReadOnly
    objFSO.DeleteFile("%USERPROFILE%\Local Settings\Temporary Internet
    Files\*.*"), DeleteReadOnly

    Any ideas? I know the script is runs but never seems to delete any files.
    The %USERPROFILE% variable should work.
     
    Eric Eichenlaub, Jul 14, 2003
    #3
  4. Eric Eichenlaub

    Robert Cohen Guest

    actually that doesn't work in vbs. try

    Dim wnet
    Set wnet=CreateObject("Wscript.Network")
    strUsername=wnet.username

    Const DeleteReadOnly = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile("c:\Documents and Settings\" & strUsername & "\Local
    Settings\Temp\*.*"), DeleteReadOnly
    objFSO.DeleteFile("c:\Documents and Settings\" & strUsername & "\Local
    Settings\Temporary Internet Files\*.*"), DeleteReadOnly
     
    Robert Cohen, Jul 14, 2003
    #4
  5. Hi,

    Also, the profile sometimes is stored under a variation of the username. For
    example, if there is a local user account with the same name, Windows will
    append the domain name to the user name when creating the profile folder on
    the local machine. To be safe you should retrieve the location from the
    registry. For example, this outputs the location of the Temporary Internet
    Files. I don't find a registry setting for the temp folder, so I also output
    the Local Settings folder (Temp is a sub folder):

    strKey1 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
    Folders\Cache"
    strKey2 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
    Folders\Local Settings"

    Set objShell = CreateObject("Wscript.Shell")
    Wscript.Echo "Cache: " & objShell.RegRead(strKey1)
    Wscript.Echo "Local Settings: " & objShell.RegRead(strKey2)

    On older clients (Win9x), the second registry key above does not exist, so
    an error is raised. It might be better to retrieve the environment variable
    "TEMP", as follows:

    Wscript.Echo "Temp: " & objShell.Environment("Process").Item("Temp")

    Depending on your client OS's, you may have to experiment with the best
    method to locate the folders.
     
    Richard Mueller [MVP], Jul 15, 2003
    #5
  6. Eric Eichenlaub

    Levent Guest

    I am using W2K3 Server with domain admin rights and I
    tried this script. It gave a "permission denied" error.
    Can you help me please ?
     
    Levent, Jul 15, 2003
    #6
  7. Eric Eichenlaub

    Robert Cohen Guest

    where did you try the script? Did you run it at the server or the
    workstation?

    --
    Sorry, I am no longer including my e-mail address as I am getting to much
    spam. I really have no desire to enlarge "it" by three inches, that is even
    if I get e-mailed 10 times a day from different e-mail addresses so I can't
    block it.
    Besides I finally came to believe what others have said, if you have a
    question, you should ask the group as others might benefit from it. Anyone
    on the group who I converse with off topic or on the side, can easily find
    my e-mail address.
     
    Robert Cohen, Jul 15, 2003
    #7
  8. Eric Eichenlaub

    Levent Guest

    I tried it on the W2K3 Server.
     
    Levent, Jul 16, 2003
    #8
  9. Eric Eichenlaub

    Robert Cohen Guest

    that script must be run locally, so if you have these files on the server
    you would use that, but you cannot run it from the server to delete them on
    the workstations. If that is what you are trying, you would need to use
    other methods. But if you are trying to run them on the workstation, you
    can have it run at the workstation through a logon script or such so that
    each workstation runs it individually.


    --
    Sorry, I am no longer including my e-mail address as I am getting to much
    spam. I really have no desire to enlarge "it" by three inches, that is even
    if I get e-mailed 10 times a day from different e-mail addresses so I can't
    block it.
    Besides I finally came to believe what others have said, if you have a
    question, you should ask the group as others might benefit from it. Anyone
    on the group who I converse with off topic or on the side, can easily find
    my e-mail address.
     
    Robert Cohen, Jul 16, 2003
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.