Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
NetConnectionEnum
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00602479
Message ID:
00602495
Vues:
13
Here's something I was working on, is this close to what you were looking for? You call the "listalldrives" function... sorry if it's not cleaned up well.

FUNCTION fgetdrives
* Return mapped drives
LOCAL lnret, lcstrdrives, lnlenstrdrives
DECLARE LONG GetLogicalDriveStrings IN kernel32.DLL ;
AS GetLogicalDriveStringsA LONG, STRING @
lcstrdrives=" " && api call will resize this var and store results here
* "Pre call" GetLogicalDriveStrings with a zero buffer to determine necessary
* stringbuffer size, then create a buffer by replicating null n times
lcstrdrives = REPLICATE(CHR(0),getlogicaldrivestringsa(0, @lcstrdrives))
lnlenstrdrives = LEN(lcstrdrives)
lnret= getlogicaldrivestringsa (@lnlenstrdrives, @lcstrdrives)
*CLEAR DLLS
RETURN IIF(lnret>0, LEFT(lcstrdrives,lnret), "")
ENDFUNC

FUNCTION mygetuncpath
LPARA lpszdrvletter
LOCAL msg, lngreturn, lpszremotename, cbremotename, retval
* unc path errors
#DEFINE err_bad_device 1200
#DEFINE err_connection_unavail 1201
#DEFINE err_extended_err 1208
#DEFINE err_more_data 234
#DEFINE err_not_supported 50
#DEFINE err_no_net_or_bad_path 1203
#DEFINE err_no_network 1222
#DEFINE err_not_connected 2250
#DEFINE no_err 0
* messagebox stuff
#DEFINE mb_ok 0
#DEFINE mb_okcancel 1
#DEFINE mb_abortretryignore 2
#DEFINE mb_yesnocancel 3
#DEFINE mb_yesno 4
#DEFINE mb_retrycancel 5
#DEFINE mb_stop 16
#DEFINE mb_question 32
#DEFINE mb_exclamation 48
#DEFINE mb_information 64
#DEFINE mb_first_button_default 0
#DEFINE mb_second_button_default 256
#DEFINE mb_third_button_default 512
STORE "" TO retval, msg
*lpszlocalname = lpszDrvLetter

IF AT(CHR(92),lpszdrvletter)>2
lpszdrvletter=SUBSTR(lpszdrvletter, 1, 2) && trim beyond drive and colon
ENDIF

lpszremotename = REPLICATE(CHR(32),255)
cbremotename = LEN(lpszremotename)
lngreturn = wnetgetconnectiona(@lpszdrvletter,@lpszremotename,@cbremotename)
DO CASE
CASE lngreturn=err_bad_device
msg = "Error: Bad Device"
CASE lngreturn=err_connection_unavail
msg = "Error: Connection Un-Available"
CASE lngreturn=err_extended_err
msg = "Error: Extended Error"
CASE lngreturn=err_more_data
msg = "Error: More Data"
CASE lngreturn=err_not_supported
msg = "Error: Feature not Supported"
CASE lngreturn=err_no_net_or_bad_path
msg = "Error: No Network Available or Bad Path"
CASE lngreturn=err_no_network
msg = "Error: No Network Available"
CASE lngreturn=err_not_connected
msg = "Error: Not Connected"
CASE lngreturn=no_err && all is successful
msg = ""
ENDCASE
IF LEN(msg) >0
MESSAGEBOX(msg, ;
mb_ok+mb_information+mb_first_button_default, 'Just so you know...')
ELSE
retval = SUBSTR(lpszremotename, 1, AT(CHR(0),lpszremotename,1) - 1)
ENDIF
*CLEAR DLLS
RETURN retval
ENDFUNC

PROC listalldrives
LOCAL lpszalldrives, lcnullchar
#DEFINE drv_unknown 0
#DEFINE drv_absent 1
#DEFINE drv_removable 2
#DEFINE drv_fixed 3
#DEFINE drv_remote 4
#DEFINE drv_cdrom 5
#DEFINE drv_ramdisk 6
lcnullchar=CHR(0)
STORE fgetdrives() TO lpszalldrives
DECLARE LONG GetDriveType IN kernel32.DLL AS GetDriveTypeA STRING
DECLARE LONG WNetGetConnection IN mpr.DLL ;
AS WNetGetConnectionA STRING @, STRING @, LONG @
DO WHILE LEN(lpszalldrives)>0 && <> ""
strdrivename = SUBSTR(lpszalldrives,1,AT(CHR(0),lpszalldrives,1)) &&-1))
* documentation GetDriveType indicates "parameter lpRootPathName Points
* to a null-terminated string that specifies root directory of the disk
* to return information about. " Ergo, the para must be by reference and
* the data in the variable must end in a null (chr(0)).

*DO WHILE SUBSTR(strdrivename, LEN(strdrivename), 1 ) = CHR(0)
* strdrivename = strdrivename + CHR(0)
*strdrivename = SUBSTR(strdrivename, 1, LEN(strdrivename)-1 )
*ENDIF
*ENDDO
*WAIT WIND STRTRAN(strdrivename,CHR(0),'~')
lngret=getdrivetypea (strdrivename)
IF CHR(0)$ strdrivename
strdrivename=SUBSTR(strdrivename, 1, AT(CHR(0), strdrivename)-1)
ENDIF
DO CASE
CASE lngret=drv_unknown
strdrivename = "Unknown Drive Type "+ strdrivename
CASE lngret=drv_absent
strdrivename = "Drive " + strdrivename + "does not exist"
CASE lngret=drv_removable
strdrivename = "Removable drive: " +strdrivename
CASE lngret=drv_fixed
strdrivename = "Local drive: " +strdrivename
CASE lngret=drv_remote
strdrivename = "Network drive: " +strdrivename+CHR(13)+CHR(10) + ;
" unc path: " + mygetuncpath( strdrivename )
CASE lngret=drv_cdrom
strdrivename = "CD Rom drive: " + strdrivename
CASE lngret=drv_ramdisk
strdrivename = "Ram Disk: " + strdrivename
ENDCASE
lpszalldrives=IIF(OCCURS(CHR(0),lpszalldrives)>1,;
SUBSTR(lpszalldrives,AT(CHR(0),lpszalldrives,1)+1), "")
? strdrivename
ENDDO
CLEAR DLLS
ENDPROC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform