1.    19 Jul 2007 #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.    20 Jul 2007 #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

  3.    20 Jul 2007 #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

  4.    20 Jul 2007 #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

  5.    22 Jul 2007 #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


Similar Threads
Thread Forum
Help deleting a .flv file please?
I have a file on my desktop called "YouTube - arabbab8_s Channel_5" It was a video "flv". It's 21.9 MB and I can't get it to delete. ...
General Discussion
Help With Deleting A File Please!
i downloaded the core temp file, and realized i already had another in Program Files. so i went about deleting the ones from the desktop, but there...
General Discussion
need help deleting a file?
I need to access webmail to get into my lotus notes account, I can get in, but I get an domino web access warning when I try to reply. I've...
Network & Sharing
deleting a file
i permanently deleted a file in shared folder of application (limewire) but now when put a search for it still appears in the search ,i again try...
Vista file management
Error when deleting file, file is in use
Hello, i'm a software developer and i installed Vista last week. I have the problem, that when i open a file, no matter what kind of file,...
Vista file management
Deleting file(s)
Vista Ultimate When deleting files, the only option I have is to permanently delete them, dialog asks: "Are you sure you want to permanently...
Vista file management
deleting file from desktop (*.exe)
I moved a 3dmark06.exe file onto my desktop by mistake, now it will not let me move it again or delete it. I have tried everything i know about...
Vista file management

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 20:58.
    .