Solved

Lock an ini file

Posted on 2002-03-06
12
1,332 Views
Last Modified: 2008-03-10
I want to lock an INI file, so that only my program can write to it.
How can I do this, and still be able to use the GetPrivateProfileString API functions?
0
Comment
Question by:MakeItWork614
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
12 Comments
 
LVL 12

Accepted Solution

by:
pjknibbs earned 100 total points
ID: 6846611
You can't. There isn't any way to lock a particular file so only a particular program can use it--the best you can do is make the file read-only, then use code to make the file writable before performing any updates to it.

If you're using an OS with the NTFS file system you can set permissions on a file so only certain USERS can access it, but even then someone with administrative rights on the machine could come in and change the file's owner.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6846763
You could encrypt the file.  Then before reading it, you could decrypt it, access its data, then encrypt it again.

Of course the user could still delete it or make meaningless (random) changes to it, but maybe just preventing the user from making 'intelligent' changes might accomplish your goal.

-- Dan
0
 
LVL 11

Expert Comment

by:griessh
ID: 6955284
Dear MakeItWork614

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "pjknibbs"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MakeItWork614
ID: 6968561
griessh,
I object.
I feel that just because pjknibbs doesn't know of a way to do this, doesn't mean there isn't a method capable of doing it.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6970317
MakeItWork614

Thanks for your feedback. Maybe DanRollins (he also commented on this question) steps in here and tells us his opinion.
I have to fully agree with pjknibbs, there is no way to lock a file for a certain application. pjknibbs didn't say he doesn't know of a way, he said that there isn't any way to do it! Quite a difference.
BTW: as I said already, if the experts don't get any feedback, they won't come back with more comments ...

======
Werner
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6970534
There is one idea...
if your program is a service, or otherwise is always running, you could open the file, setting the sharing mode to
   CFile::shareDenyRead | CFile::shareDenyWrite
That would prevent any other programs from opening the file -- as long as your program is running.  As soon as your program quites, the O/S is likely to release all file locks that it held.

I know that is not a reasonable answer, but i mention it anyway because:

   There is no reasonable way to do what you want to do.

-- Dan
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6973505
Please update and finalize this.
Moondancer - EE Moderator
0
 

Author Comment

by:MakeItWork614
ID: 6973734
Moondancer,
My question is not ready to be finalized.
When I have worked through a satisfactory answer, I will finalize this question.

DanRollins,
I will give your method a try, and get back to you.

griessh,
>>he said that there isn't any way to do it!
Just because some saids that it can't be done, doesn't mean that it can't be done.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6973756
Thanks, makes total sense to me; sorry to rush you.  I just wanted to make sure you were aware of updates, since my Email notifs were delayed.
:) Moondancer - EE Moderator
0
 
LVL 11

Expert Comment

by:griessh
ID: 6974025
MakeItWork614

I don't know how many people you need to tell you: It can't be done!

I'm glad that Dan's suggestion gives you at least a hint how to do what you want to accomplish, but that changes the question a bit ...

======
Werner
0
 

Author Comment

by:MakeItWork614
ID: 6976878
Moondancer,
Could you please split the points between pjknibbs and DanRollins?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6977807
MakeItWork614 ->  Absolutely, happy to do this.  Thank you, points have been split.

Points for DanRollins -> http://www.experts-exchange.com/jsp/qShow.jsp?qid=20294982

Moondancer - EE Moderator
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question