Solved

Login script not naming drives right

Posted on 2008-10-20
2
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch File to find and replace a string 15 116
Using winfows 7 and 10 download en install MYSQL server from a batch 13 141
batch script 3 49
Developing a front end to SPLUNK 1 61
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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