Please comment before I post into UDF forum...

Code:

;
;Function:
; fnCompress()
;
;Author:
; Christopher Shilt (christopher.shilt@relizon.com)
;
;Version:
; 1.0 (May 10, 2004)
;
;Version History:
;
;Action:
; Uses WMI to Compress/Uncompress NTFS files or directories.
;
;Syntax:
; fnCompress(TARGET, Optional UNCOMPRESS, Optional COMPUTER)
;
;Parameters:
; TARGET : Required. Target file or directory.
;
; UNCOMPRESS : Optional. Switch used to uncompress a compressed NTFS file/directory.
;
; COMPUTER : Optional. Local or Remote WMI enabled target computer.
;
;Remarks:
;

;Returns:
;
; Compress/Uncompress Method Return Value Table:
;
; Return Code Description
; ----------- ------------------------------
; 0 Success
; 2 Access denied
; 8 Unspecified failure
; 9 Invalid object
; 10 Object already exists
; 11 File system not NTFS
; 12 Invalid Operating System
; 13 Drive not the same
; 14 Directory not empty
; 15 Sharing violation
; 16 Invalid start file
; 17 Privilege not held
; 21 Invalid parameter
;
; Sets the value of @ERROR based on success/failure.
;
; Return Code Description
; ----------- ------------------------------
; 0 Success
; 1 See the Return Value Table above
; 2 System cannot file the file/directory
; ? Unspecified error creating WMI object
;
;Dependencies:
; WMI Enabled target computer.
;
;Example:
;
; ; == Compress a local file =============
; $rc = fnCompress("C:\temp\status.log")
; @ERROR " | " @SERROR ?
;
; ; == Compress a local directory ========
; $rc = fnCompress("C:\temp")
; @ERROR " | " @SERROR ?
;
; ; == Uncompress a local file ===========
; $rc = fnCompress("C:\temp\status.log",1)
; @ERROR " | " @SERROR ?
;
; ; == Uncompress a remote directory =====
; $rc = fnCompress("C:\temp",1,"MyTestPC")
; @ERROR " | " @SERROR ?
;
;
Function fnCompress($sTarget,Optional $bUncompress,Optional $sComputer)
Dim $objWMI,$colTarget
$sTarget = Join(Split($sTarget,"\"),"\\")
If Not $sComputer $sComputer=@WKSTA EndIf
$objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
$colTarget = $objWMI.ExecQuery("Select * from CIM_Logicalfile where name = '" + $sTarget + "'")
If $colTarget.Count = 0 Exit(2) EndIf
For Each $sTarget in $colTarget
If $bUncompress
$fnCompress = $sTarget.Uncompress
Else
$fnCompress = $sTarget.Compress
EndIf
Next
If $fnCompress > 0 Exit(1) EndIf
EndFunction



Edited by Chris S. (2004-05-10 06:27 PM)