Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mapping to network drive using .BAT file
Message
From
24/03/2004 07:37:55
 
 
To
23/03/2004 11:20:16
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00888895
Message ID:
00889197
Views:
32
Tim,

Cetin mentioned WNetAddConnection2. Here's some code that might help:
************************************************
FUNCTION WNetAddConnection2
************************************************
*  Created...........: 22.09.2000  14:45:27
*) Description.......: Wrapper around the API function WNetAddConnection2().
*)                   : This program is using Christof Lange's struct class.
*)                   : Returns 0 if successful
*  Calling Samples...: WNetAddConnection2("\\MyServer\apps\", "K:", "UserId", "Password")
*  Parameter List....:
*  Major change list.: 28.05.2002 DGR: New parameter < tlUpdateConnectionProfile > added.
*--------------------------------------------------------------------------------------------------
LPARAMETER tcNetworkName, tcDriveLetter, tcUserName, tcPassword, tlUpdateConnectionProfile

*--------------------------------------------------------------------------------------------------
*--  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
*[ Change DGR Fri 30.11.2001 - 10:01:28 
*[ Initialize parameters with .NULL. if not passed. This will force
*[ WinNT/Win2K to use the current user/password
*tcUserName = IIF(TYPE("tcUserName") = "C", tcUserName, "")
*tcPassword = IIF(TYPE("tcPassword") = "C", tcPassword, "")
tcUserName = IIF(TYPE("tcUserName") = "C", tcUserName, .NULL.)
tcPassword = IIF(TYPE("tcPassword") = "C", tcPassword, .NULL.)
*] End of Change

*-- 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
fdwConnection = IIF(tlUpdateConnectionProfile, CONNECT_UPDATE_PROFILE, 0)

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

RELEASE CLASSLIB Struct

RETURN lnRetVal
*-- EOF Function WNetAddConnection2 --------------------------------------------------------------------
HTH

>I need to map to a drive on another computer on the network. The network techs gave me the following batch file
>
> NET USE R: /D
> NET USE R: \\W0028109792\DATAWARE
>
>In the app's startup I do a
>
> RUN Yadayada.BAT
>
>Sometimes I see a DOS window and everything is great and other times I do not see a DOS window (and my users have to run the BAT file manually from a shortcut on the desktop). Most of my users are running Win XP. We are still using VFP 6 SP5.
>
>I am sure there is a better way of doing this in VFP (the politics of getting a login script are a problem at the moment).
>
>Thanks.
>
>Tim
Daniel
Previous
Reply
Map
View

Click here to load this message in the networking platform