Hi

Is there a way that I can copy locked file. For example ntuser.dat file that is locked by the OS, can that be copied to another location?

Thanks,

C K
Posted on 2009-07-13 02:02:43 by karthikeyanck
Yes you can do that. You have to use ShadowCopy though.

http://en.wikipedia.org/wiki/Shadow_Copy

There
Posted on 2009-07-13 07:00:08 by XCHG

Yes you can do that. You have to use ShadowCopy though.

http://en.wikipedia.org/wiki/Shadow_Copy

There


Are there any easy methods to achieve this through assembly? One of the methods that can be used is the MovefileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag set. But that requires a reboot

Edit: Added movefileex method.
Posted on 2009-07-13 08:05:35 by karthikeyanck
There is a free command line Shadow Copy application. If I were you, I would inject that into the bundle of my application and at run-time, export it to disk, run it with CreateProcess as a command line utility and don't let the user know what's happening on the background.
Posted on 2009-07-13 08:41:06 by XCHG

There is a free command line Shadow Copy application. If I were you, I would inject that into the bundle of my application and at run-time, export it to disk, run it with CreateProcess as a command line utility and don't let the user know what's happening on the background.


Sounds doable. Thanks XCHG
Posted on 2009-07-13 08:49:04 by karthikeyanck
Am still stuck with this, NTBACKUP (on Windows XP) doesn't seem to backup a single file through commandline. Am not sure if am missing out on something. All am doing is giving the EXE path "C:\Windows\System32\ntbackup.exe" and parameter "backup C:\Documents and Settings\Administrator\NTUSER.DAT /j "Command Line Backup 1" /f "C:\att.bfk"" .

But the same parameters work when I input a folder.
Posted on 2009-07-14 05:53:31 by karthikeyanck
The problem is the spaces in the filepath.
And the solution is self-evident.
Posted on 2009-07-14 08:20:34 by Homer
Thanks Homer, but I don't see that to be a problem. Windows will be able to handle that right?
Posted on 2009-07-14 09:54:52 by karthikeyanck

Thanks Homer, but I don't see that to be a problem. Windows will be able to handle that right?
Yes, if you quote the file paths - funnily you're quoting the short filepath but not the one with spaces? :)
Posted on 2009-07-14 10:16:05 by f0dder
Yeah. Try to always enclose your paths in quotation marks and try to avoid using backslash instead of forward slash.

In other words, use this:

"C:/Program Files/Adobe/"

Instead of:

C:\Program Files\Adobe\
Posted on 2009-07-14 10:52:00 by XCHG
Eh, why use forward slash instead of backward slash?

The only time it matters is when dealing with C-style escaped strings... where you just use a double-backslash. While the Windows APIs handle forward-slash properly, not all third-party software might, so it's best to use backslashes.
Posted on 2009-07-14 11:15:41 by f0dder

Eh, why use forward slash instead of backward slash?

The only time it matters is when dealing with C-style escaped strings... where you just use a double-backslash. While the Windows APIs handle forward-slash properly, not all third-party software might, so it's best to use backslashes.


Yeah, *NIX style expects C:/Program\ Files/Adobe/, where-as Windows would expect "C:\Program Files\Adobe\".

Forward slashes are still acceptable as path separators in Windows, but backslashes are expected in UNC forms on Windows, e.g. "\\myserver\files\".

Since UNC is not as flexible, it's advisable to stay consistent and just use backslashes.
Posted on 2009-07-14 12:57:24 by SpooK


Thanks Homer, but I don't see that to be a problem. Windows will be able to handle that right?
Yes, if you quote the file paths - funnily you're quoting the short filepath but not the one with spaces? :)


Ah, I've just forgot to include the closing quotes there!

This is what I understand;

Windows can recognize both backslash and forward slash when you use them in the path as C:\Windows and C:/Windows. Both are accepted format.

Then how about the switches/parameters? They are best identified when a forward slash is used against them. Ex when you use "dir /s" they work, try "dir \s"...

Thanks,

C K.
Posted on 2009-07-15 05:38:22 by karthikeyanck

Windows can recognize both backslash and forward slash when you use them in the path as C:\Windows and C:/Windows. Both are accepted format.

Then how about the switches/parameters? They are best identified when a forward slash is used against them. Ex when you use "dir /s" they work, try "dir \s"...
That's yet a reason not to use forward slashes for file paths - again, the APIs support them, but all kinds of 3rd party applications might break in all kinds of different ways.
Posted on 2009-07-15 09:02:57 by f0dder

That's yet a reason not to use forward slashes for file paths - again, the APIs support them, but all kinds of 3rd party applications might break in all kinds of different ways.


When in Rome Redmond...
Posted on 2009-07-15 18:49:04 by SpooK


That's yet a reason not to use forward slashes for file paths - again, the APIs support them, but all kinds of 3rd party applications might break in all kinds of different ways.


When in Rome Redmond...


hmmm, has anyone tried to take a backup of a single locked file using ntbackup (commandline)? The same syntax works when I take a backup of a folder, fails when I backup a file  :sad:

ntbackup backup C:\ /j "Commad Line Backup 1" /f C:\backup.bkf  --------> this works

ntbackup backup C:\test.txt /j "Command Line Backup 1" /f C:\backup.bkf ------> creates a empty 10K backup.bkf file
Posted on 2009-07-16 08:08:15 by karthikeyanck
Re: Copying locked files
Oh you are still on this?

Download Hobocopy, search for it in Google.

Then go here:

http://www.howtogeek.com/howto/windows-vista/backupcopy-files-that-are-in-use-or-locked-in-windows/

Follow the instructions. It tells you how to backup a single locked file.

Let me know if it works or not. Enable those 2 services which are described at the beginning of the article because I don't know if Hobocopy already enables them for you upon execution or not.
Posted on 2009-07-19 07:24:08 by XCHG
Re: Copying locked files
Are there no other workarounds to achieve this with the default M$ programs? I understand that hobocopy can be used to achieve this, but why not something that comes with default installation of M$ Windows?
Posted on 2009-07-21 08:11:49 by karthikeyanck
Re: Copying locked files
You could try to duplicate file handle from the target to your process, then just seek to the beginning and copy block by block. I have added this successfully as a plugin for ProcessExplorer, so I'm able to copy for example locked .flv (renamed to .tmp) files from youtube (hosted in IE).
Posted on 2009-07-21 08:53:51 by sapero
Re: Copying locked files
Ok if I understand this right, you mean to say to have a Duplicate handle created for this file....

The file which am trying to copy is the 'ntuser.dat' file that is locked by the 'system' process. Am unsure how do I get access to the handle of the 'ntuser.dat' file that's somewhere lying in the memory of the process - 'system'.....

Is my understanding right? or am way too far from the mission to be accomplished?

Thanks again for the inputs
Posted on 2009-07-22 04:20:02 by karthikeyanck