Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Protect files.

Status
Not open for further replies.

WilliamGS

Programmer
Jan 21, 2004
54
PE
Dear friends, I need to protect a group of files against modifications, these files must be only for read; but in some conditions (that I know) these files must be replaced or deleted. Somebody knows some function to protect and unprotect files? These files are in a server and are used by many users. I am using Visual C++ 6.0.

Thank you.
 
use SetFileSecurity

Ion Filipski
1c.bmp
 
_A_RDONLY

Is an attriube that should mark the folder as read only. It is part of the WIN32_FIND_DATA or _finddata_t structure and is one of the attribue flags if you set the flag that should mark the file as read only. I suggest doing a search on msdn.com. Hopefully that will help you. The following is some code from msdn.com. It only demonstrates a little about the data structure but i think you will see you are looking to fiugre out exactly how that structure works.

/* FFIND.C: This program uses the 32-bit _find functions to print
* a list of all files (and their attributes) with a .C extension
* in the current directory.
*/

#include <stdio.h>
#include <io.h>
#include <time.h>

void main( void )
{
struct _finddata_t c_file;
long hFile;

/* Find first .c file in current directory */
if( (hFile = _findfirst( &quot;*.c&quot;, &c_file )) == -1L )
printf( &quot;No *.c files in current directory!\n&quot; );
else
{
printf( &quot;Listing of .c files\n\n&quot; );
printf( &quot;\nRDO HID SYS ARC FILE DATE %25c SIZE\n&quot;, ' ' );
printf( &quot;--- --- --- --- ---- ---- %25c ----\n&quot;, ' ' );
printf( ( c_file.attrib & _A_RDONLY ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_SYSTEM ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_HIDDEN ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_ARCH ) ? &quot; Y &quot; : &quot; N &quot; );
printf( &quot; %-12s %.24s %9ld\n&quot;,
c_file.name, ctime( &( c_file.time_write ) ), c_file.size );

/* Find the rest of the .c files */
while( _findnext( hFile, &c_file ) == 0 )
{
printf( ( c_file.attrib & _A_RDONLY ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_SYSTEM ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_HIDDEN ) ? &quot; Y &quot; : &quot; N &quot; );
printf( ( c_file.attrib & _A_ARCH ) ? &quot; Y &quot; : &quot; N &quot; );
printf( &quot; %-12s %.24s %9ld\n&quot;,
c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
}

_findclose( hFile );
}
}


Output

Listing of .c files

RDO HID SYS ARC FILE DATE SIZE
--- --- --- --- ---- ---- ----
N N N Y CWAIT.C Tue Jun 01 04:07:26 1993 1611
N N N Y SPRINTF.C Thu May 27 04:59:18 1993 617
N N N Y CABS.C Thu May 27 04:58:46 1993 359
N N N Y BEGTHRD.C Tue Jun 01 04:00:48 1993 3726
 
>TalosBlack
set as readonly is to prevent accidentaly change, not to deny changes. So onyone can change readonly by clearing readonly flag. But to deny changes you should change the security.

Ion Filipski
1c.bmp
 
Thank you TalosBlack, but the read only attribute is not safe, it is easy to change with Windows Explorer and DOS command ATTRIB, I need some more safe, without posibilities to change neither user nor network administrator.

William G.S.
 
use SetFileSecurity


Ion Filipski
1c.bmp
 
Thank you IonFilipski, I'm studying SetFileSecurity.
 
SetFileSecurity is very good, but works only in Win NT/2000/XP and NTFS file system, I need work in Win 98 and FAT 32 files system, too. Some advice?

Thank you.
 
I dont think you should expect any fancy security functionality in OS:es where you can log in as previous user by pressing Esc.


/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
WilliamGS, you can not have good security under fat/fat32/win9x.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top