Jump to content

SetFileAttributes DLL Help?


Recommended Posts

I am still struggling with DLLs that have constant parameters. Currently, I find I need to change a directory (specified by user input so it is no longer Read-Only.

The Win32 API info which I found for that follows. I have tried this:

$FILE_ATTRIBUTE_DIRECTORY = 0x10
$FILE_ATTRIBUTE_HIDDEN = 0x2
$FILE_ATTRIBUTE_READONLY = 0x1
$filename = InputBox("","Enter file name:")
$SetFileAttributes = 0x2f8
$dll = DllOpen("kernel32.dll")
MsgBox(0,"","$dll = " & $dll)
$result = DllCall("kernel32.dll","int", $SetFileAttributes,"str",$filename,"int",$FILE_ATTRIBUTE_READONLY)
MsgBox(0,"","$result = " & $result)
DllClose($dll)

When I run that, the file/folder remains unchanged. Can a helpful DLL guru (well, really anybody) assist me with this? I couldn't locate any examples with constant parameters, and i don't quite get it yet.

Thanks, if you can. I have worked up a headache over this. TIA

vatobeto.

SetFileAttributes

The SetFileAttributes function sets the attributes for a file or directory.

BOOL SetFileAttributes(

LPCTSTR lpFileName,

DWORD dwFileAttributes

);

Parameters

lpFileName

[in] Pointer to a string that specifies the name of the file whose attributes are to be set.

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters,

call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.

dwFileAttributes

[in] File attributes to set for the file. This parameter can be one or more of the following values. However, all other values

override FILE_ATTRIBUTE_NORMAL.

Attribute Meaning

FILE_ATTRIBUTE_ARCHIVE A file or directory that is an archive file or a directory .Applications

Use this attribute to mark files for backup or removal.

FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary

Directory listing.

FILE_ATTRIBUTE_NORMAL A file or directory that does not have other attributes set. This

attribute is valid only when used alone.

FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file or directory is not be indexed by the

content indexing service.

FILE_ATTRIBUTE_OFFLINE The data of a file or directory is not available immediately. This

Attribute indicates that the file data is physically moved to offline

storage. This attribute is used by Remote Storage, which is the

hierarchical storage management software. Applications should not

arbitrarily change this attribute.

FILE_ATTRIBUTE_READONLY A file or directory that is read-only. For a file, applications

can read the file, but cannot write to it or delete it. For a directory,

applications cannot delete it.

FILE_ATTRIBUTE_SYSTEM A file or directory that the operating system uses a part of, or uses

exclusively.

FILE_ATTRIBUTE_TEMPORARY A file or directory that is being used for temporary storage.

File systems avoid writing data back to mass storage if sufficient

cache memory is available, because typically, an application

deletes a temporary file after the handle is closed. In that scenario,

the system can entirely avoid writing the data. Otherwise, the data

is written after the handle is closed.

FILE_ATTRIBUTE_VIRTUAL A file is a virtual file.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Edited by vatobeto
Link to comment
Share on other sites

thats normal, by default folders are readonly

Right - knew that. But, does that make it impossible to delete folders with AutoIt? I did see the following line in the FileDelete help:

Some file attributes can make the deletion impossible.

Inquiring minds need to know... :)

vatobeto.

Link to comment
Share on other sites

check out "DirRemove" in the help file, yes, you can remove folders with autoIt, and check for if successful or not.

Edited by Rick

Who needs puzzles when we have AutoIt!!

Link to comment
Share on other sites

Right - knew that. But, does that make it impossible to delete folders with AutoIt? I did see the following line in the FileDelete help:

Inquiring minds need to know... :)

vatobeto.

Oh...hello!

I know - RTFM. Or at least read the whole page you're currently viewing!

Last line of FileDelete help:

Related

FileCopy, FileMove, FileRecycle, DirRemove

DirRemove was what was needed all along. Newbies are such a pain - huh?

Mea maxima culpa - vatobeto.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...