Solved

Setting file attributes

Posted on 2000-04-07
11
340 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

737 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