rvdmast
(Fresh Scripter)
2004-01-20 11:05 PM
Recycle bin sample script

; Recycle bin sample script uses a COM object to work
; with the recycle bin.
; Requires BinManager.dll to be installed on the system,
; see http://www.cheztabor.com/binmanager/

Dim $bin, $items, $size

$bin = CreateObject("BinManager.RecycleBin")
$items = $bin.NumItems
$size = $bin.Size

? "RecycleBin contains " $items " items " $size " bytes"
; Permanently delete items recycled more than two days ago.
; Note, the argument is full calendar days, so specifying
; zero would delete all items older than today.
$Returnvalue = $bin.DeleteOldItems(2)
; This permanently deletes all recycled items.
$Returnvalue = $bin.Empty()


Sealeopard
(KiX Master)
2004-01-20 11:37 PM
Re: Recycle bin sample script

No need for COM DLLs as this could be done via pure KiXtart (optionally with WMI COM).

LonkeroAdministrator
(KiX Master Guru)
2004-01-20 11:46 PM
Re: Recycle bin sample script

I knew I had code for this.
I didn't find my COM code but here is my simple version:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB1&Number=26421


rvdmast
(Fresh Scripter)
2004-01-21 12:11 AM
Re: Recycle bin sample script

Really? dont recall reading about the recycle bin in the KiX doc's. Could you give an example?
I'm not too good at WMI either...


rvdmast
(Fresh Scripter)
2004-01-21 12:13 AM
Re: Recycle bin sample script

btw what has Lonkero's link have to do with this?

Sealeopard
(KiX Master)
2004-01-21 03:01 AM
Re: Recycle bin sample script

Why should the KiXtart documentation contain anything about the 'Recycle bin'? The 'Recycle Bin' is just a redirection from the RECYCLER subfolder that exists on the root directory of local drives, e.g. C:\RECYCLER. The RECYCLER subfolder contains numerous subfolder with the user's SID containing the user's deleted files. One can thus enumerate the folders/files via Kixtart and/or WMI/WSH and selectively delete them. However, two file sneed to preserved, namely 'desktop.ini' and the catalog file 'INFO2'.

This would also work but I beleive it will throw a prompt:
Code:

$sh = CreateObject("Shell.Application")
$fi = $sh.NameSpace(&h000a)
if $fi.items.count
$fi.ParentFolder.ParseName('::{645FF040-5081-101B-9F08-00AA002F954E}').InvokeVerb('Empty Recycle &Bin')
end if


See also http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/scrguide/sas_fil_higv.asp

Using a custom DLL requires this DLL to be distributed to all computers and installed under admin privs.


rvdmast
(Fresh Scripter)
2004-01-21 09:45 PM
Re: Recycle bin sample script

Quote:

However, two file sneed to preserved, namely 'desktop.ini' and the catalog file 'INFO2'.



Wich exactly why i didnt want to simply delete all files in the recycler folder, thereby possibly corrupting the recycle bin's functionality. Plus, i'd have to check for and delete the files on each logical drive.
But thx for that little script sample, i'll look into that.
As said i'm not much into WMI scripts (yet)


LonkeroAdministrator
(KiX Master Guru)
2004-01-21 09:57 PM
Re: Recycle bin sample script

well, gladly there is no WMI scripts in this thread yet.

Sealeopard
(KiX Master)
2004-01-21 11:07 PM
Re: Recycle bin sample script

WMI is just one option to solve the underlying problem of removing files from the RECYCLER subfolders. However, AFAIK, there's now WMI way to control the Recycle Bin.

masken
(MM club member)
2006-02-16 10:16 AM
Re: Recycle bin sample script

Rooting up an old thread, but how would one easily PUT items in the script executioners recycle bin (instead of hard deleting)? Ie, "delete to recycle bin"?

NTDOCAdministrator
(KiX Master)
2006-02-16 06:21 PM
Re: Recycle bin sample script

Well I replied in your Suggestions post too, but I'd like a KiXtart NATIVE way to deal with the Recycle Bin as well and not just delete to Recycle Bin.

Using other methods that require installation of a DLL are possible but cumbersome, which is why most of us use KiXtart in the first place as it makes all these tasks so much easier to do.


Les
(KiX Master)
2006-02-16 06:55 PM
Re: Recycle bin sample script

Can this VBA snippet be converted?
http://www.cpearson.com/excel/Recycle.htm


Radimus
(KiX Supporter)
2006-02-16 06:57 PM
Re: Recycle bin sample script

or this... I can't remember if kix support "InvokeVerb"

