The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => The Orphanage => Topic started by: Magnum on November 30, 2010, 11:17:10 PM

Title: Delete temp files under Vista
Post by: Magnum on November 30, 2010, 11:17:10 PM
I frequently work on other systems running Vista.

For security, I would like to delete the temp files in the windows\temp directory.

del /q c:\windows\temp\*.*

This batch doesn't work, even when run as an Admin.

I recall that Vista has 2 levels of admin. (Semi-admin and "for real admin")

If I can't do it via batch, I am game for writing a program to do the job.

What are your thoughts?

Thanks.
Title: Re: Delete temp files under Vista
Post by: dedndave on November 30, 2010, 11:38:50 PM
i suggest you write a program that deletes files individually, crawling throught any subfolders there may be
most of them will delete - a few are in use by programs
Title: Re: Delete temp files under Vista
Post by: Magnum on November 30, 2010, 11:47:28 PM
If I have to go that route, I will need to learn how to detect what files are in use.

They are no sub directories to deal with.

Title: Re: Delete temp files under Vista
Post by: dedndave on November 30, 2010, 11:48:49 PM
just delete all of them
if they are in use, it will return an error (access denied) - ignore the error and go on to the next one
when you try to do it with explorer, it stops at the first error - that's the issue
Title: Re: Delete temp files under Vista
Post by: dedndave on November 30, 2010, 11:55:47 PM
oh - subdirectories - there may not be all the time, but there can be
i have seen computers with ~ a hundred folders in the temp folder - all with files and subfolders - lol
a simple little recursive routine will crawl through there
Title: Re: Delete temp files under Vista
Post by: brethren on December 01, 2010, 12:05:23 AM
download crap cleaner (CCleaner :P)
http://www.piriform.com/
Title: Re: Delete temp files under Vista
Post by: redskull on December 01, 2010, 12:07:21 AM
Everyone has their own, in %TEMP%, (C:\Users\blah\blah\blah), which is where temp files are supposed to be going

-r
Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 12:18:49 AM
Looks like this has a lot of work already done.

I will study it and see where I would insert the code for removing attributes and file deletion.

I would want to delete *.tmp and *.log.

I have some 16  bit code that is a fast file finder, may study it too.

Time to learn some new stuff.

P.S.

Had an interview at Kroger.
They have a new drug test technique.
Swab your mouth.

Did the hair test b4 and the other method.

; -------------------------------------------------------------------------
; ffbe.asm (Find Files By Extension) by cobold
;
; Finds all files within in a path(recursively), including subdirectories
;
;   Usage: ffbe <path>
;
;           ffbe c:\
;
;                 to find all files with extension wcard1 on Drive C:
;                 (please set wcard1 in .data to the extension you need)
; -------------------------------------------------------------------------

include \masm32\include\masm32rt.inc

; -------------------------------------------------------------------------
; Prototypen
; -------------------------------------------------------------------------
Find_Dirs   PROTO
Find_Files  PROTO

; -------------------------------------------------------------------------
.data
    wcard       db  "*.*",0             ; wildcard for Find_Dirs
    wcard1      db  "*.tmp",0           ; wildcard for Find_Files
;--------------------- Set this to the extension you need, f.ex. *.exe
   
    szCL        db  MAX_PATH dup(0)     ; Kommandozeile
    szWrkDir    db  MAX_PATH dup(0)     ; the working directory
    szBack      dd  "..",0              ; to go back one directory
 
    cDir        dd  0                   ; number of directories searched
    cFil        dd  0                   ; number of files found
    cByt        dq  0                   ; Total bytes
   
    cfilsiz STRUCT
        fsl dd   ?
        fsh dd   ?
    cfilsiz ENDS
 
    cfs         cfilsiz <>

.code
start:
    call main
    inkey
    exit

; -------------------------------------------------------------------------
; Main
; -------------------------------------------------------------------------
main proc

; Get the path-argument from commandline, if none given currentdir is used
    invoke GetCL, 1, ADDR szCL
    .if eax == 1
        invoke SetCurrentDirectory, ADDR szCL
    .endif

    print "  Searching . . .",13,10 
    invoke Find_Dirs
 
    print chr$(13,10)
    print ustr$(cFil), " files found in "
    print ustr$(cDir), " directories, total "
    print uqword$(cByt)
    print " bytes",13,10,13,10
 
  ret
main endp

