Solved

Logon script to map network drives VBS

Posted on 2011-02-24
19
1,043 Views
Last Modified: 2012-05-11
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
Comment
Question by:ouch_mybrain_
  • 11
  • 4
  • 2
  • +2
19 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34969513
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
 

Author Comment

by:ouch_mybrain_
ID: 34969586
That has not resolved the issue. Thanks for your quick response though.
0
 
LVL 17

Expert Comment

by:Sikhumbuzo Ntsada
ID: 34969618
0
 
LVL 17

Expert Comment

by:Sikhumbuzo Ntsada
ID: 34969638
Try "Word to PDF" and "PDF to Word"
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34969639
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
 
LVL 17

Expert Comment

by:Sikhumbuzo Ntsada
ID: 34969642
Ignore my last post please
0
 
LVL 2

Expert Comment

by:chris_cox11
ID: 34969650
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
 

Author Comment

by:ouch_mybrain_
ID: 34969697
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
 

Author Comment

by:ouch_mybrain_
ID: 34970248
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
Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 
LVL 17

Expert Comment

by:Sikhumbuzo Ntsada
ID: 34970314
Here is another option to explore:

http://support.microsoft.com/kb/297684
0
 

Author Comment

by:ouch_mybrain_
ID: 34970645
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
 

Author Comment

by:ouch_mybrain_
ID: 34970906
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
 

Author Comment

by:ouch_mybrain_
ID: 34971033
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
 

Accepted Solution

by:
ouch_mybrain_ earned 0 total points
ID: 34971648
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
 

Assisted Solution

by:ouch_mybrain_
ouch_mybrain_ earned 0 total points
ID: 34971671
And just for reference, that method is (after clicking to edit the policy in question):

User Configuration > Preferences > Windows Settings > Drive Maps.

0
 

Author Comment

by:ouch_mybrain_
ID: 34971703
Reasons stated above.
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 34971878
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
 

Author Comment

by:ouch_mybrain_
ID: 34971955
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
 

Author Closing Comment

by:ouch_mybrain_
ID: 35005243
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now