Sign in to follow this  
Followers 0
kjcdude

DllCall DeviceIOControl Problem

5 posts in this topic

#1 ·  Posted (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 by kjcdude

Share this post


Link to post
Share on other sites



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'.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

;
#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)
; ============================
;

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Yashied

Share this post


Link to post
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
Sign in to follow this  
Followers 0