>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.