kjcdude Posted July 25, 2009 Share Posted July 25, 2009 (edited) I'm very new to DllCall so this code may look pretty novice. I'm trying to set the "Compress contents to save disk space" attribute on a file. Whenever i run the script it fails to complete and displays no error. $dFile = "C:\Program Files\Steam\steamapps\astropop deluxe content.ncf" $callid = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'hwnd', $dFile, 'dword', "FSCTL_SET_COMPRESSION", 'ptr', "COMPRESSION_FORMAT_NONE", "dword", DllStructGetSize("COMPRESSION_FORMAT_NONE"), "ptr", "NULL", "dword", "0", "dword*", "NULL") if @error Then MsgBox(0, "", @error) MsgBox(0, "", $callid) MSDN - http://msdn.microsoft.com/en-us/library/aa364592%28VS.85%29.aspx Thanks Edited July 25, 2009 by kjcdude Link to comment Share on other sites More sharing options...
Malkey Posted July 25, 2009 Share Posted July 25, 2009 I'm very new to DllCall so this code may look pretty novice. I'm trying to set the "Compress contents to save disk space" attribute on a file. Whenever i run the script it fails to complete and displays no error. $dFile = "C:\Program Files\Steam\steamapps\astropop deluxe content.ncf" $callid = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'hwnd', $dFile, 'dword', "FSCTL_SET_COMPRESSION", 'ptr', "COMPRESSION_FORMAT_NONE", "dword", DllStructGetSize("COMPRESSION_FORMAT_NONE"), "ptr", "NULL", "dword", "0", "dword*", "NULL") if @error Then MsgBox(0, "", @error) MsgBox(0, "", $callid) MSDN - http://msdn.microsoft.com/en-us/library/aa364592%28VS.85%29.aspx Thanks Next time, please search these forums using the export function before posting. The export function you should have searched on is 'DeviceIoControl'. Link to comment Share on other sites More sharing options...
kjcdude Posted July 25, 2009 Author Share Posted July 25, 2009 Next time, please search these forums using the export function before posting. The export function you should have searched on is 'DeviceIoControl'.I did, that's how i got to where i am. Link to comment Share on other sites More sharing options...
Malkey Posted July 26, 2009 Share Posted July 26, 2009 I did, that's how i got to where i am. This was a bit more complicated than I had first assumed. Try this. Run the script to add Compression attribute to the file. Run the script again to remove the compression attribute. expandcollapse popup; #include <WinAPI.au3> ;References ; http://www.autoitscript.com/forum/index.php?showtopic=87441&view=findpost&p=627588 ; http://msdn.microsoft.com/en-us/library/cc232042(PROT.13).aspx ; http://msdn.microsoft.com/en-us/library/aa364592(VS.85).aspx #cs BOOL DeviceIoControl( (HANDLE) hDevice, // handle to file or directory FSCTL_SET_COMPRESSION, // dwIoControlCode (LPVOID) lpInBuffer, // input buffer (DWORD) nInBufferSize, // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); #ce Global Const $FSCTL_GET_COMPRESSION = 0x0009003C ; Dec = 589884 Global Const $FSCTL_SET_COMPRESSION = 0x0009C040 ; Dec = 639040 Local $dFile = @ScriptDir & "\temp-2.au3" Local $hFile = _WinAPI_CreateFile($dFile, 2, 6, 6) ; Handle to file, open, access & share = r/w Local $tInput = DllStructCreate("byte[4]") ; Toggles compress attribute If StringInStr(FileGetAttrib($dFile), "C") = 0 Then ; Check if file is already compressed DllStructSetData($tInput, 1, 0x0002) ; If not compressed compress Else DllStructSetData($tInput, 1, 0x0000); Remove compress attribute EndIf $callid = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _ 'hwnd', $hFile, _ 'int', $FSCTL_SET_COMPRESSION, _ 'ptr', DllStructGetPtr($tInput), _ "dword", DllStructGetSize($tInput), _ "ptr", 0, _ "dword", 0, _ "dword*", 0, _ "ptr", 0) MsgBox(0,"Results", " File Attributes: " & FileGetAttrib($dFile)) ; === View variables to console ========= ConsoleWrite("$hFile: " & $hFile & @CRLF) Local $sRes = @CRLF & 'DeviceIoControl:-' & @CRLF For $x = 0 To UBound($callid) - 1 $sRes &= "$callid[" & $x & "] = " & $callid[$x] & @CRLF Next ConsoleWrite($sRes & @CRLF) ConsoleWrite("File Attributes: " & FileGetAttrib($dFile) & @CRLF) ; ============================ ; Link to comment Share on other sites More sharing options...
Yashied Posted July 27, 2009 Share Posted July 27, 2009 (edited) I'm very new to DllCall so this code may look pretty novice. I'm trying to set the "Compress contents to save disk space" attribute on a file. Whenever i run the script it fails to complete and displays no error. $dFile = "C:\Program Files\Steam\steamapps\astropop deluxe content.ncf" $callid = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'hwnd', $dFile, 'dword', "FSCTL_SET_COMPRESSION", 'ptr', "COMPRESSION_FORMAT_NONE", "dword", DllStructGetSize("COMPRESSION_FORMAT_NONE"), "ptr", "NULL", "dword", "0", "dword*", "NULL") if @error Then MsgBox(0, "", @error) MsgBox(0, "", $callid) MSDN - http://msdn.microsoft.com/en-us/library/aa364592%28VS.85%29.aspx Thanks See _WinAPI_GetCompression() and _WinAPI_SetCompression() from WinAPIEx.au3 library. Edited July 27, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now