Solved

Lock an ini file

Posted on 2002-03-06
12
1,371 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 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