Solved

Protect a file from being deleted

Posted on 2014-11-16
10
86 Views
Last Modified: 2014-11-17
How can i create a file and make it where it cannot be deleted
Like windows does with a message
"access denied" ?
file is created like this:
Public Sub SaveTextFile(sFileName As String, txt As String)
        Dim ff As Integer
        ff = FreeFile
       Open sFileName For Output As #ff
            Print #ff, txt
         Close #ff
     
End Sub

Open in new window

0
Comment
Question by:isnoend2001
  • 5
  • 4
10 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You can make a file read-only via code but that won't prevent someone from going to Widows Explorer and changing that. IMO your best bet is to hide it, but even then it can be found and deleted.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
What happens if the file is deleted?
0
 

Author Comment

by:isnoend2001
Comment Utility
The file is encrypted and reads:
"Not Registered" or
"refunded" or
"yes Registered"
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I would put the encrypted value in the Registry where it's less prone to erasure rather than a file and in either case if not found I'd assume that the app is "Not Registered".
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks Martin, I thought writing to the registry was a problem when Vista came out,No ?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
I don't really know but see this EE solution. If I were you I would create a small new project just to try it out and if you need more help I guess you'll need to ask a new question because I use XP.
0
 

Author Closing Comment

by:isnoend2001
Comment Utility
Thanks Martin
I Also use xp, but have another computer with win7 just for testing.
Using the registry is too complicated and error prone
i have though o a few work arounds  that turn into dead ends
1. open the file when the app closes, but don't close the file. This may keep a reference to the file, not sure, but the next time the computer starts it will no longer work.
2. determine if there is any way to write a value to the resource file
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
OK if you have other questions concerning your 1 and 2, ask a new question and I or others will try to help
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
"Using the registry is too complicated and error prone" - are you serious? It is less error prone than using a file, and not at all complicated once you have set it up correctly. Just three or four lines of code required.

On the other hand, accepting http:#a40446489 seems to be off, if you can't use the suggestion.
0
 

Author Comment

by:isnoend2001
Comment Utility
I agree the registry was easy until vista
the  http:#a40446489 answer provided a link for info that reinforced what i thought
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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