Question:
Is there a Win32 API call to ascertain what drives user has on his PC?
Anita Mallya
2009-03-05 06:43:56 UTC
Is there a Win32 API call to ascertain what drives user has on his PC?

I am a Visual Foxpro Programmer. I have understood lately that Windows API calls can be given using Visual Foxpro 9.0 Professional Edition.

Is there a Visual Foxpro programmer using VFP 9.0 Professional Edition in this forum or elsewhere on the net (whom u know) who has good knowledge of Visual Foxpro as well as Win32 API and who could help me?

I wish to know what is the small VFP program (function) I have to write in Visual Foxpro such that my program will understand what are the various drives that are present on the user's PC (without physically accessing those drives)

What I mean by physically accessing is -> For example if I give command SET DEFA TO E:\ (believing that Foxpro will give an error to me 'Invalid Path" if this drive doesn't exists on my PC I found two problems here:

Problem # 1: My computer doesn't have A:\ drive (that is floppy). But when I gave SET DEFA TO A:\ nothing happened for a while and then Windows gave its own message "Drive Not Ready" with three command buttons "Cancel; Try Again; Continue" and then if I pressed Cancel in Windows Error Dialog I was shown by Foxpro Invalid Path. Which means Foxpro or Windows actually physically tried to access the drive.

What I want is internally some Windows command should tell me whether a particular drive is present on users PC. For example suppose there is a Windows call
isdrivexists("A:") where A: Drive letter is passed as parameter then that Windows call will return some value which will tell me whether A:\ exists on users PC or not. So physically that drive is not accessed (and so no error "Drive Not Ready" is generated and flashed in a window by Windows). But internally I get to know that A: doesn't exist.

Problem # 2: My computer has DVD RW drive. But when I gave SET DEFA D:\ (which is DVD RW) Foxpro gave me error "Invalid drive". So immediately I understood that SET DEFA TO >>drive letter>> is useless to ascertain what drives are present on user's computers. Because in this case athough D:\ existed on my PC Foxpro gave me "Invalid drive or path" error (just because it didn't find a DVD in that drive). Now, while I am checking which drives exists the user may not be having a DVD put into his DVD Writer and so foxpro will return "Invalid drive or path" (so this SET DEFA TO command is not good to detect whether a drive exists on a user's PC).

Basically, In my Foxpro program I wish to show Drive Letters of Valid drives that are present on user's PC. So if some user has C:\ and D:\ but doesn't have A:\ then only C:\ and D:\ will be shown in drop box list. Got It!

For that I need a Windows call to internally ascertain what drives are present on user's PC. And I wish to know how to use that call from within Foxpro. So only a person who knows both Foxpro as well as Windows programming can tell me how to go about it.

Thanks & Regards,

Anita Mallya.
Three answers:
justme
2009-03-05 09:14:59 UTC
try using the following API. I dont know Foxpro (only visual C++), but this is supposed to also work with Foxpro.



GetLogicalDriveStrings

The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system.



DWORD GetLogicalDriveStrings(

DWORD nBufferLength, // size of buffer

LPTSTR lpBuffer // pointer to buffer for drive strings

);



Parameters

nBufferLength

Specifies the maximum size, in characters, of the buffer pointed to by lpBuffer. This size does not include the terminating null character.

lpBuffer

Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with representing the terminating null character.

c:\d:\



Return Values

If the function succeeds, the return value is the length, in characters, of the strings copied to the buffer, not including the terminating null character. Note that an ANSI-ASCII null character uses one byte, but a Unicode null character uses two bytes.



If the buffer is not large enough, the return value is greater than nBufferLength. It is the size of the buffer required to hold the drive strings.



If the function fails, the return value is zero. To get extended error information, use the GetLastError function.



Remarks

Each string in the buffer may be used wherever a root directory is required, such as for the GetDriveType and GetDiskFreeSpace functions.



QuickInfo

Windows NT: Requires version 3.1 or later.

Windows: Requires Windows 95 or later.

Windows CE: Unsupported.

Header: Declared in winbase.h.

Import Library: Use kernel32.lib.

Unicode: Implemented as Unicode and ANSI versions on Windows NT.
mark r
2009-03-05 09:04:48 UTC
The scripting guys at Microsoft put together scripts and refer to the WMI which may be accessible from Foxpro



I would visit the script centre at Microsoft:

http://www.microsoft.com/technet/scriptcenter/default.mspx



From memory this may be of interest:

http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx
2016-10-25 17:30:52 UTC
you want to run a deadly disease experiment. You did not get all of or not it really is deleting the record. in case you aren't getting all of it it really is going to rewrite itself. you want energetic Virus take care of. it really is ninety 8% affective.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...