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
Solved

Delphi Programming question

Posted on 1997-07-01
6
152 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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