Solved

Delphi Programming question

Posted on 1997-07-01
6
148 Views
Last Modified: 2010-04-04
Hello,I want to get a list of available drives, preferabily with drive types with delphi 2.0.I have found the relevent API calls but was wondering if there was an delphi function call to do this?
0
Comment
Question by:essbb
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
kevinb062397 earned 60 total points
ID: 1338051
Here's a app you can try.  This works on all drives. The second snip on code is for network drives info.


Start a new app.  add 1 button, 1 edit box, 1 label.  Copy the code into it and run.

procedure TForm1.Button1Click(Sender: TObject);
Var
x:integer;
drivetype:integer;
begin
for x:= 65 to (65+25)  do begin
edit1.text := chr(x) + ':';
drivetype := getdrivetype(pchar(edit1.text));
case drivetype of
0:Label1.caption := 'Drive Type Not Determined';
1:Label1.caption := 'Root Does not exists';
DRIVE_REMOVABLE:Label1.caption := 'Removable Drive';
DRIVE_FIXED:Label1.caption := 'Fixed Drive';
DRIVE_REMOTE:Label1.caption := 'Remote Drive';
DRIVE_CDROM:Label1.caption := 'CD Drive';
DRIVE_RAMDISK:Label1.caption := 'RamDisk Drive';
end;
update;
sleep(500);
end;
end;

-----------------------------------------------------------------

   s1 := TStringList.Create;
   nMappingsCount := GetNetworkDriveMappings(s1);
   for i := 0 to nMappingsCount -1 do begin
      listbox2.items.add(s1[i]);
   end;
   s1.free;
   getinfo;
   filefind;
   refresh;
end;


Function TForm1.GetNetworkDriveMappings(s1:TStrings):integer;
Var
   i:Integer;
   sNetPath:String;
   dwMaxNetPathLen:DWord;
Begin
   s1.clear;
   dwMaxNetPathLen := MAX_PATH;
   SetLength(Snetpath,dwMaxNetPathLen);
   For i := 0 to 25 do
   Begin
      if (NO_ERROR = Windows.WNetGetConnection(Pchar('' + Chr(65 + i) + ':'),
      Pchar(sNetPath), dwMaxNetPathLen))
      Then Begin
         s1.add(Chr(65 + i) + ':' + sNetPath);
      end;
   end;
   Result := s1.count;
end;

Let me know if you need more.
0
 

Author Comment

by:essbb
ID: 1338052
Thanks!
0
 

Author Comment

by:essbb
ID: 1338053
Do you know why the drive that the program is running from comes up as 'root not found' unless you are running the program from the root directory?Is it an API Bug?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:kevinb062397
ID: 1338054
It could be... You might try changing directories to the root of each drive before you getdrivetype.  Since the function uses the drive letter (i.e. C: ) it might be actual giving it the current directory.

I'm curious now, Thanks for the bit of info.
I'm going to try a few things myself.  I'll let you know if I find anything.

0
 
LVL 1

Expert Comment

by:kevinb062397
ID: 1338055
I added this just befor the getdrivetype:

{$I-}
chdir(edit1.text + '\');
{$I+}
if IOResult = 0 then begin

It listed all the drives correctly.

See if it will work for you.  ????
0
 

Author Comment

by:essbb
ID: 1338056
Yeah, That makes sense but you only need do it on the drive that the program is running on, If you go into the other drives first and change dir down a few levels it still works. Must be an API bug I think.btw - the getDriveType also works for all my networked drivesThanks-Brett
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now