Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
June 20, 2013, 05:33:12 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Locked files  (Read 8187 times)
auser
JkDefrag Junior
**
Posts: 7


View Profile
« on: December 21, 2007, 09:58:56 am »

Hi,

I am trying to write some code which copies a locked file. the system registry to be exact.
Does someone have some experience with that?

Thanks
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7156



View Profile WWW
« Reply #1 on: December 21, 2007, 07:06:56 pm »

I am trying to write some code which copies a locked file. the system registry to be exact.
Does someone have some experience with that?
If all else fails you can access the raw disk and copy the file from there. You can find out where exactly on disk a file is with the FSCTL_GET_RETRIEVAL_POINTERS system call. Opening a handle to a raw disk is easy:

VolumeHandle = CreateFile("C:", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

For finding out where a file is on disk see the GetFragments() subroutine in the JkDefragLib.cpp source. I don't have an example for reading the file into memory, but take a look at the "Read the boot block from the disk" section in the AnalyzeNtfsVolume() subroutine in the ScanNtfs.cpp sources.
Logged
auser
JkDefrag Junior
**
Posts: 7


View Profile
« Reply #2 on: December 21, 2007, 08:54:14 pm »

hmmm  Roll Eyes
Logged
cf
JkDefrag Hero
*****
Posts: 65



View Profile WWW
« Reply #3 on: December 22, 2007, 12:03:43 pm »

You might first try the FILE_FLAG_BACKUP_SEMANTICS flag for CreateFile.

According to the MSDN, this flag does the following:
Quote from: MSDN
The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges in a Token.
I think the "override of security checks" means that you can open it even when it is locked. So you should be able to read all the data and save it to another file.
Logged

Try JkDefragStarter - the smallest GUI for JkDefrag out there
Tihs txet suhlod be dfgaeegrd!
auser
JkDefrag Junior
**
Posts: 7


View Profile
« Reply #4 on: December 22, 2007, 01:09:43 pm »

You might first try the FILE_FLAG_BACKUP_SEMANTICS flag for CreateFile.

According to the MSDN, this flag does the following:
Quote from: MSDN
The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges in a Token.
I think the "override of security checks" means that you can open it even when it is locked. So you should be able to read all the data and save it to another file.

Thank you both. Maybe just for the challenge of it you'd want to try copying the file "C:\WINDOWS\system32\config\system" ( xp )

Let me know if you are successful.

For your information I have done the following so far:
got the SE_BACKUP_NAME privilege. according to GetLastError success.
But CreateFile fails with GENERIC_READ flag set. no matter what the other flags are. no read or write access is possible.

Thanks
Logged
Morne44gell
Newbie
*
Posts: 1



View Profile
« Reply #5 on: February 26, 2011, 06:53:41 am »

You might first try the FILE_FLAG_BACKUP_SEMANTICS flag for CreateFile.

According to the MSDN, this flag does the following:
Quote from: MSDN
The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges in a Token.
I think the "override of security checks" means that you can open it even when it is locked. So you should be able to read all the data and save it to another file.

Got error while Creating File "INVALID_HANDLE_VALUE" failure, if I return it then same error occurs , can you explain how to avoid this error?
Logged

Fit is the most important aspect of swimming goggles.Most common  and effective lens “color” is clear.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!