Solved

Logon script doesn't replace mapped network share

Posted on 2006-06-10
7
294 Views
Last Modified: 2010-04-18
My intention with this script is to re-map the user's drive mappings to a new server. We are retiring an old file server and copying user and community files to a new server. This script does a wonderful job of mapping drives if they have not been previously mapped and disconnecting previously mapped drives. It won't replace the old U: drive mapping with the new one; it only disconnects it and leaves it mapped to the old share. This is the script:

Dim objADSysInfo, objUser, objNetwork
Dim strComputer, strDriveUser, strDriveCC, strCNUser, strUserLogon

On Error Resume Next

strComputer = "TEAK"
strDriveUser = "U:"
strDriveCC = "L:"

Set objADSysInfo = CreateObject("ADSystemInfo")
strCNUser = objADSysInfo.UserName

Set objUser = GetObject("LDAP://" & strCNUser)
strUserLogon = objUser.sAMAccountName

Set objNetwork = WScript.CreateObject("Wscript.Network")
objNetwork.RemoveNetworkDrive strDriveUser, True
objNetwork.MapNetworkDrive strDriveUser, "\\" & strComputer & "\" & strUserLogon
objNetwork.RemoveNetworkDrive strDriveCC, True
objNetwork.MapNetworkDrive strDriveCC, "\\" & strComputer & "\Campus_Center"

Help with this would be great. Thanks in advance.
0
Comment
Question by:Dan_Mahoney
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:Netman66
ID: 16882431
This line:  objNetwork.RemoveNetworkDrive strDriveUser, True

Should be:  objNetwork.RemoveNetworkDrive strDriveUser

AND

This line:  objNetwork.RemoveNetworkDrive strDriveCC, True

Should be:  objNetwork.RemoveNetworkDrive strDriveCC


NM
0
 
LVL 51

Accepted Solution

by:
Netman66 earned 500 total points
ID: 16882435
If you MUST use brute force, then you need an additional TRUE.

objNetwork.RemoveNetworkDrive strDriveCC, True, True

Like that.

0
 
LVL 1

Author Comment

by:Dan_Mahoney
ID: 16887377
Thank you for looking at this.

I think I have tried both of your suggestions and thought that I was not getting the results I wanted. I try again. First no true and second both trues.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:Dan_Mahoney
ID: 16887444
The no trues produced the Disconnected network drive I have experienced before.
0
 
LVL 1

Author Comment

by:Dan_Mahoney
ID: 16887604
Both trues does the trick. Thanks!
0
 
LVL 51

Expert Comment

by:Netman66
ID: 16887618
You're welcome!

NM
0
 
LVL 51

Expert Comment

by:Netman66
ID: 16888172
The second true updates the profile (where the mappings are stored for network drives).

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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