Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Connecting to a network resource
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00208246
Message ID:
00208283
Vues:
23
>I need to connect (login) to a network resource in VFP. What is the API call to do it?
>

There are several ways to do this. if you install the Windows Scripting Host (built into Win98 and Win2K, and distributed as a part of IE4/Ie5 and IIS, and also available as a self-installing .EXE from http://msdn.microsoft.com/scripting), you can use the WScript.network automation object.

You can also use the WNetAddConnection family of API calls; I have example code in my NETRESOURCE class for using WNetAddConnection3() (you'll need to download CLSHEAP.ZIP and NETRSC.ZIP from the Files Section on UT; the example code is DEMO_WNetAddConnection3.PRG in NETRSC.ZIP, but it relies on services in my NETRESOURCE and Heap classes.)

If you don't need to specify a user id (you intend to use the current Windows login to attach to the remote resource) you can implement WNetAddConnection as a single API call; it's les capable than WNetAddConnection2() and WNetAddConnection3(), and is included only for some backwards compatibility. The declaration for WNetAddConnection would look like:
DECLARE INTEGER WNetAddConnection IN Win32API ;
	STRING cRemoteUNC, ;
	STRING cPassword, ;
	STRING cLocalDrive

IF WNetAddConnection('\\SomeServer\SomeShare','MyPassword'+CHR(0),'N:') = 0
   *  it worked
ENDIF
You can attach a device by name like 'LPT1:' to attach a remote printer, etc.
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
Répondre
Fil
Voir

Click here to load this message in the networking platform