Solved

Lock an ini file

Posted on 2002-03-06
12
1,254 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
  • 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now