Stuart McLachlan
stuart at lexacorp.com.pg
Thu Feb 6 01:07:00 CST 2003
On 6 Feb 2003 at 0:14, John W. Colby wrote:
> Guys, I have a VPN setup to allow me to Remote Access into a client's
> system.. Works great, highly recommended.
>
> I also have a mapped drive on the client's system. using that, whenever I
> have the VPN connection going I can drag and drop from my hard disk to the
> client's hard disk. Also works well except... if I don't have the VPN up,
> it wreaks havoc with many different things. Basically any time that Windows
> goes out to "scan" for available media, I have to endure a timeout. This
> means when any File Find dialog opens and I click the combo at the top to
> display the hard disks... 10 (or more) seconds while it figures out it can't
> see that drive. IEs "autocomplete" in the address bar doesn't work any more
> etc.
>
> My question is, is there any way, using scripting or otherwise, to set up
> something like a batch file to create the mapped drive. This would allow me
> to unmap the drive whenever I am not connected, the connect and remap the
> drive whenever I want to connect to that client using the VPN.
>
> I like the mapped drive and drag and drop from here to there soooo much I am
> very hesitant to disable it, but it is a major PITA to endure the problems
> whenever the VPN is not active.
>
You got me interested so i just had a look at the API to see how this could be done. it's fairly simple, just a single call
each way, so I knocked up a couple of PowerBasic CLI applications to map and unmap drives.
They have VERY limited error checking/reporting (just a message box if there is an error), but they should do what you
want as long as you get the command line in your batch file or shortcut right.
Let me know if you want the compiled executables and I will email them to you. They fit into a 10Kb zip file
Alternatively, you can adapt the source and roll your own in whatever language you prefer.
The only problem you may have converting to VB or VBA is with the ASCIIZ, ASCIIZ PTR and STRPTR .
Here is the PB source:
(watch for wrapping)
AAAAAH! just checking it before clicking "Send" and noticed I had still got an Admin level username and password in
there - and I'm working on a major network here at the moment.
UNMAP.EXE:
==========
DECLARE FUNCTION WNetCancelConnection2 LIB "MPR.DLL" ALIAS "WNetCancelConnection2A" (lpName AS ASCIIZ, BYVAL dwFlags AS DWORD, BYVAL fForce AS LONG) AS DWORD
FUNCTION PBMAIN() AS LONG
DIM strCommand AS STRING
DIM Sharename AS ASCIIZ * 255
DIM ireturn AS LONG
strCommand = COMMAND$
IF strCommand = "" THEN
MSGBOX "Usage: UNMAP D ,where D is the drive letter"
EXIT FUNCTION
END IF
sharename = strCommand$ & ":\"
ireturn = WNetCancelCOnnection2(sharename,0,0)
MSGBOX STR$(IRETURN)
END FUNCTION
======End of UNMAP.EXE=========
MAP.EXE
=======
dwScope AS DWORD
dwType AS DWORD
dwDisplayType AS DWORD
dwUsage AS DWORD
lpLocalName AS ASCIIZ PTR
lpRemoteName AS ASCIIZ PTR
lpComment AS ASCIIZ PTR
lpProvider AS ASCIIZ PTR
END TYPE
DECLARE FUNCTION WNetAddConnection2 LIB "MPR.DLL" ALIAS "WNetAddConnection2A" (lpszNetResource AS NETRESOURCE, lpszPassword AS ASCIIZ, lpszUserName AS ASCIIZ, BYVAL dwFlags AS DWORD) AS DWORD
FUNCTION PBMAIN() AS LONG
DIM strCommand AS STRING
DIM Sharename AS STRING
DIM Drivename AS STRING
DIM NResource AS NETRESOURCE
DIM ireturn AS LONG
DIM pw AS ASCIIZ * 32
DIM Username AS ASCIIZ * 32
pw = "xxxxxxxx"
username = "xxxxxxxxxx"
strCommand = COMMAND$
IF strCommand = "" THEN
MSGBOX "Usage: MAP D \\Server\Share where D is the drive letter to Map"
EXIT FUNCTION
END IF
Sharename = MID$(strCommand,INSTR(strCommand,"\\"))
Drivename = LEFT$(strCommand,1) & ":"
NResource.dwScope = 2 'RESOURCE_GLOBALNET
NResource.dwType = 1 'RESOURCETYPE_DISK
NResource.dwDisplayType = 3 'RESOURCEDISPLAYTYPE_SHARE
NResource.dwUsage = 1 'RESOURCEUSAGE_CONNECTABLE
NResource.lpLocalName = STRPTR(Drivename)
NResource.lpRemoteName = STRPTR(Sharename)
ireturn = WNetAddCOnnection2(NResource,pw,username,0)
MSGBOX STR$(ireturn)
END FUNCTION
--
Stuart McLachlan
Lexacorp Ltd
Application Development, IT Consultancy
http://www.lexacorp.com.pg