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
Solved

Setting file attributes

Posted on 2000-04-07
11
333 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

789 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