Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to know my server is on?
Message
De
20/01/2001 02:21:03
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00465537
Message ID:
00466119
Vues:
13
>>Hi,
>> I am developing multiuser application. I faced a problem that, my application will be hang/error if the server is not switch on, not connect to network or access permission is not set properly.
>> How to implement a TestConnection function to check these issue before I open database ?
>>
>>Thank you
>
>How about
>if NOT file(addbs(PATH_TO_DATA_ON_SERVER) + "MYDBC.DBC")
>   ** Can't find data
>   return
>endif
>
>You can use ADIR() to check file attributes. Checking access permissions is beyond my knowledge with restpect to NT servers. I use NetLib to determine access rights on Novell servers.

Actually, it'd be better to use WNetAddConnection2() or WNetAddConnection3() to attach the UNC; it would actually attach the UNC, permitting a login and password specification, and allowing either mapped or UNC-based attachment of the resource. If the WNetAddConnection?() fails, the issue of access is a non-starter. Under NT or Win2K, you can use NetUserGetInfo() to determine some privilege information; in general, it's easier to simply use low-level file I/O to attempt to read/write/create files; while this is probably sufficient fore a Win9x share, where rights apply at the granularity of a folder, WinNT/2K have file-level privilege granularity; if this sort of information is needed, the using the ADSI ActiveX controls to access user and share information is probablyu going to be needed.

The following will attempt to access a UNC:
FUNCTION MapDevice
LPARAMETERS tcLocal, tcRemote, tcUserID, tcPassword, tlPermanent
LOCAL oHeapObj, oNetRsc, nResult
IF ! 'CLSHEAP' $ UPPER(SET('PROC'))
   SET PROCEDURE TO CLSHEAP ADDITIVE
ENDIF
IF ! 'NETRSC' $ UPPER(SET('PROC'))
   SET PROCEDURE TO NETRSC ADDITIVE
ENDIF
oHeapObj=CREATEOBJ('Heap') && I need a heap to allocate a static block

oNetRsc=CREATEOBJ('NETRESOURCE',oHeapObj)

oNetRsc.SetRemoteName(tcRemote)  && UNC of remote device
oNetRsc.SetLocalName(tcLocal)     && Local device name


IF TYPE('tcUserID') # 'C'        && No userid specified - null, use WinLogin
   tcUserID = 0
ELSE
   tcUserID = tcUserID + CHR(0)
ENDIF
IF TYPE('tcPassword') # 'C'       && No password given - null, use WinLogin
   tcPassword = 0
ELSE
   tcPassword = tcPassword + CHR(0)
ENDIF
*	Create the NETRESOURCE for the API call
oNetRsc.BuildNETRESOURCE()

DECLARE INTEGER WNetAddConnection3 IN WIN32API ;
	INTEGER hWnd, ;
	STRING @ lpNETRESOURCE, ;
	STRING @ lpPassword, ;
	STRING @ lpUserID, ;
	INTEGER dwFlags
DECLARE INTEGER GetActiveWindow IN WIN32API  && If we need a dialog
                                             && root to active window

*  tlPermanent indicates that we want to reestablish this mapping at next login

nResult = WNetAddConnection3(GetActiveWindow() , ;
                             oNetRsc.cNETRESOURCE, ;
                             tcPassword, ;
                             tcUserID, ;
                             IIF(tlPermanent,1,0) )
oNetRsc = NULL
oHeapObj = NULL
RETURN nResult

*  To use this:
nError = MapDevice('','\\Server\Share','MyUserID','Password')
* You can specify a drive letter for the first parameter to map the UNC to the
* drive, omitting userid and password use the WIndows Login userid and password
IF nError = 0
   *  UNC is now Addressible - you should check for the ability to Create, Open
   *  Read, Write, Delete, create subdirectories and alter file attributes using
   *  low-level functions and API calls, or the Scripting.FileSystemObject
ELSE
   *  Error is one of: ERROR_ACCESS_DENIED, ERROR_ALREADY_ASSIGNED,
   *  ERROR_BAD_DEV_TYPE, ERROR_BAD_DEVICE, ERROR_BAD_NET_NAME,
   *  ERROR_BAD_PROFILE, ERROR_BAD_PROVIDER, ERROR_BUSY,
   *  ERROR_CANCELLED, ERROR_CANNOT_OPEN_PROFILE,
   *  ERROR_EXTENDED_ERROR, ERROR_INVALID_PASSWORD, ERROR_NO_NET_OR_BAD_PATH,
   *  ERROR_NO_NETWORK
ENDIF
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform