Solved

Login script not naming drives right

Posted on 2008-10-20
2
187 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
Comment Utility
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
Comment Utility
Perfect!!!! 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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

16 Experts available now in Live!

Get 1:1 Help Now