Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

map a network drive 1

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
GB
Is there a way within Foxpro to map a network drive, which requires a password? Or would I have to use the DOS command Net use F: \\.........

Thanks
 
bebbo,

Just did a quick keyword search on this forum and found the following for you:

Maping a network drive with password
thread184-326642

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
bebbo

There also this:
Code:
oNet = CreateObject("WScript.Network")    
oNet.MapNetworkDrive("I","\\myserver\myFiles",.T.,"mike","password")


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
How would I check to see if the drive is already mapped. If it is it comes up with an error.

Thanks
 
bebbo

One solution might be to trap the error, althought this isn't accurate, where if you send the wrong parameters, it will also give you the same message. I would suggest you first create an array of the already mapped drives and use ASCAN to determine if the drive you are trying to map is already mapped. Here is how to create an array of you mapped drives.
Code:
WshNetwork = CREATEOBJECT("WScript.Network")
   oDrives = WshNetwork.EnumNetworkDrives
   PUBLIC ARRAY mappeddrives[oDrives.count-1]
   FOR i = 1 TO oDrives.COUNT -1
         STORE oDrives.ITEM(i) TO mappeddrives[i]
   NEXT



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks

In the end I have achieved this as below:

IF !FILE("c:\3100\NETWORK")
RETURN
ENDIF
STORE FOPEN('c:\3100\NETWORK') TO gnFileHandle && Open STORE FSEEK(gnFileHandle, 0, 2) TO gnEnd && Move pointer
STORE FSEEK(gnFileHandle, 0) TO gnTop && Move pointer
IF gnEnd <= 0 && Is file empty?
*WAIT WINDOW 'This file is empty!' NOWAIT
ELSE && If not
gcString = FGETS(gnFileHandle, gnEnd) && Store contents
DRV = SUBSTR(GCString,1,(AT(",", gcString,1)-1)) && Map
GcString = SUBSTR(GCString,(AT(",", gcString,1)+1))
SERVER = SUBSTR(GCString,1,(AT(",", gcString,1)-1)) &&
gcString = SUBSTR(GCString,(AT(",", gcString,1)+1))
StrUSER = SUBSTR(GCString,1,(AT(",", gcString,1)-1)) &&
StrPASS = SUBSTR(GCString,(AT(",", gcString,1)+1)) &&
oNet = CreateObject("WScript.Network")
oDrives = oNet.EnumNetworkDrives()
nLOCATED = .F.
For i = 0 To oDrives.Count - 1 &&Step 2
IF Alltrim(UPPER(oDrives.Item(i))) == ALLTR(UPPER(DRV))
nLOCATED = .T.
EXIT
ENDIF
Next
If nLOCATED = .F.
oNet.MapNetworkDrive(DRV + ":",SERVER,.F.,StrUSER, StrPASS)
ENDIF
ENDIF
= FCLOSE(gnFileHandle) && Close the file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top