Page 1 of 1 1
Topic Options
#119279 - 2004-05-10 03:02 PM RFC: fnCompress - Compress/Uncompress NTFS files
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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)

Top
#119280 - 2004-05-10 06:30 PM Re: RFC: fnCompress - Compress/Uncompress NTFS files
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Minor modification to the script to use CIM_Logicalfile, which works with either files or directories. Had problems with GetFileAttr() while running against remote computers.

This has been tested against remote and local computers now.

Top
#119281 - 2004-05-11 09:56 PM Re: RFC: fnCompress - Compress/Uncompress NTFS files
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
If there are no comments I will post this to the UDF forum tomorrow morning (check local listings).
Top
#119282 - 2004-05-14 11:43 AM Re: RFC: fnCompress - Compress/Uncompress NTFS files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
checked local listing, didn't see

anyways:
Quote:

Uses WMI to Compress/Uncompress NTFS files or directories.




ok, that is fine.
I think it's more like:
Uses WMI to set the NTFS Compression flag.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1635 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.126 seconds in which 0.099 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org