Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determining a Net Connection.
Message
De
04/09/2001 11:41:10
 
 
À
04/09/2001 11:22:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00552078
Message ID:
00552095
Vues:
77
Melvin,
In order to find out if a connection exists, you could check for a known filename on the U:\ drive. If the file doesn't exist, presumably it's because the connection doesn't exist. Here's a procedure that allows you to map to a network drive:
*  Program...........: NetAddConnect
*  Author............: Daniel Gramunt
*  Created...........: 22.09.2000  14:45:27
*) Description.......: Wrapper to the API function WNetAddConnection2().
*)                   : This program is using Christof Lange's struct class.
*)                   : Returns 0 if successful
*  Calling Samples...: NetAddConnect("\\MyServer\apps\", "K:", "UserId", "Password")
*  Parameter List....:
*  Major change list.:
*--------------------------------------------------------------------------------------------------
LPARAMETER tcNetworkName, tcDriveLetter, tcUserName, tcPassword

*--------------------------------------------------------------------------------------------------
*--  Bit flag for fdwConnection in WNetAddConnection2()
*--------------------------------------------------------------------------------------------------
#DEFINE CONNECT_UPDATE_PROFILE   0x00000001

*--------------------------------------------------------------------------------------------------
*--  Error values returned by WNetAddConnection2()
*--------------------------------------------------------------------------------------------------
#DEFINE NO_ERROR                              0
#DEFINE ERROR_ACCESS_DENIED                   5
#DEFINE ERROR_ALREADY_ASSIGNED               85
#DEFINE ERROR_BAD_DEV_TYPE                   66
#DEFINE ERROR_BAD_DEVICE                   1200
#DEFINE ERROR_BAD_NET_NAME                   67
#DEFINE ERROR_BAD_PROFILE                  1206
#DEFINE ERROR_BAD_PROVIDER                 1204
#DEFINE ERROR_BUSY                          170
#DEFINE ERROR_CANCELLED                    1223      
#DEFINE ERROR_CANNOT_OPEN_PROFILE          1205
#DEFINE ERROR_DEVICE_ALREADY_REMEMBERED    1202
#DEFINE ERROR_EXTENDED_ERROR               1208
#DEFINE ERROR_INVALID_PASSWORD               86
#DEFINE ERROR_NO_NET_OR_BAD_PATH           1203
#DEFINE ERROR_NO_NETWORK                   1222

*--------------------------------------------------------------------------------------------------
*-- NETRESOURCE structure: scope of enumeration (dwScope)
*--------------------------------------------------------------------------------------------------
#DEFINE RESOURCE_CONNECTED   0x00000001
#DEFINE RESOURCE_GLOBALNET   0x00000002
#DEFINE RESOURCE_REMEMBERED  0x00000003

*--------------------------------------------------------------------------------------------------
*-- NETRESOURCE structure: bitmask of resource type (dwType)
*--------------------------------------------------------------------------------------------------
#DEFINE RESOURCETYPE_ANY     0x00000000
#DEFINE RESOURCETYPE_DISK	 0x00000001
#DEFINE RESOURCETYPE_PRINT	 0x00000002

*--------------------------------------------------------------------------------------------------
*-- NETRESOURCE structure: display type (dwDisplayType)
*--------------------------------------------------------------------------------------------------
#DEFINE RESOURCEDISPLAYTYPE_GENERIC  0x00000000
#DEFINE RESOURCEDISPLAYTYPE_DOMAIN   0x00000001
#DEFINE RESOURCEDISPLAYTYPE_SERVER   0x00000002
#DEFINE RESOURCEDISPLAYTYPE_SHARE    0x00000003

*--------------------------------------------------------------------------------------------------
*-- NETRESOURCE structure: bitmask of resource usage (dwUsage)
*--------------------------------------------------------------------------------------------------
#DEFINE RESOURCEUSAGE_CONNECTABLE    0x00000001
#DEFINE RESOURCEUSAGE_CONTAINER      0x00000002

*-- check parameters
ASSERT TYPE("tcNetworkName") = "C" AND NOT EMPTY(tcNetworkName) 
ASSERT TYPE("tcDriveLetter") = "C" AND NOT EMPTY(tcDriveLetter)

tcDriveLetter = LEFT(UPPER(tcDriveLetter),1)

*-- make sure drive letter is between G and Z
IF NOT BETWEEN(ASC(tcDriveLetter), 71, 90)
	WAIT WINDOW NOWAIT "Drive letter must be between G and Z!"
	RETURN -1
ELSE
	*-- add colon to drive letter
	tcDriveLetter = tcDriveLetter + ":"
ENDIF

*-- optional parameters
tcUserName = IIF(TYPE("tcUserName") = "C", tcUserName, "")
tcPassword = IIF(TYPE("tcPassword") = "C", tcPassword, "")

*-- declare API function
Declare Integer WNetAddConnection2 in Win32API ;
    String lpNetResource, ;
    String lpPassword, ;
    String lpUsername, ;
    Integer fdwConnection

*-- create structure
LOCAL loNetResource
SET CLASSLIB TO Struct ADDITIVE

loNetResource = CreateObject("NETRESOURCE")

With loNetResource 
	.dwScope        = RESOURCE_GLOBALNET
	.dwType         = RESOURCETYPE_DISK          && required by WNetAddConnection2
	.dwDisplayType  = 0
	.dwUsage        = RESOURCEUSAGE_CONNECTABLE
	.lpLocalName    = tcDriveLetter              && required by WNetAddConnection2
	.lpRemoteName   = tcNetworkName              && required by WNetAddConnection2
	.lpComment      = .NULL.
	.lpProvider     = .NULL.                     && required by WNetAddConnection2
EndWith

lpNetResource = loNetResource.GetString()
lpPassword    = tcPassword
lpUsername    = tcUsername
fdwConnection = CONNECT_UPDATE_PROFILE

*-- call API function
lnRetVal = WNetAddConnection2(lpNetResource, ;
                              lpPassword, ;
                              lpUsername, ;
                              fdwConnection)

RELEASE CLASSLIB Struct

RETURN lnRetVal
*-- EOF Function NetAddConnect --------------------------------------------------------------------

DEFINE CLASS NETRESOURCE AS struct
	dwScope        = 0
	dwType         = 0       && required by WNetAddConnection2
	dwDisplayType  = 0
	dwUsage        = 0
	lpLocalName    = .NULL.  && required by WNetAddConnection2
	lpRemoteName   = .NULL.  && required by WNetAddConnection2
	lpComment      = .NULL.
	lpProvider     = .NULL.  && required by WNetAddConnection2

	cMembers = "l:dwScope, l:dwType, l:dwDisplayType, l:dwUsage, "+;
	           "pz:lpLocalName, pz:lpRemoteName, pz:lpComment, pz:lpProvider"
ENDDEFINE
>Hi again.
>
>I have this problem rigth now. In a client we have create a remote sale system, in th system we require that the computer of the vendor be connect to a fisical net unit like: U:\ (where U:\ refers to \\name_server\folder_shared).
>
>I would like to know if exist any API function that allow me to know if the connection exist, and if not then any other function that allow me to reconnect to the user into the net.
>
>Thanks in advance,
>
>Melvin
Daniel
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform