Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
'net use' equivalent in VFP 5
Message
De
16/03/2001 00:22:44
 
 
À
15/03/2001 18:58:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00485664
Message ID:
00485724
Vues:
10
>Hello,
>
>Is there an equivalent of the DOS 'net use' command in VFP 5? I would like to connect to a server on a LAN, copy some files, then disconnect with code. Using the FoxPro 'run' command ( ! net use...) works, but not very well.
>

You can call the Windows API - WNetAddConnection3() can map a UNC to a local disk letter, permitting you to specify a userid and password when you make the connection, or the older WNetAddConnection() allows you to map the drive, but will use the current userid to connect to the remote server. WNetCancelConnection unmaps a remote share from a local drive letter. WNetAddConnection() and WNetCancelConnection() are documented in the Win API section; WnetAddConnection3() requires more complex code to implement; my NETRESOURCE class in the Files Section provides sample code to use it.

In addition, if the WSH is installed, it's Wscript.Network object offers a MapNetWorkDrive method and a RemoveNetworkDrive method using COMinstead of using direct calls to the Win32 API. It's covered in detail in artciles in back issues of the VFUG newsletter available on www.vfug.org; the COM objects also have additional capabilities built into their interfaces.

Finally, as mentioned, you can use a UNC to reference a file rather than mapping a drive to the UNC; if you might issue the command:

RUN NET USE Q: \\MyServer\MyShare

and then

COPY FILE Q:\MyFile TO C:\MyFile

you could instead issue:

COPY FILE \\MyServer\MyShare\MyFile TO C:\MyFile

with the sole problem being that in the event you are not already logged into \\MyServer, and can't be authenticated at the time you make the UNC reference, the command will fail (any number of things might cause a failure, like exceeding the maximum number of connections permitted simultaneously by the remote system, not having read privileges on the remote system unless a password was given when the connection was first issued, or some other system holding a lock which prevents other systems from accessing the file until it releases it's lock, are a few of the things that might prevent it from working, although the last one will happen to mapped drives, too.) The UNC has the advantage of making the same reference regardless of any drive mappings which might differ from system to system and user to user; it's an absolute reference for every member of the same network, since server names will be unique within a network, and the share names on a system refer to a specific resource of the individual server.
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