Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Mapped Drives not persistent when mapped from logon script

Posted on 2007-11-15
Medium Priority
Last Modified: 2010-03-17
I have the attached vbs logon script being called by logon.bat. I have a 2003 Server running AD and clients are XP SP2. I can logon and the script runs no problem. My drives are mapped. However, they are not persistent. If I log into Windows, then manually run the script the drives mapped and are persistent. Any thoughts would be greatly appreciated.

' MCMAPDRIVE.vbs - maps drives for users based on group membership
Dim objNet, strUserName 
Dim FileSysObj
On Error Resume Next
'Check the local ComputerName and run only if it's not a citrix server
'Set WshNetwork = WScript.CreateObject("WScript.Network")
'strSysEnvCN = WshNetwork.ComputerName 
'bolWTS =  InStr(strSysEnvCN, "JERMC6") 
  Set objNet = CreateObject("Wscript.Network") 
  set FileSysObj = CreateObject("Scripting.FileSystemObject")
  strUserName =objNet.UserName 
  set UserObj = GetObject("WinNT://" & objNet.UserDomain & "/" & objNet.UserName)
  For Each Group In UserObj.groups
     Select Case Group.Name
        Case "_Marketing" '80
		   MapDrive "m:", "", "marketing"
	Case "_Implementation"
           MapDrive "p:", "", "nsfforms"
        Case "_HR"
           MapDrive "r:", "", "hr"
        Case "_InternalIT"
           MapDrive "t:", "", "internalIT"
        Case "_Executives"
           MapDrive "x:", "", "executives"
        Case "_Finance"
           MapDrive "y:", "", "finance"
        Case "_Accounting"
           MapDrive "z:", "", "accounting"
     End Select
  'Call DisplayMappings
'End If
Sub MapDrive(Drive, FileServer, Share) '180
     FileServer = "\\" & FileServer
     Share = "\" & Share
     MapCount = MapCount + 1
  'Wscript.Echo "Now Mapping " & Drive & " to " & FileServer & Share
  If FileSysObj.DriveExists(Drive) = True Then
    objNet.RemoveNetworkDrive Drive, True, True
  End If
  objNet.MapNetworkDrive Drive, FileServer & Share & ", True"
End Sub
Sub DisplayMappings()
     Set DriveCollection = objNet.EnumNetworkDrives
     MsgString = "You have access to following network " & vbcrlf & "drive connections: " & vbCRLF & vbCRLF
     For i = 0 To DriveCollection.Count - 1 Step 2
          MsgString = MsgString & vbCRLF & vbtab & DriveCollection(i) & Chr(9) & DriveCollection(i + 1)
     MsgBox MsgString,vbInformation,"Your Information Technology"
End Sub     

Open in new window

Question by:mwarstler
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
  • 5
  • 4

Expert Comment

ID: 20294403
The third parameter of MapDrive needs to be a boolean, not a string.

Change to:

objNet.MapNetworkDrive Drive, FileServer & Share, True

Expert Comment

ID: 20294407
Sorry, I meant MapNetworkDrive.  But you get the point.

Author Comment

ID: 20294725

Thanks for your quick response. I'll test in the morning and reply.

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Author Comment

ID: 20297598
I'm having the same problem. If I log into Windows and run the script the drives are persistent. If I run it as a logon script they are not persistent. I've also tried this with the same results.

Set SH = CreateObject("WScript.Shell")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
SH.Run "NET USE " & Drive & " /delete"
SH.Run "NET USE " & Drive & " " & FileServer & Share & " /Persistent:YES"
'Wscript.Echo "net use " & Drive & " " & FileServer & Share & " /Persistent:YES"

Expert Comment

ID: 20298021
A potentially obvious question for both of you:

If you have the drive mappings in a logon script, why do you need them to be persistent?  They'll re-map each time you log on.

If you're saying that they're not persistent because you are logging in to a different user profile that doesn't run the script.. well, yeah, they wouldn't be.

Author Comment

ID: 20298321
My laptop users need them to be mapped when they go home and VPN into the office

Expert Comment

ID: 20298466
when they go home, do they log in to their domain account or a local account on the machine?

Author Comment

ID: 20298493
They log into thier domain account

Author Comment

ID: 20320384
The solution was to only call the vbs scipt directly and not via logon.bat

Accepted Solution

ee_auto earned 0 total points
ID: 24128502
Question PAQ'd, 500 points refunded, and stored in the solution database.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

618 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