Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Doing a "map network drive"

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Doing a "map network drive"
#13610
Posted by: DougA 2012-06-28 20:18:25
Is there a function that will accomplish the "map network drive" in windows ?
I wish to access some files on another computer that's connected via a router, I can do the map network drive manually, and that works.  However, I can't leave it "reconnect at logon" since this machine is normally used in a VPN setup, and i only need access once in a while.
What I'd like to do is issue this from my rexx program  (it's a file sync application)
Doug
Message2.
#13612
Posted by: Jeff Glatt 2012-07-02 14:41:32
Try this. I don't have network shares, so I can't test. Tell me if it works.
/* Call this subroutine once at the start of my script, to
 * give me two functions: AddNetDrive and RemoveNetDrive.
 */
err = registerfuncs()
IF err \== "" THEN DO
	SAY err
	RETURN
END

/* Now call AddNetDrive() to map my network share "\\ServerName\ShareName"
 * to drive letter X. First I must setup a stem variable that I must pass
 * to AddNetDrive(). I'll use a stem name of NetR, but any stem will work.
 */

/* Set the scope where connected = 1, global = 2, and remembered = 3 */
netr.1 = 2

/* Set the type of device where disk = 1, printer = 2, and any other type = 0 */
netr.2 = 1

/* Set the display type where domain = 1, server = 2, share = 3, and any other type = 0 */
netr.3 = 3

/* Set the usage where connectable = 1, container = 2 */
netr.4 = 1

/* Map the share to the X drive letter */
netr.5 = "X:"

/* Your valid share name goes here */
netr.6 = "\\ServerName\ShareName"

/*
 * Call AddNetDrive now. The first arg is the name of the stem we
 * setup above.
 * The second and third args are the password and user name (strings)
 * needed to access the share. If these args are omitted, the
 * user context for the process provides the default user name.
 * The fourth arg is 1 if the user profile should be updated, or
 * 0 if not.
 */
err = addnetdrive("NetR", "MyPassword", "MyUserName", 1)
IF err \= 0 THEN DO
/*
AddNetDrive returns 0 for success, or non-zero for failure.
Here are some of the error numbers AddNetDrive may return:
ACCESS_DENIED = 5
ALREADY_ASSIGNED = 85
BAD_DEVICE_TYPE = 66
BAD_DEVICE = 1200
BAD_NET_NAME = 67
BAD_PROFILE = 1206
BAD_PROVIDER = 1204
BUSY = 170
CANCELLED = 1223
CANNOT_OPEN_PROFILE = 1205
DEVICE_ALREADY_REMEMBERED = 1202
EXTENDED_ERROR = 1208
INVALID_PASSWORD = 86
NO_NET_OR_BAD_PATH = 1203
*/
   SAY "AddNetDrive failed:" err
   RETURN
END

/* Success. I can now use X drive. If desired, I can unmap it
 * it when I'm all done, by calling RemoveNetDrive.
 */
err = removenetdrive("X:", 1 /* update profile */, 0)
IF err \= 0 THEN SAY "RemoveNetDrive failed:" err

RETURN

registerfuncs: PROCEDURE
netresource = "32u,32u,32u,32u,str *,str *,str *,str *"
err = FUNCDEF("AddNetDrive", "32u,struct NETRESOURCE,str,str,32u", "mpr.dll", "WNetAddConnection2A")
IF err = 0 THEN DO
   err = FUNCDEF("RemoveNetDrive", "32u,str,32u,32u", "mpr.dll", "WNetCancelConnection2A")
   IF err \= 0 THEN RETURN "Registering RemoveNetDrive failed:" err
   RETURN ""
END
RETURN "Registering AddNetDrive failed:" err
Message3. Perfect
#13613
Posted by: DougA 2012-07-06 01:05:17
Thanks Jeff, works perfect.

question, what does "update the user profile" mean ?
Doug
Message4.
#13614
Posted by: Jeff Glatt 2012-07-06 06:00:51
The system updates your user profile to remember the mapping so that it it is reconnected upon the next login.

Actually, you may instead want to omit the fourth arg to AddNetDrive (and 2nd arg to removenetdrive).
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥333.00 ·
 
 
¥1,280.00 ·
 
 
¥1,760.00 ·
 
 
¥900.00 ·
 
 
¥950.00 ·
 
 
¥880.00 ·
© Tue 2024-11-5  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0