; -------------------------------------------------------------------------
; Find_Dirs: Verzeichnisse rekursiv durchlaufen
; -------------------------------------------------------------------------
align 4

Find_Dirs proc

    LOCAL   hSearch :DWORD
    LOCAL   wfd     :WIN32_FIND_DATA

align 4 
    invoke GetCurrentDirectory, MAX_PATH, ADDR szWrkDir
    invoke Find_Files
    invoke FindFirstFile, ADDR wcard, ADDR wfd
    .if eax != INVALID_HANDLE_VALUE
        mov hSearch, eax
    .else
        jmp Find_Next_Dir
    .endif
align 4
    .while eax != 0
        mov ebx, wfd.dwFileAttributes
        .if bx & FILE_ATTRIBUTE_DIRECTORY
            .if wfd.cFileName != "."
                add cDir,1
                invoke SetCurrentDirectory, ADDR wfd.cFileName
                .if eax == NULL
                    print "Error on SetCurrentDirectory "
                    print ADDR wfd.cFileName,13,10
                    jmp Find_Next_Dir
                .endif
                invoke Find_Dirs
            .endif
        .endif
Find_Next_Dir:       
        invoke FindNextFile, hSearch, ADDR wfd
    .endw
    invoke FindClose, hSearch
    .if eax == NULL
        print "Error on FindClose in Proc Find_Dirs "
        print ADDR szWrkDir
        exit
    .endif
align 4   
    invoke SetCurrentDirectory, ADDR szBack
    invoke GetCurrentDirectory, MAX_PATH, ADDR szWrkDir
    ret
Find_Dirs endp

; -------------------------------------------------------------------------
; Find_Files: Find all files with extension wcard1 in current directory
; -------------------------------------------------------------------------
align 4

Find_Files proc

    LOCAL   hSearch :DWORD
    LOCAL   wfd     :WIN32_FIND_DATA
   
    invoke FindFirstFile, ADDR wcard1, ADDR wfd
    .if eax != INVALID_HANDLE_VALUE
        mov hSearch, eax
    .else
        jmp Find_Exit
    .endif
    .while eax != 0
        mov ebx, wfd.dwFileAttributes
        .if !(bx & FILE_ATTRIBUTE_DIRECTORY)
            print ADDR szWrkDir,"\"
            print ADDR wfd.cFileName,13,10
            add cFil, 1
            mov ebx, wfd.nFileSizeLow
            mov cfs.fsl, ebx
            mov ebx, wfd.nFileSizeHigh
            mov cfs.fsh, ebx
            fild cfs
            fild cByt
            fadd
            fistp cByt
        .endif
        invoke FindNextFile, hSearch, ADDR wfd
    .endw
    invoke FindClose, hSearch
    .if eax == NULL
        print "FindClose Error in "
        print ADDR szWrkDir,13,10
        exit
    .endif
Find_Exit:
    ret
Find_Files endp

end start

Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 12:22:57 AM
Quote from: brethren on December 01, 2010, 12:05:23 AM
download crap cleaner (CCleaner :P)
http://www.piriform.com/

This is a computer used by seniors.

I try to leave a small footprint.

Title: Re: Delete temp files under Vista
Post by: Antariy on December 01, 2010, 12:28:16 AM
Quote from: Magnum on November 30, 2010, 11:17:10 PM
I frequently work on other systems running Vista.

For security, I would like to delete the temp files in the windows\temp directory.

del /q c:\windows\temp\*.*

This batch doesn't work, even when run as an Admin.

Andy, something was printed on the the console screen? Why .BAT is not work? They should say the reason. It is access denied, or something else?
Title: Re: Delete temp files under Vista
Post by: dedndave on December 01, 2010, 12:32:31 AM
CCleaner is a pretty good program
note that, windows has a disk cleanuip utility built-in
but it is slower than the second coming
with CCleaner, you can selectively decide which files to delete
it does a great job of locating registry issues
although - i never automatically do anything to the registry
i like it, still, because i can right-click on an issue in the list, and it will open regedit to that key   :U

another thing about CCleaner - if you remove it - it uninstalls cleanly

