none
Delete files to Recycle Bin via VBS and/or WMI

    Question

  • Hello,

    I'd like to create a script that deletes a file into the Recycle Bin (without the confirmation dialog). I wonder if that's possible through WMI or VBS. I couldn't find anything on the net. I'm thinking in VBS (in contrast to PowerShell) to be compatible with arbitrary XP+ machines.

    Any suggestion would be much appreciated.

    Thanks,
    Levente.

    Wednesday, March 14, 2012 11:29 PM

Answers

All replies

  • Have you tried batch files? 

    del /?

    del *.txt /S /Q


    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool
    AD User Creation tool

    Wednesday, March 14, 2012 11:40 PM
    Moderator
  • Hello,

    I'd like to create a script that deletes a file into the Recycle Bin (without the confirmation dialog). I wonder if that's possible through WMI or VBS. I couldn't find anything on the net. I'm thinking in VBS (in contrast to PowerShell) to be compatible with arbitrary XP+ machines.

    Any suggestion would be much appreciated.

    Thanks,
    Levente.

    The recycle bin is an arm of Explorer.  Scripts and batch files cannot delete to the recycle bin.

    I am not suere but Shell.Application might be able to do this as it is also an arm of Explorer.


    ¯\_(ツ)_/¯

    Thursday, March 15, 2012 12:05 AM
  • Yes - shell.application FolderItem.InvofkeVerb 'delete' will delete to the recycle bin.

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb787810(v=vs.85).aspx

    The MSDN site has numerous vbscript examples of how to use the shell.application object.


    ¯\_(ツ)_/¯

    Thursday, March 15, 2012 12:13 AM
  • Hello,

    I'd like to create a script that deletes a file into the Recycle Bin (without the confirmation dialog). I wonder if that's possible through WMI or VBS. I couldn't find anything on the net. I'm thinking in VBS (in contrast to PowerShell) to be compatible with arbitrary XP+ machines.

    Any suggestion would be much appreciated.

    Thanks,
    Levente.

    The recycle bin is an arm of Explorer.  Scripts and batch files cannot delete to the recycle bin.

    I am not suere but Shell.Application might be able to do this as it is also an arm of Explorer.


    ¯\_(ツ)_/¯

    Hrm, I never even thought about that.  Then again, I haven't checked my recycle bin in years.  I typically make sure I want the files gone before I delete them.  And I also rebuild my system about once a month, so it never fills up.  Ahh, the joys of unattended OS installs, scripted software installs, and a NAS.

    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool
    AD User Creation tool

    Thursday, March 15, 2012 12:34 AM
    Moderator
  • Hi,

    As was noted, the recycle bin is a feature of the Windows Explorer shell and you can invoke the "delete" verb. However, this is not robust as the verb required is language-specific.

    Bill

    Thursday, March 15, 2012 3:07 AM
    Moderator
  • Hi,

    As was noted, the recycle bin is a feature of the Windows Explorer shell and you can invoke the "delete" verb. However, this is not robust as the verb required is language-specific.

    Bill

    Bill - yes but...

    There is no other way to do this via scripting.  We can use the API from a compiled program but not from script.


    ¯\_(ツ)_/¯

    Thursday, March 15, 2012 3:36 AM
  • Correct, that is the only way via native scripting. This is why I don't recommend it -- because it is language-specific.

    Bill

    Thursday, March 15, 2012 8:19 PM
    Moderator
  • abqBill:

    Robust is great, so if I were put in the position where I didn't know my script's "audience", I'd probably setup an external (community serverbased) lookup table for the appropriate verb for a likely subset of localizations settings, and if the setting returned from a localization query doesn't match any key entries in the table, I'd be half-tempted to prompt for the proper verb, and add the location key and proper verb to said table so it can grow in situ.

    Either that, or perhaps there is some means of drilling down into a particular context menu and pulling the members out for comparison?

    Might not be  the pinnacle of code writing, but I loathe "can't", it immediately puts me in "oh yeah?, wanna bet?" mode...

    Paraphrased, I see the box as a place to think both inside and outside.  :)

    DAS

    Friday, March 16, 2012 2:12 PM
  • You're welcome to do that, of course, if you think it's worth the engineering effort.

    I'd rather write an external executable that performs the appropriate API call and call that from my script.

    To each his own, I guess :)

    Bill

    Friday, March 16, 2012 2:24 PM
    Moderator
  • I tend to take the leap of faith that if someone is looking for scripting help either they don't have the inclination, the means, or the knowledge to actually write an exe.

    I could be wrong, its happened numerous times> :)

    DAS

    Friday, March 16, 2012 2:42 PM