Q #1: How do I empty the recycle bin from within
AutoIt? Maybe a Rundll command?
---------------------------------------------------------------------
A #1: You can use an AutoIt script to
clear it from the desktop like this:
; ======= Scriptlet Starts Here
=======
WinMinimizeAll
leftclick,0,0
send, recy+{F10}
send, b{ENTER}
winwaitactive, Confirm
send, !y
WinMinimizeAllUndo
; ======= Scriptlet Ends Here
=======
It can be put in either an AutoIt
script file or compiled into an
EXE. If it's compiled. It
becomes a lot like number 4.
---------------------------------------------------------------------
A #2: You can use a 3rd party command such
as ERB. Found at:
http://hjem.get2net.dk/fec/software/erb/index.html
This command was specially written
to empty the recycle bin. It can
be run from say a network drive (t:)
from within AutoIt by using:
Run, %comspec% /c t:\\erb.exe /hide
It can also be run from the logon
script with the following command:
erb.exe /hide
---------------------------------------------------------------------
A #3: You can use Windows explorer and
AutoIt to do the job like this:
; ======= Scriptlet Starts Here
=======
Run,C:\\\\Windows\\\\Explorer.exe
\\\\Recycled
Send,!fb{ENTER}!fc
; ======= Scriptlet Ends Here
=======
---------------------------------------------------------------------
A #4: You can run a batch file (call it
say: "eraserb.bat") with the following
commands in it.
; ======= Batch File Starts Here
=======
C:
CD\RECYCLED
ATTRIB -h *.*
ATTRIB +h desktop.ini
ECHO Y | DEL *.* >> NUL:
; ======= Batch File Ends Here
=======
---------------------------------------------------------------------
A #5: You can use a single DOS internal
command like:
erase C:\recycled
or an external DOS command like:
deltree /y c:\recycled\
These commands can be run from
within AutoIt like this:
; ======= Scriptlet Starts Here =======
Run, %comspec% /c deltree /y
c:\\recycled\\
Run, %comspec% /c erase C:\\recycled
; ======= Scriptlet Ends Here
=======
---------------------------------------------------------------------
A #6: Some other suggestions can be found
on techrepublic.com in an article by
Bill Shadish (which is where I got
the batch file from). It states:
"You’ve probably heard the Paul
Simon song "Fifty Ways to Leave Your
Lover," which describes a number of tricks for breaking free from an
Undesired relationship. This article places a spin on the concepts used in
that song. No, I can’t guarantee that simply by reading this article youll
meet that special person. But This article will provide 40 ways to solve
some common disk-space problems under
Windows 9x and Windows NT.
Cleanup
You can use a small program to empty
the Recycle Bin (29) (its really just
A special directory on the root of the C drive). The C header code to do
So looks like this:
SHEmptyRecycleBin
SHSTDAPI SHEmptyRecycleBin(
HWND hwnd,
LPCTSTR pszRootPath,
DWORD dwFlags
);
However, you must install the
Explorer 4.0x extensions (such as channels)
To get the required version 4.71 of the Shell32.dll file to make the call.
I, for one, am not interested in installing tons (read that, megabytes) of
glut just to be able to delete files from one directory. So, lets look at
a batch file that does the same thing. Note that the recycle directory
contains two special, hidden files. Info maps the names of files in the
Recycle Bin to their original filenames; you should delete this file. The
shell uses Desktop.ini to recognize that the Recycle Bin is a special
folder; dont remove this file. (30) Place the following lines within a
batch file called, perhaps, Dump.bat:
C:
CD\RECYCLED
ATTRIB -h *.*
ATTRIB +h desktop.ini
ECHO Y | DEL *.* >> NUL:
You can now empty the Recycle Bin by
calling this file."
---------------------------------------------------------------------
A #7: One possible solution has not been
proven or necessarily shown to be
a solution as yet. But the comments have been included here for
completeness. It entails using the Rundll command and the
shell32.dll
function
"SHEmptyRecycleBin". the gist
is to use a command like:
rundll32 shell32, SHEmptyRecycleBin
---------------------------------------------------------------------
The function exists
"SHEmptyRecycleBinA",
Some examples of how to use it in a
Visual Basic program can be found
at:
http://support.microsoft.com/support/kb/articles/Q164/7/87.ASP
http://www.TheScarms.com/vbasic/rundll.asp
---------------------------------------------------------------------
I would assume that it can be done,
but getting the right parameters
and using them correctly is the key.
I call api functions to open
certain dialogs or perform other
functions with AutoIt. So more than
likely emptying the recycle bin through
an api call is possible. I
found an interesting website with a
ton of api functions along with
the parameters.
http://www.vbapi.com/ref/funca.html
---------------------------------------------------------------------
For the SHEmptyRecycleBin you need
at least Shell32 V.4.71, but I
have the 4.00 version and I can
empty the recycle bin, so I think
there is a way to do this, if you
create a folder and name it:
Recycle Bin {645FF040-5081-101B-9F08-00AA002F954E}
You'll got another recycle bin.
---------------------------------------------------------------------
Unfortunately, I don't think you can
do it with Rundll. The
SHEmptyRecycleBin function is in the
SHELL32.DLL file, but it doesn't
work with RunDll, because it needs a
Windows handle, unlike
SHExitWindowsEx, which just takes a
simple parameter.
---------------------------------------------------------------------
One avenue you may want to research
is Microsoft's MSDN site. I've
found this to be a great resource
for locating this type of thing.
After a quick search I was able to
find the following information:
The Windows API provides the ability
to perform a copy, move, rename,
or delete operations on a file
system object using the
SHFileOperation function that is
exported by Shell32.DLL.
---------------------------------------------------------------------
One other option, as a developer,
would be to lump the functions you
need into your own library (DLL or
OCX), and then call your own
functions.