Solved

Login script not naming drives right

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

776 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