News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Delete temp files under Vista

Started by Magnum, November 30, 2010, 11:17:10 PM

Previous topic - Next topic

Magnum

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.
Have a great day,
                         Andy

dedndave

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

Magnum

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.

Have a great day,
                         Andy

dedndave

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

dedndave

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

brethren


redskull

Everyone has their own, in %TEMP%, (C:\Users\blah\blah\blah), which is where temp files are supposed to be going

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Magnum

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

Have a great day,
                         Andy

Magnum

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.

Have a great day,
                         Andy

Antariy

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?

dedndave

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

dedndave

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

Magnum

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.



Have a great day,
                         Andy

Antariy

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 :-)

Magnum

Have a great day,
                         Andy