Read size of file

Got a problem you cannot solve? Try here.
Post Reply
jdeleon7010
Posts: 27
Joined: Thu Jul 26, 2012 2:23 pm

Read size of file

Post by jdeleon7010 »

Is there support to read the size of a file?
jdeleon7010
Posts: 27
Joined: Thu Jul 26, 2012 2:23 pm

Re: Read size of file

Post by jdeleon7010 »

I am actually trying to call GetFileSize from kernel32.dll. The return value is EXTERNELEXCEPTION, what is wrong with my parameters?

Code: Select all

~InstallAware Clipboard Data~
~MessageBox~
~{66E06A30-BF40-45A5-97A9-EBBD5C91110A}~
~TEST~
~$FILE_SIZE$~
~0~
~1~
~~
~Call DLL Function~
~{20E7AA1B-23BA-4372-AABA-429C2285A8B6}~
~kernel32.dll,GetFileSize,byte,FILE_SIZE,"pointer to string",$SD$\_TMP\test.bat,$~
~mIDEFunc.dll\mEXEFunc.dll~
~Set Variable~
~{115FF94E-88EC-49F3-B6F2-0B615D0CE92A}~
~FILE_SIZE$MYAH$MYAH$FALSE~
~~
jdeleon7010
Posts: 27
Joined: Thu Jul 26, 2012 2:23 pm

Re: Read size of file

Post by jdeleon7010 »

Disregard, I had to add dword false parameter.
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Read size of file

Post by FrancescoT »

Happy that you solved! :D
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
saleen98r
Posts: 6
Joined: Mon Sep 10, 2007 7:48 pm

Re: Read size of file

Post by saleen98r »

Hi, I'm actually trying to do this to confirm a size of corporate standard wallpaper in a IDE script to create, then set the wallpaper on all machines. We are then using GPO later to enforce it. The previous poster stated he added "double word" and false. I may be using the parameter incorrectly because the result is always "255". No matter what the BMP size is. Can you be more specific please?

~Call DLL Function~
~{637DE3A5-C922-445E-A928-4AA086F52B79}~
~kernel32.dll,GetFileSize,byte,FILESIZE,"pointer to string",$WIN$Wallpaper.bmp,"double word",FALSE,$~
~mIDEFunc.dll\mEXEFunc.dll~
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Read size of file

Post by FrancescoT »

Dear User,

the above code is not correct.
Please use the following code as example:

Code: Select all

~InstallAware Clipboard Data~
~End~
~{BD9DC602-43A6-49B9-8ED7-3C2BB6F2845E}~
~End~
~{F550168D-EB0B-4C74-B680-312B684D777C}~
~Call DLL Function~
~{D3C689B6-EA56-4243-B345-DDE8E25B1FDC}~
~Kernel32.dll,CloseHandle,bool,RESULT,"double word",$FILE_HANDLE$,$~
~~mIDEFunc.dll\mEXEFunc.dll~~
~Set Variable~
~{A6A2A769-8FBF-437B-8351-1E6ED556B129}~
~RESULT$MYAH$MYAH$FALSE~
~FALSE~
~Comment~
~{803610FC-F813-47EC-AA82-5C1AF4AC58BF}~
~~
~MessageBox~
~{DE1DCA8F-0DED-446A-8130-0B380680A414}~
~DEBUG~
~File size = $FILE_SIZE$~
~0~
~1~
~~
~Call DLL Function~
~{F1DD8BDF-F788-40B1-BFF1-319FBDC9EC6B}~
~Kernel32.dll,GetFileSize,"double word",FILE_SIZE,"double word",$FILE_HANDLE$,"double word",0,$~
~~mIDEFunc.dll\mEXEFunc.dll~~
~If~
~{BFDEFE3F-8E45-4A2A-A6D6-E8215079BE1E}~
~FILE_HANDLE~
~4~
~4294967295~
~TRUE~
~If~
~{8A8542B7-F393-456F-A5B6-C43E71707039}~
~FILE_HANDLE~
~2~
~0~
~FALSE~
~Call DLL Function~
~{F319E9BC-C572-4D74-A615-F8220D901E02}~
~Kernel32.dll,CreateFileA,"double word",FILE_HANDLE,"pointer to string",C:\myfile.pdf,"double word",2147483648,"double word",0,long,0,"double word",3,"double word",128,"double word",0,$~
~~mIDEFunc.dll\mEXEFunc.dll~~
~Comment~
~{9501523B-B740-427B-B34C-ADBC53E04771}~
~~
~Set Variable~
~{FBF5A181-86AF-4E88-BCD3-97D85FE7F7B1}~
~FILE_SIZE$MYAH$MYAH$FALSE~
~~
~Set Variable~
~{05684256-A473-45A6-98A2-0C56FE6B682C}~
~FILE_HANDLE$MYAH$MYAH$FALSE~
~~
Hope this helps you.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
saleen98r
Posts: 6
Joined: Mon Sep 10, 2007 7:48 pm

Re: Read size of file

Post by saleen98r »

Hi. I've tried the new code. For some reason, the $FILE_HANDLE$ shows 0 even though it was declared. Once it ran, the $RESULT$ showed as FALSE. Is the code correct? I thought function is suppose to be GetFileSize to get the size of a file, not CloseHandle.

I've included screen capture of Call DLL function and all codes pertaining to this task. Thanks for helping in advance.

Here's my current code:
Set Variable FILE_HANDLE to $WINDIR$\System32\msiexec.exe
Call DLL Function Kernel32.dll->CloseHandle (get result into variable RESULT)
MessageBox: DEBUG, HANDLE = $FILE_HANDLE$$NEWLINE$RESULT = $RESULT$

Here's the contents of the CALL DLL FUNCTION:
~InstallAware Clipboard Data~
~Call DLL Function~
~{099FCEC6-3AF8-40DE-9526-64F4F9093FE1}~
~Kernel32.dll,CloseHandle,bool,RESULT,"double word",$FILE_HANDLE$,$~
~mIDEFunc.dll\mEXEFunc.dll~
Attachments
Screen capture of Call DLL fuction
Screen capture of Call DLL fuction
SNAG-0039.jpg (34.68 KiB) Viewed 9472 times
saleen98r
Posts: 6
Joined: Mon Sep 10, 2007 7:48 pm

Re: Read size of file

Post by saleen98r »

BTW, i "SET variable FILE_HANDLE = $WINDIR$\System32\msiexec.exe" just as a test because I know the file exists for sure and the exe contains fields/data that a BMP file does not contain.
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Read size of file

Post by FrancescoT »

Dear User,

please review my code once again ... what you are doing is not correct at all.

FILE_HANDLE points to a file handle pointer (with WIN API is declared as HANDLE) not to the file name.

With my code the file name is passed as first parameter in CreateFileA WIN API function.
So just replace the file name I used with my sample and leave all the rest as it is.

The call to CloseHandle is required because it is necessary to FREE the pointer returned (FILE_HANDLE ) ... otherwise could cause problems.

To use my code just copy and then paste it in your script.
The sample will show a dialog that reports the size of the given file.
I have personally tested it!

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
Post Reply