Delphi - Automating Windows Scripting Host
Posted on 2006-06-10
I am doing something stupid here (not for the first time<g>) but I just cannot see it.
I simply want to use wsh to retrieve info about all the drives (specifically whether they are NTFS or not). (actually I did not want to use WSH or WMI which is a wrapper over WSH, and only wanted to find out which drives were NTFS but I could find no way of doing that - if anyone knows appropriate API calls for that, I would be pleased).
But now I am stuck with this stupid automation problem. I tried late binding and that did not work .. tried early binding and I got the same problem.
Here is the early binding version after having imported the IWshRuntimeLibrary_TLB;
procedure TForm1.btnTestForNTFSClick(Sender: TObject);
var fso: IFilesystem3;
var drvs: IdriveCollection;
var drv : Idrive;
fso := coFileSystemObject.create;
showmessage(inttostr(drvs.Count)); // 8 drives
// drv :=drvs.Item as Idrive; .. ***** crashes
drv :=drvs.get_Item(k) as Idrive; // ************ also crashes
// if fso.DriveExists('C:') then showmessage('ok') else showmessage('nope');
here is the late binding version
fso, drv, drvs,itm : OleVariant;
var k: integer;
fso := CreateOleObject('Scripting.FileSystemObject');
drvs := fso.drives;
showmessage('drive count =' +inttostr(drvs.count));
for k:=1 to drvs.count do begin
itm :=drvs(k); // *************** crashes
end; // end for
what am I doing wrong? casting? some problem with my understanding of collections?