Solved

Delphi Programming question

Posted on 1997-07-01
6
146 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
Comment Utility
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
Comment Utility
Thanks!
0
 

Author Comment

by:essbb
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:kevinb062397
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

12 Experts available now in Live!

Get 1:1 Help Now