File with permission
-
Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.
Proud To Be an India
Do you mean a simple text file written through VC++ / C++ code ? If this is your requirement then try
_chmod, _wchmod
. Regards, Paresh. -
Do you mean a simple text file written through VC++ / C++ code ? If this is your requirement then try
_chmod, _wchmod
. Regards, Paresh. -
Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.
Proud To Be an India
Hi, Check with SetFileAttribute(...) Api. It will Help You.
Uday kiran
-
I have a program running under USER mode - and later i have to create a file in administrator mode - setting the privilages and all... Hope u got my requirement now..
Proud To Be an Indian
Try using API
SetFileSecurity
. Regards, Paresh. -
Try using API
SetFileSecurity
. Regards, Paresh.Try also using
SetNamedSecurityInfo
. Regards, Paresh. -
Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.
Proud To Be an India
I was having the same issue. When the ini file was created by someone in the administrators group, the file was only accessible by others in the administrators group. 'Normal' users were denied permission. So I changed the fourth parameter in the CreateFile() function call to be: m_hFile = CreateFile(..., ..., ..., GetSAForEveryone(), ..., 0, 0); SECURITY_ATTRIBUTES* GetSAForEveryone() { static SECURITY_ATTRIBUTES SA; static SECURITY_DESCRIPTOR SD; static bool FirstTime(true); if (FirstTime) { SD.Revision = SECURITY_DESCRIPTOR_REVISION; SD.Sbz1 = 0; // reserved SD.Control = SE_DACL_PRESENT; SD.Owner = 0; SD.Group = 0; SD.Sacl = 0; SD.Dacl = 0; // This grants access to everyone SA.nLength = sizeof(SECURITY_ATTRIBUTES); SA.bInheritHandle = false; SA.lpSecurityDescriptor = &SD; FirstTime = false; } return &SA; } This works great. The file is created so that everyone on the machine can read/write/delete/copy/move it. However, the next hurdle you will face is that if a user in the administrators group copies/moves the file to another folder, the file is again not accessible by all users. To get around this issue I found a page (http://support.microsoft.com/kb/310316) that addresses the issue. The bottom line is that I set the registry entry mentioned in that article for each user that creates the file. This may not be an acceptable solution in your case but it works for me.
-
I was having the same issue. When the ini file was created by someone in the administrators group, the file was only accessible by others in the administrators group. 'Normal' users were denied permission. So I changed the fourth parameter in the CreateFile() function call to be: m_hFile = CreateFile(..., ..., ..., GetSAForEveryone(), ..., 0, 0); SECURITY_ATTRIBUTES* GetSAForEveryone() { static SECURITY_ATTRIBUTES SA; static SECURITY_DESCRIPTOR SD; static bool FirstTime(true); if (FirstTime) { SD.Revision = SECURITY_DESCRIPTOR_REVISION; SD.Sbz1 = 0; // reserved SD.Control = SE_DACL_PRESENT; SD.Owner = 0; SD.Group = 0; SD.Sacl = 0; SD.Dacl = 0; // This grants access to everyone SA.nLength = sizeof(SECURITY_ATTRIBUTES); SA.bInheritHandle = false; SA.lpSecurityDescriptor = &SD; FirstTime = false; } return &SA; } This works great. The file is created so that everyone on the machine can read/write/delete/copy/move it. However, the next hurdle you will face is that if a user in the administrators group copies/moves the file to another folder, the file is again not accessible by all users. To get around this issue I found a page (http://support.microsoft.com/kb/310316) that addresses the issue. The bottom line is that I set the registry entry mentioned in that article for each user that creates the file. This may not be an acceptable solution in your case but it works for me.
skornel . .. MY actual requirement is - i have a file, that is having "R" only permision for users... its some thing like a log file. THe program has to be RUN in USER MODE(Restricted permission). But in betweeen i have to switch to admin mode to make some chnges in that file. Iam trying to use cacl - a windows command to change file permission
Proud To Be an Indian