Link to home
Start Free TrialLog in
Avatar of ouch_mybrain_
ouch_mybrain_

asked on

Logon script to map network drives VBS

Dear Experts,

I am no programmer by any means. The following I have extracted from my one of my company's logon scripts. It's purpose is to map a shared folder to a drive on the client computer. As far as scripts go, it is fairly straight forward.

Option Explicit
On Error Resume Next
Dim objNetwork

Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.MapNetworkDrive "J:" , "\\192.168.10.1\Applications"
objNetwork.MapNetworkDrive "K:" , "\\192.168.10.1\test Shared"

HOWEVER, even though it maps the folder and is accessible by the user, its appearence in My Computer is "disconnected". More specifically, the icon is in a light grey with a big red cross going through it. The description for the drive states "Disconnected Network Drive (J:)" and "Disconnected Network Drive (K:)". The script has also been assigned to the user via Group Policy (if that makes a difference).

Is anyone able to tell if the problem is with the script, or is there another configuration that needs to be applied?

Many Thanks,
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Try to remove drive before you map it by adding this line before each mapping line

objNetwork.RemoveNetworkDrive "<DriveLetter>", True, True

i.e.


objNetwork.RemoveNetworkDrive "J:", True, True
objNetwork.MapNetworkDrive "J:" , "\\192.168.10.1\Applications"


objNetwork.RemoveNetworkDrive "K:", True, True
objNetwork.MapNetworkDrive "K:" , "\\192.168.10.1\test Shared"

Regards,
Krzysztof
Avatar of ouch_mybrain_
ouch_mybrain_

ASKER

That has not resolved the issue. Thanks for your quick response though.
Try "Word to PDF" and "PDF to Word"
OK, try to set up one more GPO setting in

Computer Configuration -> Administrative Templates -> System -> Logon
and configure "Always wait for the network at computer startup and logon"

then your NIC will be up and then GPOs start applying.

and reboot client for test it.

Maybe that causes this problem?

Krzysztof
Ignore my last post please
if this is going to be added into login scripts then just use this string

net use J: /delete
net use K: /delete
net use J: \\192.168.10.1\Applications
net use K: \\192.168.10.1\test Shared


Make sure that you save this as a .bat file and in the NETLOGON folder on the server so that user accounts in AD can use this as a logon script.
iSiek, thanks but it still has not worked. This setting seems more driven towards XP (based on the policy explanation (i.e. Description: Determines whether Windows XP waits for the network during computer startup and logon). The client is Win7 (sorry for not mentioning that.

Will try Santasi24's solution, but it would only be a work around not a solution.
Santasi24: The script on the link maps the network drives but I still have the same problem where the client sees them as disconnected. Thank you for your suggestion though.

I am about to try Chris Cox's idea.
Here is another option to explore:

http://support.microsoft.com/kb/297684
Chris Cox, it has not worked. I literally created a new text file and saved it as a ".bat", with the content as:

net use J: /delete
net use K: /delete
net use J: \\192.168.10.1\Applications
net use K: \\192.168.10.1\Test Shared

Added it to the GPO scripts as normal, on client gpupdate /force and then reboot.

I placed the .bat it in the NETLOGON folder and also tried in the Machine\Scripts\Startup folder, but the net effect for both was that it only mapped the J drive and also still showed it as disconnected. So I actually got one less drive than expected doing it this way.

I am now going to try Santasi24's other solution.

Thanks
Santasi24, thanks for your response but it has not resolved the problem.

First of all I reversed back to my original script which mapped the drives but showed them as disconnected and made sure it worked. I then went onto the server to amend the registry setting as per the Microsoft Article. made all changes as necesarry, gpupdate /force and reboot on the client. Did not made the mapped drives appear as online.

Also, this article stated the problem as "the mapped drive may be disconnected after a regular interval of inactivity, and Windows Explorer may display a red "X" on the icon of the mapped drive". The problem I have is not to do with it timing out, but rather it showing as disconnected as default (yet I can still access the resources).

I still can't help but feel this is a really simple one, where perhaps there is a slight configuration that needs to be tweaked.

Thanks everyone for all your help it is much appreciated. If anyone has any more ideas then please let me know.

Thanks,
FYI I think i'm going to look for a different practice that achieves the same thing. It might be the way I have tried to do this is the problem. Will keep you updated.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of ouch_mybrain_
ouch_mybrain_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Reasons stated above.
Have you tried putting in a time delay? I think I ran into this issue when I implemented it as a logon script as well.

Since the profile was still loading, it didn't seem to have time to actually "connect" to the drive. So I ended up having to put a "sleep" command of about maybe 30 seconds to allow the user's profile to fully load before the drives were actually mapped.
Hi ThinkPaper,

Thanks for your suggestion but I don't want to spend any more time on this. I have found a means of doing the thing I wanted to do in a lot simpler way than I originally set out, so i am happy with my own solution.

Thanks again.
I looked into an alternative way to achieve the same thing I was looking for a solution for, and basically I found it. I did have help (with regards to this approach), although I am appreciative of other members contributions RE trying to get my original way to work.

Thanks.