What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Get File Properties

Pages: (2): « First [ 1 ] 2 » Last »
Get File Properties
Author: Message:
wincy
Junior Member
**


Posts: 67
Reputation: 4
35 / Male / Flag
Joined: Feb 2008
O.P. Get File Properties
Hello!
I'm trying to get properties of a file on computer.
(In particular Author and Description), so I wrote this:

var oWMI = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colFiles = oWMI.ExecQuery("Select * from Win32_FileSpecification WHERE Name='C:\\Windows\\notepad.exe'");

for(var colFile = new Enumerator(colFiles); !colFile.atEnd(); colFile.moveNext()) {

Debug.Trace(colFile.FileSize+" "+colFile.Description);

}


But it doesn't works. Maybe i'm using the wrong function?
I tried also:

     var objFil = CreateObject("DSOFile.OleDocumentProperties");
    objFil.Open("C:\antivir.exe");
    Debug.Trace(objFil.SummaryProperties.Author);


with no results.
Can you help me doing this?
Thanks in advance!
02-18-2009 02:38 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Get File Properties
I think you need to use SHGetFileInfoW.
02-18-2009 03:27 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Get File Properties
Also, CreateObject and GetObject are not valid JScript functions IIRC. I think they're WScript

They usually have to be replaced with "new ActiveXObject"...
<Eljay> "Problems encountered: shit blew up" :zippy:
02-18-2009 03:44 PM
Profile PM Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
35 / Male / Flag
Joined: Feb 2008
O.P. RE: Get File Properties
quote:
Originally posted by matty
I think you need to use SHGetFileInfoW.

Thanks! Unfortunatly i'm not sure about i should use that funcion... maybe with Interop.Call("kernel32"... ecc?? Help

I made a function which lists current active processes using
GetObject and works correctly even without calling "new ActiveXObject".
02-18-2009 03:54 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Get File Properties
quote:
Originally posted by Spunky
Also, CreateObject and GetObject are not valid JScript functions IIRC. I think they're WScript

They usually have to be replaced with "new ActiveXObject"...
Using WMI you need to use it with GetObject.
quote:
Originally posted by wincy
Thanks! Unfortunatly i'm not sure about i should use that funcion... maybe with Interop.Call("kernel32"... ecc?? Help
I don't have the time right now to do further research on it. I am at work.
02-18-2009 04:16 PM
Profile E-Mail PM Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
35 / Male / Flag
Joined: Feb 2008
O.P. RE: Get File Properties
Made this:

var SHGFI_DISPLAYNAME = "&H200";
var FILE_ATTRIBUTE_NORMAL = "&H80";

var Result = Interop.Call('shell32', 'SHGetFileInfo', 'C:\antivir.exe', FILE_ATTRIBUTE_NORMAL, 0, 0, SHGFI_DISPLAYNAME);

Debug.Trace(Result);


This returns "0" in Debugger. How can i fix it?
02-18-2009 04:30 PM
Profile E-Mail PM Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
RE: Get File Properties
You're passing in a null pointer (the 0) to the API call. What you need to do is create a databloc which you can put SHFILEINFO into. Unfortunately, it's been a while since I scripted, so you'll need to read the documentation on this.
[Image: AndrewsStyle.png]
02-18-2009 05:19 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Get File Properties
Also every \ in JScript has to be escaped so instead of C:\antivir.exe you need to put C:\\antivir.exe
02-18-2009 05:35 PM
Profile E-Mail PM Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
35 / Male / Flag
Joined: Feb 2008
O.P. RE: Get File Properties
var FILE_ATTRIBUTE_NORMAL = "&H80";
var FFile = "C:\antivir.exe";
var Result = Interop.Call('shell32', 'SHGetFileInfo', FFile, FILE_ATTRIBUTE_NORMAL, '', FFile, "&H800");
Debug.Trace(Result);


Using only one "\" it outputs "1", but i don't think it is correct anyway. How can i use SHFILEINFO then? Here is its structure:

typedef struct _SHFILEINFO {
    HICON hIcon; // i don't have it
    int iIcon; // i don't have it
    DWORD dwAttributes; // needs GetAttributesOf (below)
    TCHAR szDisplayName[MAX_PATH]; // should i put file path here?
    TCHAR szTypeName[80]; // what to put here?
} SHFILEINFO;


GetAttributesOf here:

HRESULT GetAttributesOf(UINT cidl,
    PCUITEMID_CHILD_ARRAY *apidl,
    SFGAOF *rgfInOut
);


:( what a mess
02-18-2009 05:57 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Get File Properties
Ok you need to review a bit about memory allocations.

js code:
var szDisplayName = Interop.Allocate(512);
var szTypeName= Interop.Allocate(162);
var SHFILEINFO = Interop.Allocate(18);

with ( SHFILEINFO ) {
    WriteDWORD(10, szDisplayName.DataPtr);
    WriteDWORD(14, szTypeName.DataPtr);
    Debug.Trace( 'ShGetFileInfoW : ' + ( Interop.Call('shell32', 'ShGetFileInfoW', 'C:\\antivir.exe', 0x80, SHFILEINFO.DataPtr, Size, 0x800 ) === 0 ? 'Passed' : 'Failed' ) );
}

And obviously I have no way of testing the above it is just a guideline... but do research a bit more.

This post was edited on 02-18-2009 at 06:46 PM by matty.
02-18-2009 06:13 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On