Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Kill or .deletefile

Status
Not open for further replies.

SiberBob

Programmer
Aug 28, 2002
107
0
0
US
I need to write VBA Code to delete some files that are have security permissions set for administrators and specific users. I need to be able to write either a KILL sub or a .DeleteFile sub that will only delete those files for the current user [environ("Username")]...

Any suggestions?

Here is what I have so far but it won't work because there are files secured by multiple users...

Code:
    With New FileSystemObject
        .DeleteFile ("C:\MHP\TEMP\R5_*.TXT")
    End With
 
Code:
Dim fs As FileSystemObject

Set fs = New FileSystemObject
With fs
  .DeleteFile ("C:\MHP\TEMP\R5_*.TXT")
End With
Set fs = Nothing

You are correct in that it will only work if the current user has permissions to delete these files and also has modify permission on the folder itself (as deleting a file causes the folder to be modified). Checking this from VBA, however, is a bit more tricky than actually deleting the files themselves.

John
 
Thanks for the clarification on the code I have so far.

I still need to figure out how to determine what user has privileges to delete which files... If I can find out how to read the username that has rights to a file, should be able to run through only those files the current user has rights to and remove just them...
 
Are these files specifically secured using NTFS permissions such that some user accounts won't have permissions to delete the files?

Is there a pattern to their name that would let you work out which users will have filenames accessible to them (eg their login ID in the filename?)

John
 
You could try a delete and capture the error.
 
I have a list of userids for all users (actually that information is in one of my tables).

All users have the same rights to only delete files they created.

On a Windows XP Pro system, our network admins have set the policies to restrict read / write / delete and such... Users can read other users files, but can not edit / delete them.

I'm not sure if network admins used the NTFS Permissions you speak of.
 
I wonder if I could just for/next loop through each file in the folder and see if the attrib settings for that file are set to currently allow delete? that would tell me if each file can be deleted by the current user...
 
SiberBob

If your users can delete only their files, if you start deleting everything and ignore the errors your user deletes its files. Just make sure that the rule has no exceptions!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top