Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Deleting a file in use

Closed Thread
 
Thread Tools Display Modes
Old 07-19-2007   #1 (permalink)
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
Old 07-20-2007   #2 (permalink)
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

Old 07-20-2007   #3 (permalink)
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
------------------------------------------------------

Old 07-20-2007   #4 (permalink)
Jason
Guest


 

Re: Deleting a file in use

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

http://ccollomb.free.fr/unlocker/



Cheers,
Jason


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

Old 07-22-2007   #5 (permalink)
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

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help deleting a file? bessiere Network & Internet 1 01-07-2008 01:10 PM
deleting a file gursaran abott Vista file management 3 10-31-2007 08:32 PM
Error when deleting file, file is in use Martin Weber Vista file management 3 07-17-2007 09:53 PM
Deleting file(s) MagneX Vista file management 0 05-11-2007 03:23 AM
deleting hibernation file chinga69 Vista General 7 09-28-2006 03:01 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50