Solved

Login script not naming drives right

Posted on 2008-10-20
2
188 Views
Last Modified: 2013-11-25
I created a login script in VB that works fine and computer that the user has never logged into but when the user logs into a computer that he has logged into it renames the drives to somthing other than what I have told it to. I can run a drive clean in my script do to hard mapping, but I did disconnect the drives before I ran the script, here is the script;
ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, objNetwork, UserString, UserObj, Path, GroupObj, ADSysInfo

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString = WSHNetwork.UserName

memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.

WSHNetwork.MapNetworkDrive "I:", "\\PWG-FS1\FoxPro",True
WSHNetwork.MapNetworkDrive "R:", "\\PWG-FS1\Production",True
WSHNetwork.MapNetworkDrive "Q:", "\\PWG-FS1\Vol1",True
WSHNetwork.MapNetworkDrive "T:", "\\PWG-FS1\Graphics",True
WSHNetwork.MapNetworkDrive "U:", "\\PWG-FS4\Users\" & UserString,True

'Check for group memberships and take needed action
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name

'Added "Graphics" Drive Mapping 10/16/08

Case "Graphics"
WSHNetwork.MapNetworkDrive "H:", "\\pwg-fs2\T_Share",True

Case "MIS Tracking"
WSHNetwork.MapNetworkDrive "M:", "\\pwg-fs1\MISTracking",True

Case "IT Help Desk Staff"
WSHNetwork.MapNetworkDrive "W:", "\\pwg-fs4\HelpDesk",True

Case "IT Operations Staff"
WSHNetwork.MapNetworkDrive "Y:", "\\pwg-fs4\ITOperations",True

Case "IT Programming Staff"
WSHNetwork.MapNetworkDrive "X:", "\\pwg-fs1\Developers\ComputerDept",True

Case "Domain Admins"
WSHNetwork.MapNetworkDrive "Z:", "\\pwg-fs1\Tech",True

'Added "Inventory" drive mapping on 10/14/08   JV

'Case "Inventory"
'WSHNetwork.MapNetworkDrive "L:", "\\pwg-fs4\Inventory",True


'Added Miami Drive mapping 03/28/07 SS

Case "Miami Drive Access"
WSHNetwork.MapNetworkDrive "K:", "\\pwgfldc2\public",True

END SELECT
NEXT

'Quit the Script
wscript.quit

0
Comment
Question by:Raquelfournier
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22758336
When you say "renames the drives to somthing other than what I have told it to", do you mean that there is a problem with the drive labels or that the drives are being mapped to the wrong shares?

If it's the latter then you may want to add code to unmap all existing network drives before mapping new ones.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0915.mspx

Alternatively you can preface each drive mapping with a command to un-map the drive first.


Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colDrives = objWMIService.ExecQuery("Select * From Win32_NetworkConnection")
 

For Each objDrive in colDrives

    If UCase(objDrive.LocalName) = "I:" Then

        WSHNetwork.RemoveNetworkDrive "I:", True, True

        Exit For

    End If

Next
 

WSHNetwork.MapNetworkDrive "I:", "\\PWG-FS1\FoxPro"

Open in new window

0
 

Author Comment

by:Raquelfournier
ID: 22759918
Perfect!!!! thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

23 Experts available now in Live!

Get 1:1 Help Now