Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

Setting file attributes

How do I set the attributes of a file to Full Access through VB?

Cheers.
0
Luke_Stephens
Asked:
Luke_Stephens
  • 4
  • 4
  • 2
  • +1
1 Solution
 
corvanderlindenCommented:
You can use the FileSystemObject from the MS Scripting library
Set a reference to Microsoft Scripting Runtime (\system32\scrrun.dll)
0
 
Luke_StephensAuthor Commented:
Cheers, but how do I use this then?
0
 
fibdevCommented:
This is all you do:

SetAttr "TESTFILE", vbHidden      ' Set hidden attribute.
SetAttr "TESTFILE", vbHidden + vbReadOnly      ' Set hidden and read-only
      ' attributes.

SetAttr "TESTFILE", vbArchive
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
fibdevCommented:
To use SetAttr you don't need to reference any library files.  After posting this I realized this might not be what you were asking.

Is this question about NT file permissions or file attributes?

If this question is just about attributes then:

SetAttr "filename", vbArchive

will allow you to have full control over the file if it has been set to read-only and/or hidden by another proccess.  If this is the case, you should set the attribute(s) back with the SetAttr function after you are done working with the file(s).
0
 
Luke_StephensAuthor Commented:
Sorry, it was NT permissions I was after.
0
 
fibdevCommented:
Good luck,

I don't know how to do what you are asking.  I question the ability to do this as it would be a security risk for NT.  Not to say it isn't possible  :)
0
 
adam8Commented:
this sets and gets file attributes..
THE CODE

FILE_ATTRIBUTE_ARCHIVE = &H20
FILE_ATTRIBUTE_COMPRESSED = &H800
FILE_ATTRIBUTE_DIRECTORY = &H10
FILE_ATTRIBUTE_HIDDEN = &H2
FILE_ATTRIBUTE_NORMAL = &H80
FILE_ATTRIBUTE_READONLY = &H1
FILE_ATTRIBUTE_SYSTEM = &H4


Public Function SetAttributes(ByVal FullFilePath As String, Optional ByVal FileAttributes As Long = &H20) As Long


    'makes sure that the file path is not to

    '     o long

    FullFilePath = Left(FullFilePath, 255)
    SetAttributes = SetFileAttributes(FullFilePath, FileAttributes)
End Function




Public Function GetAttributes(ByVal FullFilePath as String) as Integer


    GetAttributes = GetFileAttributes(FullFilePath)
End Function
0
 
fibdevCommented:
Just to clarify here ...

I asked this before to confirm it.

Luke is not trying to control file "attributes" but rather "NT permissions" to a file.
0
 
corvanderlindenCommented:
If it's about NT Security I could send you a sample VB project if you give me your email address
0
 
Luke_StephensAuthor Commented:
Yeah, it's about setting NT permissions.  

My e-mail is  lukes@sunuk.com

cheers mate.
0
 
Luke_StephensAuthor Commented:
Just what I was after, even though it's a serious load of code to wade through!

Cheers mate, and Fibdev for giving it a go.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now