By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Protecting files

P: n/a
Hi

Is there a way to protect system files, eg .ini files but still allow
access to them from C++ code?

As an example I have a settings file called SIMS.INI. This file is
often accessed through C++ using FILE and fstream. I do not want a
user to be able to open/edit/delete etc. this file.

Thanks

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
wallacej wrote:
Is there a way to protect system files, eg .ini files but still allow
access to them from C++ code?

As an example I have a settings file called SIMS.INI. This file is
often accessed through C++ using FILE and fstream. I do not want a
user to be able to open/edit/delete etc. this file.


Is there a C++ _language_ question here somewhere that I am not seeing?
Jul 23 '05 #2

P: n/a

"wallacej" <ja*************@yahoo.co.uk> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi

Is there a way to protect system files, eg .ini files but still allow
access to them from C++ code?

As an example I have a settings file called SIMS.INI. This file is
often accessed through C++ using FILE and fstream. I do not want a
user to be able to open/edit/delete etc. this file.

Thanks


You'd need to ask in a newsgroup for the platform (Windows), not here. File
permissions are platform-specific.

But... there are a couple options, at least. One would be to not use a text
file, but instead use a binary file, and encode the contents in some simple
manner so that it's not easily readable by your users. Another might be to
mark it as read-only (using whatever system API calls are available on
Windows), such that the user gets a "hint" that it shouldn't be touched.
That wouldn't stop them if they really wanted to, but it might help. Or,
you could hide your file in some Windows-specific directory, and give it a
name they would never associate with your application. Or any combination
of the above.

In any case, you need to ask in a windows newsgroup if you've got questions
specific to that operating system.

-Howard

Jul 23 '05 #3

P: n/a
wallacej wrote:

Hi

Is there a way to protect system files, eg .ini files but still allow
access to them from C++ code?

As an example I have a settings file called SIMS.INI. This file is
often accessed through C++ using FILE and fstream. I do not want a
user to be able to open/edit/delete etc. this file.


Then you should check what capabilities your operating system offers
to protect files.

Note: operating system, not C++

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #4

P: n/a
Cheers,

I thought that maybe there was some way to protect the file, un-protect
it for access and then re-protect it after; all within the C++
_language_ .

wallace

Jul 23 '05 #5

P: n/a
wallacej wrote:
Cheers,

I thought that maybe there was some way to protect the file, un-protect
it for access and then re-protect it after; all within the C++
_language_ .

wallace

Sorry, but the _standard_ C++ language only provides
a minimal interface for files. Protecting them, passwords,
and redirection are left for the operating system.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.