as for the code above - yah - someone was playing with a find routine the other day
just stick a delete in there and you have it
Title: Re: Delete temp files under Vista
Post by: dedndave on December 01, 2010, 01:03:46 AM
if you still want to write your own, you might consider using SHFileOperation to delete files (under XP)
or IFileOperation (under Vista/Win7)
one advantage being that you can delete entire folders
also - if a folder has read-only child attributes, you can delete the files under it without messing with all the attributes
Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 01:13:32 AM
Quote from: Antariy on December 01, 2010, 12:28:16 AM
Quote from: Magnum on November 30, 2010, 11:17:10 PM
I frequently work on other systems running Vista.

For security, I would like to delete the temp files in the windows\temp directory.

del /q c:\windows\temp\*.*

This batch doesn't work, even when run as an Admin.

Andy, something was printed on the the console screen? Why .BAT is not work? They should say the reason. It is access denied, or something else?

I did not have time to figure out how to get to a cmd window under Vista.

I am so thankful, I have XP. :-)

When I go back Monday, I will know how.



Title: Re: Delete temp files under Vista
Post by: Antariy on December 01, 2010, 01:16:29 AM
Quote from: Magnum on December 01, 2010, 01:13:32 AM
Quote from: Antariy on December 01, 2010, 12:28:16 AM
Quote from: Magnum on November 30, 2010, 11:17:10 PM
I frequently work on other systems running Vista.

For security, I would like to delete the temp files in the windows\temp directory.

del /q c:\windows\temp\*.*

This batch doesn't work, even when run as an Admin.

Andy, something was printed on the the console screen? Why .BAT is not work? They should say the reason. It is access denied, or something else?

I did not have time to figure out how to get to a cmd window under Vista.

I am so thankful, I have XP. :-)

When I go back Monday, I will know how.

Well, no needed how you start console, only what it is printed when you tried to delete files.

I have XP, too :-)
Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 01:23:59 AM
It might be a UAC issue too.
Title: Re: Delete temp files under Vista
Post by: dedndave on December 01, 2010, 04:03:39 AM
that isn't likely for files in the temp folder
it is more likely they are in use
i know, for example, that sqlsrvr and a few others create temporary performance data files in there (perflibxxxx)
usually, they are deleted if the program that created them closes normally
Title: Re: Delete temp files under Vista
Post by: GregL on December 01, 2010, 04:48:19 AM
Magnum,

I don't think you should delete any files from the C:\Windows\Temp folder, unless you put them there and if you did you are putting them in the wrong place.  Like redskull said, you should be using %TEMP% (C:\Users\UserName\AppData\Local\Temp) for temporary files.  Vista and Seven (sounds like a drink) have special rules about where files can go, they won't like it if you are using C:\Windows\Temp, I wouldn't be surprised if you could not delete them even as admin, it is due to system security and permissions.


Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 04:55:59 AM
I am not putting any files there.

I just run apps from my USB on occasion as well as apps on the machine.

With Windows being notorious for leaving all kinds of temp files everywhere without doing any self-cleaning, I just want to know that I made a reasonable effort to not leave too many bread crumbs.

I'll see what's in those files before I do anything.

I sure would like to get rid of the ribbon bar or whatever they call it from Word 20**.

As Hutch would say, It's a pain in the arse.





Title: Re: Delete temp files under Vista
Post by: GregL on December 01, 2010, 05:11:44 AM
Quote from: MagnumI sure would like to get rid of the ribbon bar or whatever they call it from Word 20**.

Yeah, it sure is different, I have pretty much gotten used to it now.

Title: Re: Delete temp files under Vista
Post by: GregL on December 01, 2010, 05:17:22 AM
Magnum,

I just took a look at my C:\Windows\Temp folder, I had to have admin rights to just view it.  It looks to me like Windows itself is using it.  I wouldn't delete anything from there.
Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 07:56:41 AM
Thanks, you saved me a whole lot of work.

I will still see what's in them thar files.



Title: Re: Delete temp files under Vista
Post by: sinsi on December 01, 2010, 08:32:00 AM
That's %temp% for things like NT AUTHORITY\SYSTEM, NT AUTHORITY\NETWORK SERVICE and the like. Because it is a temp directory, there should be no worries about emptying it. There will be a few files in use and undeleteable though.
Title: Re: Delete temp files under Vista
Post by: Magnum on December 01, 2010, 12:15:24 PM
Quote from: sinsi on December 01, 2010, 08:32:00 AM
That's %temp% for things like NT AUTHORITY\SYSTEM, NT AUTHORITY\NETWORK SERVICE and the like. Because it is a temp directory, there should be no worries about emptying it. There will be a few files in use and undeleteable though.

Thanks.