Solved

Delphi Programming question

Posted on 1997-07-01
6
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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