?
Solved

Setting file attributes

Posted on 2000-04-07
11
Medium Priority
?
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

765 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