|  Get File Properties | 
| Author: | 
Message: | 
wincy 
Junior Member 
  
  
 
Posts: 67 Reputation: 4 
35 /   /   
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 | 
 | 
  | 
matty 
Scripting Guru 
     
  
 
Posts: 8327 Reputation: 109 
40 /   /   
Joined: Dec 2002
 
Status: Away
 
 | 
 | 
| 02-18-2009 03:27 PM | 
 | 
  | 
Spunky 
Former Super Mod 
     
  
  
 
Posts: 3656 Reputation: 61 
37 /   /   
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"    
 |   
 | 
| 02-18-2009 03:44 PM | 
 | 
  | 
wincy 
Junior Member 
  
  
 
Posts: 67 Reputation: 4 
35 /   /   
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 | 
 | 
  | 
matty 
Scripting Guru 
     
  
 
Posts: 8327 Reputation: 109 
40 /   /   
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 | 
 | 
  | 
wincy 
Junior Member 
  
  
 
Posts: 67 Reputation: 4 
35 /   /   
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 | 
 | 
  | 
andrewdodd13 
Senior Member 
    
  
  
Oh so retro
  
Posts: 869 Reputation: 16 
35 /   /   
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. 
 |   
 | 
| 02-18-2009 05:19 PM | 
 | 
  | 
matty 
Scripting Guru 
     
  
 
Posts: 8327 Reputation: 109 
40 /   /   
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 | 
 | 
  | 
wincy 
Junior Member 
  
  
 
Posts: 67 Reputation: 4 
35 /   /   
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 | 
 | 
  | 
matty 
Scripting Guru 
     
  
 
Posts: 8327 Reputation: 109 
40 /   /   
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 | 
 | 
  | 
| 
Pages: (2): 
« First
  
 [ 1 ]
 2
 
»
 
Last »
 | 
| 
 |