Option Explicit
Dim oWinShell, oSHFolder, oSHFItems, oSHFItem
Dim Start
msgbox "Go..."
start = csng(timer)
Set oWinShell = CreateObject("Shell.Application")
Set oSHFolder = oWinShell.Namespace("C:\")


Set oSHFItems = oSHFolder.Items
Set oSHFItem = oSHFItems.Item("temp.txt")
oSHFItem.InvokeVerb("&Delete")


Set oWinShell = Nothing
Set oSHFolder = Nothing
Set oSHFItems = Nothing
Set oSHFItem = Nothing
msgbox csng(timer) - start


--


NTDOCAdministrator
(KiX Master)
2006-02-16 06:58 PM
Re: Recycle bin sample script

Not directly with KiXtart but maybe a shell to VB script which then shells the API call.

I'm sure Ruud could implement something which is the point of recent discussion I suppose, unless Masken is wanting something a bit sooner in which case that may be a great link for him Les.


Why does the Recycle Bin have different file system names on FAT and NTFS?
http://blogs.msdn.com/oldnewthing/archive/2006/01/31/520225.aspx

Don't forget that KiXtart would also need to be aware of such programs as Norton Protected Recycle Bin and act accordingly.


NTDOCAdministrator
(KiX Master)
2006-02-16 07:01 PM
Re: Recycle bin sample script

Similar code that Jens posted a while back. Unless I'm mistaken here I don't think Masken was wanting or looking for a method to do it right now so much as I think he wanted an EASY way with a built-in command or function from KiXtart.

But if that's not the case and he is looking for immediate answer then I suppose all these work-arounds might be of immediate value for him.


Les
(KiX Master)
2006-02-16 07:01 PM
Re: Recycle bin sample script

The FileAction() UDF will send to recyle bin but it prompts first.
Break On

$sFile="C:\test.txt"

$=FileAction($sFile,"Delete")
@ERROR " | " @SERROR ?

Get $


Les
(KiX Master)
2006-02-16 07:05 PM
Re: Recycle bin sample script

Oh, and FileAction() proves that InvokeVerb does in fact work in KiX.

LonkeroAdministrator
(KiX Master Guru)
2006-02-16 08:51 PM
Re: Recycle bin sample script

yes it does

Les
(KiX Master)
2006-02-16 10:15 PM
Re: Recycle bin sample script

Only prob, Jooel's version doesn't work, I need to use Chris' version.

LonkeroAdministrator
(KiX Master Guru)
2006-02-16 10:36 PM
Re: Recycle bin sample script

lol.
no, only problem is, xp sp2 doesn't work with my udf.
there is no problem in the udf


masken
(MM club member)
2006-02-17 10:34 AM
Re: Recycle bin sample script

yeah, working with DLL's and calling other script languages isn't really KiX:ing, is it?

This seems like an elementary function that really should be supported natively if you ask me...

@NTDOC, I don't think the system needs to be aware of the Norton thing, if so, every application written for win would need to be aware of different AV-functions. I think it works on another level?


LonkeroAdministrator
(KiX Master Guru)
2006-02-17 11:39 AM
Re: Recycle bin sample script

k, lets get the facts straight a little bit.
starting from binmanager.
that dll is nothing more but shell object wrapper and thus totally unneeded for this.

and what comes to recygle bin being something a scripting language should support natively.
eh, lets start by someone showing a scripting language that already does.

recycle bin is a gui undo helper for helpless end-users.
so why would any scripter want to say, "hey, I'm helpless and don't know wtf I'm doing, please give me undo!"
and, "please do place the files in the recycle bin, so my end users can also see that I do write scripts but I have no idea what I'm doing, so they can laught at me."

it just doesn't make any sense.


masken
(MM club member)
2006-02-17 03:14 PM
Re: Recycle bin sample script

You can't just generalize like that m8... for me, a function like this natively makes ALOT of sense. It all depends on what you're doing with the script. And since KiX is more of a general sysadmin processor than a login script processor, it makes even more sense.

Let's say you have a script that empties a folder with any given interval. Maybe one would want backup for that.

Let's say you've got a KiXform application which has delete-functionality in it.

Let's say an end-user has been assigned a script by a sysadmin with a del-function in it.

Lot's of usability.


LonkeroAdministrator
(KiX Master Guru)
2006-02-17 03:23 PM
Re: Recycle bin sample script

you saying that you would like to have your recycle bin act as backup folder?

come on man.


masken
(MM club member)
2006-02-17 04:17 PM
Re: Recycle bin sample script

well that's it's sole purpose and why it's there in the first place, so yes.