Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1090
  • Last Modified:

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,
0
ouch_mybrain_
Asked:
ouch_mybrain_
  • 11
  • 4
  • 2
  • +2
2 Solutions
 
Krzysztof PytkoSenior Active Directory EngineerCommented:
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
0
 
ouch_mybrain_Author Commented:
That has not resolved the issue. Thanks for your quick response though.
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
Try "Word to PDF" and "PDF to Word"
0
 
Krzysztof PytkoSenior Active Directory EngineerCommented:
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
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
Ignore my last post please
0
 
chris_cox11Commented:
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.
0
 
ouch_mybrain_Author Commented:
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.
0
 
ouch_mybrain_Author Commented:
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.
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
Here is another option to explore:

http://support.microsoft.com/kb/297684
0
 
ouch_mybrain_Author Commented:
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
0
 
ouch_mybrain_Author Commented:
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,
0
 
ouch_mybrain_Author Commented:
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,
0
 
ouch_mybrain_Author Commented:
Guys just to let you know, that within Group Policy Administration there is a GUI that maps shared folders for you. It has removed the need for me to have a VB script to do this for me.

So I am pleased to confirm I have answered my own question.

Thanks,
0
 
ouch_mybrain_Author Commented:
And just for reference, that method is (after clicking to edit the policy in question):

User Configuration > Preferences > Windows Settings > Drive Maps.

0
 
ouch_mybrain_Author Commented:
Reasons stated above.
0
 
ThinkPaperIT ConsultantCommented:
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.
0
 
ouch_mybrain_Author Commented:
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.
0
 
ouch_mybrain_Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 11
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now