WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Files and Directories

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Disable Offline Attribute


Question:

Any thoughts how to disable\enable the offline caching off a share?? wntShareInfo() doesn't show this item

Answer:

There doesn't seem to be any build in WinBatch function. Here is some UNDEBUGGED code, that will get and set that attribute.



#DefineFunction UDF_GetFileAttributes(filename)
	;DWORD GetFileAttributes(
	;  LPCTSTR lpFileName
	;);
	
	;1     FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. 
	;                              In the case of a directory, applications cannot delete it. 
	;2     FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing. 
	;4     FILE_ATTRIBUTE_SYSTEM The file or directory is part of, or is used exclusively by, the operating system. 
	;16    FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory. 
	;32    FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file or directory. Applications use this attribute to mark files 
	;                             for backup or removal. 
	;64    FILE_ATTRIBUTE_DEVICE Reserved; do not use. 
	;128   FILE_ATTRIBUTE_NORMAL The file or directory has no other attributes set. This attribute is valid only if used alone. 
	;256   FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems avoid writing data back to mass storage 
	;                               if sufficient cache memory is available, because often the application deletes the temporary file 
	;                               shortly after the handle is closed. In that case, the system can entirely avoid writing the data. 
	;                               Otherwise, the data will be written after the handle is closed. 
	;512   FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file. 
	;1024  FILE_ATTRIBUTE_REPARSE_POINT The file or directory has an associated reparse point. 
	;2048  FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file 
	;                                is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. 
	;4096  FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. This attribute indicates that the file data has 
	;                             been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical 
	;                             storage management software. Applications should not arbitrarily change this attribute. 
	;8192  FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file will not be indexed by the content indexing service. 
	;16384 FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data streams in the file 
	;                               are encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories. 
	;
	
	dll = StrCat(Dirwindows(1),"kernel32.dll")
	ret = DllCall(dll,long:"GetFileAttributesA",lpstr:filename)
	if ret == 0
		 Message("UDF_GetFileAttributes Error",DllLastError())
		 exit
	endif
	return(ret)
#EndFunction

#DefineFunction UDF_SetFileAttributes(filename, attr)
;	BOOL SetFileAttributes(
;  LPCTSTR lpFileName,
;  DWORD dwFileAttributes
;);

	
	;1     FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. 
	;                              In the case of a directory, applications cannot delete it. 
	;2     FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing. 
	;4     FILE_ATTRIBUTE_SYSTEM The file or directory is part of, or is used exclusively by, the operating system. 
	;16    FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory. 
	;32    FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file or directory. Applications use this attribute to mark files 
	;                             for backup or removal. 
	;64    FILE_ATTRIBUTE_DEVICE Reserved; do not use. 
	;128   FILE_ATTRIBUTE_NORMAL The file or directory has no other attributes set. This attribute is valid only if used alone. 
	;256   FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems avoid writing data back to mass storage 
	;                               if sufficient cache memory is available, because often the application deletes the temporary file 
	;                               shortly after the handle is closed. In that case, the system can entirely avoid writing the data. 
	;                               Otherwise, the data will be written after the handle is closed. 
	;512   FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file. 
	;1024  FILE_ATTRIBUTE_REPARSE_POINT The file or directory has an associated reparse point. 
	;2048  FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file 
	;                                is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. 
	;4096  FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. This attribute indicates that the file data has 
	;                             been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical 
	;                             storage management software. Applications should not arbitrarily change this attribute. 
	;8192  FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file will not be indexed by the content indexing service. 
	;16384 FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data streams in the file 
	;                               are encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories. 
	;
	
	dll = StrCat(Dirwindows(1),"kernel32.dll")
	ret = DllCall(dll,long:"SetFileAttributesA",lpstr:filename, long:attr)
	if ret == 0
		 Message("UDF_SetFileAttributes Error",DllLastError())
		 exit
	endif
	return(ret)
#EndFunction

path = "c:\temp"
rslt = UDF_GetFileAttributes(path)
if rslt & 1 then message(path,"READONLY")
if rslt & 2 then message(path,"HIDDEN")
if rslt & 4 then message(path,"SYSTEM")
if rslt & 16 then message(path,"DIRECTORY")
if rslt & 32 then message(path,"ARCHIVE")
if rslt & 64 then message(path,"DEVICE")
if rslt & 128 then message(path,"NORMAL")
if rslt & 256 then message(path,"TEMPORARY")
if rslt & 512 then message(path,"SPARSE_FILE")
if rslt & 1024 then message(path,"REPARSE_POINT")
if rslt & 2048 then message(path,"COMPRESSED")
if rslt & 4096 then message(path,"OFFLINE")
if rslt & 8192 then message(path,"NOT_CONTENT_INDEXED")
if rslt & 16384 then message(path,"ENCRYPTED")

if rslt & 4096 ;if offline
	 UDF_SetFileAttributes(path, rslt&4096)
endif





Article ID:   W16248
File Created: 2004:03:30:15:43:34
Last Updated: 2004:03:30:15:43:34