Mapped Drives not persistent when mapped from logon script

Posted on 2007-11-15
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
  • 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.


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.
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS VPS as AD Server 2 55
Group policy backup error 8 25
Add Local Admin to all Workstations but Block Server Access 5 46
Exchange 2013 event logs 1 21
[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
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 tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

895 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

17 Experts available now in Live!

Get 1:1 Help Now