We help IT Professionals succeed at work.

Login Script Issues - Drops Network Drives Randomly

572 Views
Last Modified: 2012-03-26
I am having issues with a script that we ran across in a domain network.  Trying to clean things up so that there is a better grasp of rights within the domain, but in the meantime the following code should work correctly, but something is causing the network drives to appear (let's say 8 drives based on the script) and then the drives will randomly disappear without notice or cause that I can see.  Is it something in my code or is it something in the Domain that I need to reference or check?

'~~Script~~.
'--------------------------------------------------------------------
'
'Program Name       Login.VBS
'
'Author             David K.
'
'Description        VBS Login Script for Glen domain
'
'Design             Script can be set up to map network drives
'                   and printers using the IsMember("Group Name")
'                   function to determine group membership.  Script
'                   will also map drives and printers using the
'                   MapDrive() and MapPrinter() functions alone.
'                   A summary of network connections is displayed
'                   using the DisplayResources() function.
'
'Edit History
'                  12/16/06      Created
'                  02/11/2012    Edited by Clancy With NCP
'--------------------------------------------------------------------
'     declare global variables here

Option Explicit

Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict, TShoot, uHome, WSHshell
Dim fs, msg, strComputer, objReg, strKeyPath, strStringValueName, afile, oExec
'--------------------------------------------------------------------
'     Objects go here

Set oShell = CreateObject("Wscript.Shell")
Set oNet   = CreateObject("Wscript.Network")
set oFSO   = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")

TShoot = 0  '1 to troubleshoot; 0 for normal operation
'--------------------------------------------------------------------
                                       'all mapping and stuff is done from'here
                                       'you should not have to change functions
                                       'unless they do not work for some'reason

If TShoot then Greeting()
                                       'you can put any combination of code in
 				       'to process the function calls
                                       'this is just a quick example


'All common Startup Stuff goes Here

	If IsMember("COMMON") Then
	MapDrive "P", "\\glen_asi_svr\common"	'All User Public folders


	end if

'Virus Removal Was Here

'---------- Home Directory ----------

	If IsMember("AUTO-SITE") Then
	uHome = "\\glen_asi_svr\personal\" & oNet.UserName	
'MapDrive "Z",
'	if NOT oNet.UserName = "avideo" then	
 		MapDrive "Z", uHome
	end if

	If IsMember("General Managers") Then
	MapDrive "J", "\\glen_asi_svr\owner" 	  'W2K Local Share
	MapDrive "L", "\\glen_asi_svr\sales"
	MapDrive "M", "\\glen_asi_svr\ps"
	MapDrive "O", "\\glen_asi_svr\dir"
	MapDrive "R", "\\glen_asi_svr\hr"
	MapDrive "W", "\\glen_asi_svr\fi"

	end if

	If IsMember("Accounting Directors") Then
	MapDrive "O", "\\glen_asi_svr\dir"
	MapDrive "R", "\\glen_asi_svr\hr"

	end if

	If IsMember("Sales") Then
	MapDrive "L", "\\glen_asi_svr\sales"	'W2K Local Share
	MapDrive "W", "\\glen_asi_svr\fi"

	end if

	If IsMember("Parts Service") Then
	MapDrive "M", "\\glen_asi_svr\ps"	'W2K Local Share

	end if

	If IsMember("Finance Managers") Then
	MapDrive "W", "\\glen_asi_svr\fi"	'W2K Local Share

	end if

	If IsMember("Internet Managers") Then
	MapDrive "V", "\\glen_asi_svr\internet"	'W2K Local Share

	end if

	If IsMember("HR") Then
	MapDrive "R", "\\glen_asi_svr\hr"	'W2K Local Share

	end if

	If IsMember("Title Clerks") Then
	MapDrive "S", "\\glen_asi_svr\vehacct"	'W2K Local Share

	end if

	If IsMember("ASI Subaru") Then
	MapDrive "T", "\\asi_svr_gss\f"

	end if

	If IsMember("ASI Ford") Then
	MapDrive "Q", "\\glen_asi_svr\g"

	end if

	If IsMember("ASI Summit") Then
	MapDrive "Y", "\\SUM_ASI_SVR\P"

	end if

'--------------------------------------------------------------------
                                       'find out what groups the user belongs too
Function IsMember(sGroup)
    Dim sAdsPath, oUser, oGroup

    If IsEmpty(oGroupDict) Then
        Set oGroupDict         = CreateObject("Scripting.Dictionary")
        oGroupDict.CompareMode = vbTextCompare

        sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
        Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

        For Each oGroup In oUser.Groups
            oGroupDict.Add oGroup.Name, "-"
        If TShoot Then Wscript.Echo("Member of Group: " & oGroup.Name)
        Next

        Set oUser = Nothing
    End If

    IsMember = CBool(oGroupDict.Exists(sGroup))

End Function

'----------------------------------------+----------------------------------------
' MapDrive - Function to map a drive
'----------------------------------------+----------------------------------------
Function MapDrive(ByVal strDriveLetter, ByVal strPath)
  Dim objRegExp
  Dim iDrive
  Dim bExists
  Dim colDrives

  Set objRegExp = New RegExp

  strDriveLetter = UCase (strDriveLetter)
  objRegExp.IgnoreCase  = true
  objRegExp.Pattern = "^[F-Z]$"

  If Not objRegExp.Test (strDriveLetter) Then
    MapDrive = False
    Exit Function
  End If

  strDriveLetter = strDriveLetter & ":"

  bExists = False
  Set colDrives = oNet.EnumNetworkDrives()
  For iDrive = 0 To colDrives.Count - 1 Step 2
    If colDrives.Item(iDrive) = strDriveLetter Then
      bExists = True
    End If
  Next

  If bExists Then
    oNet.RemoveNetworkDrive strDriveLetter, true
  End If
  On Error Resume Next
  oNet.MapNetworkDrive strDriveLetter, strPath
  if TShoot = 1 then oShell.PopUp "Drive " & strDriveLetter & " connected to " & strPath & " successfully.", 5, "Logon", 0
  MapDrive = True

End Function

'----------------------------------------+----------------------------------------

Open in new window

Comment
Watch Question

Commented:
Could it be that user connects external drive example flash drives etc to computer it will override network drives ?
you could check from device manager that user does not have any other device mapped to same drive letter.

Author

Commented:
Would it matter in the code that I went from a 2003 Domain Server to a 2008 Domain Server?  Would the server read something in the code differently?
Frank McCourryV.P. Holland Computers, Inc.
CERTIFIED EXPERT

Commented:
Are the drives dropping for users that are members of different groups?  Since code runs sequentially, if a user is a member of the first group and the third group, then the code for the third group would override the first.  Attempting to map the same drive letter twice may cause windows to drop the mapping in the confusion.

Since you mentioned the AD upgrade from 2003 to 2008, this also could be the result of changed group memberships or permissions on the groups.  If a user is the member of a group that does not have access rights to a shared resource (Most likely List access but nothing else), the drive may map, but be inaccessible.  This does not explain the drive disappearing, but may help diagnosing the problem.  Keep in mind that the most restrictive group rights will apply to the user.

Author

Commented:
The drives are disconnecting after an indeterminate time periods on these domain machines and other times the drives are not connecting at all on these machines. The issues are hit and miss across the entire domain.
Frank McCourryV.P. Holland Computers, Inc.
CERTIFIED EXPERT

Commented:
If the drives are connecting and then disconnecting later, then I would suspect that you script is running properly.  You may want to check you policies in AD to see if one of them may be causing the disconnect.  

Create a test group and place a couple of computers in that group, then remove all policies except the one that runs this script.  See if the problem persists.

Author

Commented:
Let me explain something that I have found.  The Sharing section of the folder that I am trying to map is currently set with permissions of:

Everyone
Administrators

The Security of the folder is not set with everyone, but has the following:

Domain Admins
Administrators
General Managers
System

What do you think will be the issues that I am facing?
V.P. Holland Computers, Inc.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This script was being set to push through each user profile under User > Profile > User Profile > Login script

I can go into the system and look under SysVol and find that there was a place for the files to be dropped that may have been running the login scripts from past.

I need to explain something in this process.  We had an admin that was in charge of this project.  He was supposed to promote the domain from a Windows 2003 Server to the new Windows 2008 Server.  In the process we did not check what settings he was making, but from what I can tell the place you may be indicating that the file must run from is the opposite direction than the place he dropped the script.  If we Go under:
Windows > SYSVOL > sysvol > domain.com > Policies there are 6 folders.  Under one of the folders is the oldddddd script file that was originally used for the network logins.  Not sure why its still in here, but from what you're indiciating this is where we should have been editing the file.

Direct me if this was put the wrong place.  I have converted the system over to a batch file for the moment which seems to be mapping the drives currently.  I will add the batch file so you can see.

@echo off

net use J: /delete
net use L: /delete
net use M: /delete
net use O: /delete
net use R: /delete
net use W: /delete
net use V: /delete
net use S: /delete
net use T: /delete
net use Q: /delete
net use Y: /delete
net use Z: /delete
net use P: /delete
net use Z: /delete

net use J: \\10.16.182.40\owner              /y
net use L: \\10.16.182.40\sales              /y
net use M: \\10.16.182.40\ps                 /y
net use O: \\10.16.182.40\dir                /y
net use R: \\10.16.182.40\hr                 /y
net use W: \\10.16.182.40\fi                 /y
net use V: \\10.16.182.40\internet           /y
net use S: \\10.16.182.40\vehacct            /y
net use T: \\10.16.182.41\f                  /y
net use Q: \\10.16.182.40\g                  /y
net use Y: \\sum_asi_svr\P                   /y
net use X: \\10.16.182.40\personal           /y
net use P: \\10.16.182.40\common             /y
net use Z: \\10.16.182.40\personal\snilsson  /y
Frank McCourryV.P. Holland Computers, Inc.
CERTIFIED EXPERT

Commented:
The path I gave you is the correct location.  The user profiles path will still work but is outdated and as you can see may cause problems.  Move your scripts to the Profiles folder and your conflict should go away.  I would try your original script in this location, not that the batch file will not work, but by changing multiple variables you will complicate finding the true culprit.

* Off Topic - It's interesting that you are using an IP address in your batch file, is there a DNS resolution problem on your network?

Author

Commented:
Your last thoughts made a world of difference in the solution to our problem.
Thanks

"One last thought, because you have not said so, I've been assuming that this is a logon script most likely pushed by a group policy within Active Directory.  I am assuming that the settings of this policy are "User Configuration > Policies > Windows Settings > Scripts > Logon > Name of your script".  Please correct me if this is wrong."
Frank McCourryV.P. Holland Computers, Inc.
CERTIFIED EXPERT

Commented:
You're welcome!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.