Well, this sounds like a pretty simple question. But I just can’t seem to get the Permissions to work properly under windows (Win2k3 Server, WinXP, WinNT, etc), such that I can secure a LOG file from the user. I'm testing this on Win2k3 server at this time, but it actually needs to work on WinXP computers that are connected to a WinNT server (on a NT domain).
Basically, I have written a mess of calls to an audit function within my program that opens up a log file for append access. You know something like this (though I have tried a few other ways (TextStream etc…)):
Open FFN For Append As #1
Print #1, stEventLine
Close #1
Then during installation I log on as the administrator and create the log file (FFN). I then try to set the privileges under WinXP to allow the “Users” group to only have append privileges to that file. However, I get the strangest, unexplainable, weird, reaction to any changes to the privileges. When I set it for append only I still got an access error when trying to append to the log file.
Stranger still, when I set the “Users” to deny read access for some reason the Administrator also got read access denied. All sorts of other strange stuff happened, but that isn’t important for this question. I’m just interested in Append for now.
I also created a separate group and tried to set its privileges rather then using the “Users” group, but that had the same results. I also set the directory privileges as well as the files privileges but I still got the access error when trying to append (as a user).
I have also messed around with inheritance. Turning it on and turning it off. What seemed to work best was to set the folder permissions first and while doing that check the checkbox that says to “Replace permissions on all child objects”, and to also turn off inheritance. But nothing I do allows for append only. I always get an permission denied error when I try anything while logged in as a user.
Basically, I just need some advice on how to set up the privileges on a log file so that some set of users (either the “Users” group or some other group) has only append access (they can have read access as well, but not delete or write—this is to say that I want to allow users to append to the file but not change existing data or delete existing data). Also, I need to know how to write the code to append to that file (is it just a simple open for append like above)?
by: EnladePosted on 2003-08-19 at 15:46:43ID: 9184494
Here is some test source code for you, so you don't have to write your own. Just create a form that has the three buttons and also add the Microsoft Scripting Runtime Reference. I've tried some other ways to as well, but there are two different ways to append in this little example code.
Option Explicit
Private Sub AppendToFile(ByVal file, ByVal towrite)
Dim fso, ofile
'FAILURE HERE
Set fso = CreateObject("Scripting.Fi
'OR FAILURE HERE
Set ofile = fso.OpenTextFile(file, 8, True)
Randomize
ofile.Write towrite
ofile.Close
Set ofile = Nothing
Set fso = Nothing
End Sub
Private Sub cmdAppend1_Click()
Open "C:\TLog\a.txt" For Append As #1
Print #1, "Append1 Data"
Close #1
End Sub
Private Sub cmdAppend2_Click()
AppendToFile "C:\TLog\a.txt", "Append2 Data" & vbCrLf
End Sub
Private Sub cmdWrite_Click()
Open "C:\TLog\a.txt" For Output As #1
Print #1, "Create Log File"
Close #1
End Sub