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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

map network drive to always connect at logon 3

Status
Not open for further replies.

R17

Programmer
Jan 20, 2003
267
PH

i use WSH to connect to a network drive, and i want to always connect it at logon so i use,

Code:
onet.mapnetworkdrive "H:","\\server1\data","True"
but the second time i run the program i have this error,

OLE IDispatch exception code 0 from WSHNetwork.MapNetworkDrive: An attemp was made to remember a device that had previously been remembered.

what should i do?
 
but the second time i run the program i have this error...what should i do?

Don't run the code a second time?

IF !Directory("H:\") && Doesn't exist - map it
oNet = CreateObject("WScript.Network")
oNet.MapNetworkDrive("H:","\\server1\data",.T.)
ENDIF

...the code snippet you have posted is not VFP code, and for that matter the third parameter should be type boolean according to the documentation of the MapNetworkDrive method and you are sending it a string "TRUE". I don't think that code would even work in VBScript. I'm not sure how you are making this work to begin with, so you may have more errors than just the one you are outlining here, either that or I am missing something.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
HI

This could be a older approach, but without errors.

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, STRING cAction, STRING cFileName, ;
STRING cParams, STRING cDir, INTEGER nShowWin

=ShellExecute(0,"RUN","NET","USE H: \\Server\data /YES","",0)

=ShellExecute(0,"RUN","NET", ;
"USE H: \\Server\data /User:myUser password /YES","",0)

:)

ramani :)
(Subramanian.G)
 


slighthaze,

why can't i run the form more than once? tried it with the string "True", i got the error. tried your suggestion, run the application the first time and got no error. closed the application and run it again, and i get the error.

am i wrong in putting the code in the init event of my form?

 
Hi R17,

Any attempt to use the same drive letter will create the error. YOu can trap it using ON ERROR routine and ignore it.

If you are using the code I posted.. the /YES confirms to overwrite the connection letter and so no error will come.

You can run that several times. HOwever, you have to make sure that the drive letter is infact available in either case. What if the server is down ?. SO you have to cover that.

:)

ramani :)
(Subramanian.G)
 
Hi R17,

Try this....

if drivetype('H')=1 && drive not exist
*connect drive
onet.mapnetworkdrive "H:","\\server1\data","True"
endif

Hope this will solve ur problem!

omr1119:)
 


hi omr1119,

that's what im doing, but error i posted above comes out.
 
R17,

Are you running exactly the code I posted? If not could you post the code you are running or try the code I posted in the init event of your form? This should be your code in the Init event of your form:

Local oNet
IF !Directory("H:\")
oNet = CreateObject("WScript.Network")
oNet.MapNetworkDrive("H:","\\server1\data",.T.)
ENDIF


Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
This command will map the drive without errors even if it is already mapped.

RUN /N7 NET USE DriveLetter: \\ServerName\DrivePath

e.g. "RUN /N7 NET USE F: \\PIV\Data"

Brian
 

i have this in the init event of my main form,

onet = createobject('WScript.Network')
if mappeddrive("H:")
* oNet.RemoveNetworkDrive('H:')
else
onet.mapnetworkdrive("H:", "\\Domainserver1\Home",.T.)
endif
 
R17,

I don't know what's in your mappeddrive() function for code, but if you'll just use the code I posted for you I can almost 100% assure you that your problem will be solved. If for some reason you don't like my code, then there are plenty of other suggestions here that you should be trying.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Looks like you have tried to use an example I posted in another thread.

Here's the complete code:
Code:
oNet = CREATEOBJECT('WScript.Network')
IF MappedDrive("H:")
   oNet.RemoveNetworkDrive('H:')
ENDIF 
oNet.MapNetworkDrive("H:", "\\MyServer\DATA")

ONET = .NULL.
RELEASE ONET
RETURN


*....... MappedList - checks for mapped drive ......
FUNCTION MappedDrive
PARAMETERS Which

Which = UPPER(Which)
STORE '' TO cUNC, cCurrentDrive
STORE .F. TO lRetVal
oDrives = ONET.EnumNetworkDrives
FOR iii = 0 TO (oDrives.COUNT - 1) STEP 2
   cCurrentDrive = oDrives.ITEM[iii]
   IF cCurrentDrive = Which 
      lRetVal = .T.
   ENDIF 
NEXT
oDrives = .NULL.
RELEASE oDrives
RETURN lRetVal

But if you're going to use this code in a form, you need to take the FUNCTION MappedDrive and put in in a form method. Then you can call it like

Change your init code to read:
onet = createobject('WScript.Network')
if !Thisform.mappeddrive("H:")
onet.mapnetworkdrive("H:", "\\Domainserver1\Home",.T.)
endif



-Dave S.-
[cheers]
Even more Fox stuff at:
 


actually Dave i put the function mappedDrive in a prg (it contains all my procedure/functions) and in my init event of my main's form i put set procedure to that prg before i call your code.

i wonder where did i go wrong.

 
Well that should be fine then. Otherwise, you would be getting an error saying the function doesn't exist.
But you're saying the app doesn't see the 'H:' drive as being mapped?
What happens if you step through the mappeddrive function call? Do you get the list?


-Dave S.-
[cheers]
Even more Fox stuff at:
 


dave,

mapping the drive to the network works perfectly using your code.

however, when i try to put the .T. to remember the connection, i get the error i posted above.

 
OLE IDispatch exception code 0 from WSHNetwork.MapNetworkDrive: An attemp was made to remember a device that had previously been remembered.

I am assuming that this is the error you are referring to. Here's perhaps what is going on... You have a drive that is mapped and have it configured to reconnect that drive at logon. However, when you are running for some reason the drive gets unmapped, and though it is "remembered" and would reconnect it at the next logon you are trying to get it to remap the drive right now, without restarting windows. So, in that case forego the .T. parameter and just remap the drive again.

oNet.MapNetworkDrive("H:","\\server1\data")

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top