Re: SetAttr() Behaves differently under Vista

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



news-server.socal.rr.com <allen@xxxxxxxxxxxxxxxxx> wrote:
I'm trying to set a files attributes to NOT (Read Only) like so:

SetAttr sFile, GetAttr(sFile) And (Not vbReadOnly)

When the line above is called, I get a "Run-time error '5': Invalid
procedure call or argument"

GetAttr(sFile) = 8224
vbReadOnly = 1

The same run time error occurs if I simply call:

SetAttr sFile, GetAttr(sFile)

Is there some compatibilty issue I should know about between Vista and older
OS's?????

It's not just Vista. SetAttr just doesn't accept the higher-bit attributes. See
this post from 2003:

http://groups.google.com/group/microsoft.public.office.developer.vba/browse_thread/thread/f6a17d421f8af449/a52af5c17cb2fc94?lnk=st&q=&rnum=1#a52af5c17cb2fc94

In a nutshell, you need to use the API instead. Override the native SetAttr with
one of your own:

Private Declare Function SetFileAttributes Lib "kernel32" Alias
"SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As
Long

Public Function SetAttr(FileName As String, ByVal Attributes As Long) As Boolean
' Nothing fancy, just set new attribute and return
SetAttr = SetFileAttributes(FileName, Attributes)
End Function
--
..NET: It's About Trust!
http://vfred.mvps.org


.



Relevant Pages

  • Re: API function to remove Write Protection of a file
    ... >> existing ones that included the newer/higher attributes, SetAttr ... Run-time error '5': ... Also, popping into the Immediate window, this generates the same error: ...
    (microsoft.public.vb.winapi)
  • Re: Add methods to string objects.
    ... It's fascinating that the setattrworks (and I agree with you that it's a ... bad idea), but given that it does work, why doesn't it work with a string ... the time" is also a tricky proposition - string literals are made into ... setattr(object, name, value) ...
    (comp.lang.python)
  • Re: Interesting things of getattr and setattr
    ... getattr / setattr seems treat any string as attribute name. ... Feature. ...
    (comp.lang.python)
  • Interesting things of getattr and setattr
    ... I don't know it is a feature, ... getattr / setattr seems treat any string as attribute name. ...
    (comp.lang.python)