Luke_Stephens
asked on
Setting file attributes
How do I set the attributes of a file to Full Access through VB?
Cheers.
Cheers.
ASKER
Cheers, but how do I use this then?
This is all you do:
SetAttr "TESTFILE", vbHidden ' Set hidden attribute.
SetAttr "TESTFILE", vbHidden + vbReadOnly ' Set hidden and read-only
' attributes.
SetAttr "TESTFILE", vbArchive
SetAttr "TESTFILE", vbHidden ' Set hidden attribute.
SetAttr "TESTFILE", vbHidden + vbReadOnly ' Set hidden and read-only
' attributes.
SetAttr "TESTFILE", vbArchive
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).
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).
ASKER
Sorry, it was NT permissions I was after.
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 :)
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 :)
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(FullFile Path, FileAttributes)
End Function
Public Function GetAttributes(ByVal FullFilePath as String) as Integer
GetAttributes = GetFileAttributes(FullFile Path)
End Function
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(FullFile
End Function
Public Function GetAttributes(ByVal FullFilePath as String) as Integer
GetAttributes = GetFileAttributes(FullFile
End Function
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.
I asked this before to confirm it.
Luke is not trying to control file "attributes" but rather "NT permissions" to a file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, it's about setting NT permissions.
My e-mail is lukes@sunuk.com
cheers mate.
My e-mail is lukes@sunuk.com
cheers mate.
ASKER
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.
Cheers mate, and Fibdev for giving it a go.
Set a reference to Microsoft Scripting Runtime (\system32\scrrun.dll)