Solved

Login script not naming drives right

Posted on 2008-10-20
2
190 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

765 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