Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Lock an ini file

Posted on 2002-03-06
12
Medium Priority
?
1,396 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

715 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