Solved

Setting file attributes

Posted on 2000-04-07
11
336 Views
Last Modified: 2010-05-02
How do I set the attributes of a file to Full Access through VB?

Cheers.
0
Comment
Question by:Luke_Stephens
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2692799
You can use the FileSystemObject from the MS Scripting library
Set a reference to Microsoft Scripting Runtime (\system32\scrrun.dll)
0
 

Author Comment

by:Luke_Stephens
ID: 2692819
Cheers, but how do I use this then?
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2692834
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:fibdev
ID: 2692838
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
 

Author Comment

by:Luke_Stephens
ID: 2692855
Sorry, it was NT permissions I was after.
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2694675
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
 
LVL 1

Expert Comment

by:adam8
ID: 2709975
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
 
LVL 3

Expert Comment

by:fibdev
ID: 2711358
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
 
LVL 2

Accepted Solution

by:
corvanderlinden earned 50 total points
ID: 2715002
If it's about NT Security I could send you a sample VB project if you give me your email address
0
 

Author Comment

by:Luke_Stephens
ID: 2715014
Yeah, it's about setting NT permissions.  

My e-mail is  lukes@sunuk.com

cheers mate.
0
 

Author Comment

by:Luke_Stephens
ID: 2715146
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

679 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