Windows Vista Forums

Deleting a file in use

  1. #1


    Ashish Guest

    Deleting a file in use

    Is there any way in powershell to delete a file which is in use?
    I tried move and delete and that didnt work.. Am looking at something in Win
    API like MOVEFILE_DELAY_UNTIL_REBOOT

      My System SpecsSystem Spec

  2.   


  3. #2


    RichS Guest

    RE: Deleting a file in use

    If the file is locked open you won't be able to delete it from PowerShell
    during that session
    --
    Richard Siddaway
    Please note that all scripts are supplied "as is" and with no warranty
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "Ashish" wrote:

    > Is there any way in powershell to delete a file which is in use?
    > I tried move and delete and that didnt work.. Am looking at something in Win
    > API like MOVEFILE_DELAY_UNTIL_REBOOT


      My System SpecsSystem Spec

  4. #3


    Jason Guest

    Re: Deleting a file in use

    Hi Ashish:

    > Is there any way in powershell to delete a file which is in use?


    You probably already know about it, but you might be interested in this
    tool:
    http://www.microsoft.com/technet/sys...pendmoves.mspx


    Cheers,
    Jason


    ------------------------------------------------------
    PowerShell Training at SANS Conferences
    http://www.WindowsPowerShellTraining.com
    ------------------------------------------------------


      My System SpecsSystem Spec

  5. #4


    Jason Guest

    Re: Deleting a file in use

    Oh, and this too, there was a thread on this earlier in this group:

    http://********.free.fr/unlocker/



    Cheers,
    Jason


    ------------------------------------------------------
    PowerShell Training at SANS Conferences
    http://www.WindowsPowerShellTraining.com
    ------------------------------------------------------


      My System SpecsSystem Spec

  6. #5


    Ashish Guest

    RE: Deleting a file in use

    i created a Pinvoke code which calls MoveFileEx API for the same...seems like
    it isnt happy taking values of long type. any ideas what may have gone wrong?


    $domain = [AppDomain]::CurrentDomain
    $name = New-Object Reflection.AssemblyName 'TestAssembly'
    $assembly = $domain.DefineDynamicAssembly($name, 'Run')
    $module = $assembly.DefineDynamicModule('TestModule')
    $type = $module.DefineType('TestType')


    [Type[]]$parameterTypes = [string], [string], [int64]
    $method = $type.DefineMethod("MoveFileeX", 'Public,Static,PinvokeImpl',
    [bool], $parameterTypes)

    $ctor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([string])
    $attr = New-Object Reflection.Emit.CustomAttributeBuilder $ctor, 'kernel32'
    $method.SetCustomAttribute($attr)


    $realType = $type.CreateType()
    [object[]]$args = [string]'F:\\dll\\abc.dll', [string]$null, [int64]4
    $realType.InvokeMember('MoveFileeX', 'Public,Static,InvokeMethod',
    $null,$null, $args)

    "RichS" wrote:

    > If the file is locked open you won't be able to delete it from PowerShell
    > during that session
    > --
    > Richard Siddaway
    > Please note that all scripts are supplied "as is" and with no warranty
    > Blog: http://richardsiddaway.spaces.live.com/
    > PowerShell User Group: http://www.get-psuguk.org.uk
    >
    >
    > "Ashish" wrote:
    >
    > > Is there any way in powershell to delete a file which is in use?
    > > I tried move and delete and that didnt work.. Am looking at something in Win
    > > API like MOVEFILE_DELAY_UNTIL_REBOOT


      My System SpecsSystem Spec


Deleting a file in use
Similar Threads
Thread Forum
Help deleting a .flv file please? General Discussion
Solved Help With Deleting A File Please! General Discussion
deleting a file Vista file management
Error when deleting file, file is in use Vista file management
Deleting file(s) Vista file management