?
Solved

Mapped Drives not persistent when mapped from logon script

Posted on 2007-11-15
11
Medium Priority
?
690 Views
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") 
'IF bolWTS=FALSE THEN
 
  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:", "1.2.3.4", "marketing"
	Case "_Implementation"
           MapDrive "p:", "1.2.3.4", "nsfforms"
        Case "_HR"
           MapDrive "r:", "1.2.3.4", "hr"
        Case "_InternalIT"
           MapDrive "t:", "1.2.3.4", "internalIT"
        Case "_Executives"
           MapDrive "x:", "1.2.3.4", "executives"
        Case "_Finance"
           MapDrive "y:", "1.2.3.4", "finance"
        Case "_Accounting"
           MapDrive "z:", "1.2.3.4", "accounting"
           
     End Select
  Next          
  
 
  '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)
     Next
     
     MsgBox MsgString,vbInformation,"Your Information Technology"
               
End Sub     
 
Wscript.quit

Open in new window

0
Comment
Question by:mwarstler
[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
  • 5
  • 4
11 Comments
 
LVL 4

Expert Comment

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

Change to:

objNet.MapNetworkDrive Drive, FileServer & Share, True
0
 
LVL 4

Expert Comment

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

Author Comment

by:mwarstler
ID: 20294725
cjohnsen2,

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

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:mwarstler
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"
0
 
LVL 4

Expert Comment

by:cjohnsen2
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.
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:mwarstler
ID: 20298493
They log into thier domain account
0
 

Author Comment

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

Accepted Solution

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

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

762 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